blob: 9330070bf66bda6ea17c769eb458869cf73b4a52 [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 Bataev5ec3eb12013-07-19 03:13:43 +00001380 /// \brief Build a new OpenMP 'private' clause.
1381 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001382 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001383 /// Subclasses may override this routine to provide different behavior.
1384 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1385 SourceLocation StartLoc,
1386 SourceLocation LParenLoc,
1387 SourceLocation EndLoc) {
1388 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1389 EndLoc);
1390 }
1391
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001392 /// \brief Build a new OpenMP 'firstprivate' clause.
1393 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001394 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation EndLoc) {
1400 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1401 EndLoc);
1402 }
1403
Alexander Musman1bb328c2014-06-04 13:06:39 +00001404 /// \brief Build a new OpenMP 'lastprivate' clause.
1405 ///
1406 /// By default, performs semantic analysis to build the new OpenMP clause.
1407 /// Subclasses may override this routine to provide different behavior.
1408 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1409 SourceLocation StartLoc,
1410 SourceLocation LParenLoc,
1411 SourceLocation EndLoc) {
1412 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1413 EndLoc);
1414 }
1415
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001416 /// \brief Build a new OpenMP 'shared' clause.
1417 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001418 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001419 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001420 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1421 SourceLocation StartLoc,
1422 SourceLocation LParenLoc,
1423 SourceLocation EndLoc) {
1424 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1425 EndLoc);
1426 }
1427
Alexey Bataevc5e02582014-06-16 07:08:35 +00001428 /// \brief Build a new OpenMP 'reduction' clause.
1429 ///
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
1432 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation ColonLoc,
1436 SourceLocation EndLoc,
1437 CXXScopeSpec &ReductionIdScopeSpec,
1438 const DeclarationNameInfo &ReductionId) {
1439 return getSema().ActOnOpenMPReductionClause(
1440 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1441 ReductionId);
1442 }
1443
Alexander Musman8dba6642014-04-22 13:09:42 +00001444 /// \brief Build a new OpenMP 'linear' clause.
1445 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001446 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001447 /// Subclasses may override this routine to provide different behavior.
1448 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1449 SourceLocation StartLoc,
1450 SourceLocation LParenLoc,
1451 SourceLocation ColonLoc,
1452 SourceLocation EndLoc) {
1453 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1454 ColonLoc, EndLoc);
1455 }
1456
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001457 /// \brief Build a new OpenMP 'aligned' clause.
1458 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001459 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001460 /// Subclasses may override this routine to provide different behavior.
1461 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1462 SourceLocation StartLoc,
1463 SourceLocation LParenLoc,
1464 SourceLocation ColonLoc,
1465 SourceLocation EndLoc) {
1466 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1467 LParenLoc, ColonLoc, EndLoc);
1468 }
1469
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001470 /// \brief Build a new OpenMP 'copyin' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1479 EndLoc);
1480 }
1481
James Dennett2a4d13c2012-06-15 07:13:21 +00001482 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001483 ///
1484 /// By default, performs semantic analysis to build the new statement.
1485 /// Subclasses may override this routine to provide different behavior.
1486 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1487 Expr *object) {
1488 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1489 }
1490
James Dennett2a4d13c2012-06-15 07:13:21 +00001491 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001492 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001493 /// By default, performs semantic analysis to build the new statement.
1494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001495 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001496 Expr *Object, Stmt *Body) {
1497 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001498 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001499
James Dennett2a4d13c2012-06-15 07:13:21 +00001500 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001501 ///
1502 /// By default, performs semantic analysis to build the new statement.
1503 /// Subclasses may override this routine to provide different behavior.
1504 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1505 Stmt *Body) {
1506 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1507 }
John McCall53848232011-07-27 01:07:15 +00001508
Douglas Gregorf68a5082010-04-22 23:10:45 +00001509 /// \brief Build a new Objective-C fast enumeration statement.
1510 ///
1511 /// By default, performs semantic analysis to build the new statement.
1512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001514 Stmt *Element,
1515 Expr *Collection,
1516 SourceLocation RParenLoc,
1517 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001518 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001519 Element,
John McCallb268a282010-08-23 23:25:46 +00001520 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001521 RParenLoc);
1522 if (ForEachStmt.isInvalid())
1523 return StmtError();
1524
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001525 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001527
Douglas Gregorebe10102009-08-20 07:17:43 +00001528 /// \brief Build a new C++ exception declaration.
1529 ///
1530 /// By default, performs semantic analysis to build the new decaration.
1531 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001532 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001533 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001534 SourceLocation StartLoc,
1535 SourceLocation IdLoc,
1536 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001537 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001538 StartLoc, IdLoc, Id);
1539 if (Var)
1540 getSema().CurContext->addDecl(Var);
1541 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001542 }
1543
1544 /// \brief Build a new C++ catch statement.
1545 ///
1546 /// By default, performs semantic analysis to build the new statement.
1547 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001548 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001549 VarDecl *ExceptionDecl,
1550 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001551 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1552 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001553 }
Mike Stump11289f42009-09-09 15:08:12 +00001554
Douglas Gregorebe10102009-08-20 07:17:43 +00001555 /// \brief Build a new C++ try statement.
1556 ///
1557 /// By default, performs semantic analysis to build the new statement.
1558 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001559 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1560 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001561 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001562 }
Mike Stump11289f42009-09-09 15:08:12 +00001563
Richard Smith02e85f32011-04-14 22:09:26 +00001564 /// \brief Build a new C++0x range-based for statement.
1565 ///
1566 /// By default, performs semantic analysis to build the new statement.
1567 /// Subclasses may override this routine to provide different behavior.
1568 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1569 SourceLocation ColonLoc,
1570 Stmt *Range, Stmt *BeginEnd,
1571 Expr *Cond, Expr *Inc,
1572 Stmt *LoopVar,
1573 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001574 // If we've just learned that the range is actually an Objective-C
1575 // collection, treat this as an Objective-C fast enumeration loop.
1576 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1577 if (RangeStmt->isSingleDecl()) {
1578 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001579 if (RangeVar->isInvalidDecl())
1580 return StmtError();
1581
Douglas Gregorf7106af2013-04-08 18:40:13 +00001582 Expr *RangeExpr = RangeVar->getInit();
1583 if (!RangeExpr->isTypeDependent() &&
1584 RangeExpr->getType()->isObjCObjectPointerType())
1585 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1586 RParenLoc);
1587 }
1588 }
1589 }
1590
Richard Smith02e85f32011-04-14 22:09:26 +00001591 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001592 Cond, Inc, LoopVar, RParenLoc,
1593 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001594 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001595
1596 /// \brief Build a new C++0x range-based for statement.
1597 ///
1598 /// By default, performs semantic analysis to build the new statement.
1599 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001600 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001601 bool IsIfExists,
1602 NestedNameSpecifierLoc QualifierLoc,
1603 DeclarationNameInfo NameInfo,
1604 Stmt *Nested) {
1605 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1606 QualifierLoc, NameInfo, Nested);
1607 }
1608
Richard Smith02e85f32011-04-14 22:09:26 +00001609 /// \brief Attach body to a C++0x range-based for statement.
1610 ///
1611 /// By default, performs semantic analysis to finish the new statement.
1612 /// Subclasses may override this routine to provide different behavior.
1613 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1614 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1615 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001616
David Majnemerfad8f482013-10-15 09:33:02 +00001617 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1618 Stmt *TryBlock, Stmt *Handler) {
1619 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001620 }
1621
David Majnemerfad8f482013-10-15 09:33:02 +00001622 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001623 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001624 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001625 }
1626
David Majnemerfad8f482013-10-15 09:33:02 +00001627 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1628 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001629 }
1630
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// \brief Build a new expression that references a declaration.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001635 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001636 LookupResult &R,
1637 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001638 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1639 }
1640
1641
1642 /// \brief Build a new expression that references a declaration.
1643 ///
1644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001646 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001647 ValueDecl *VD,
1648 const DeclarationNameInfo &NameInfo,
1649 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001650 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001651 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001652
1653 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001654
1655 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001659 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001664 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
Douglas Gregorad8a3362009-09-04 17:36:40 +00001667 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001668 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001671 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001672 SourceLocation OperatorLoc,
1673 bool isArrow,
1674 CXXScopeSpec &SS,
1675 TypeSourceInfo *ScopeType,
1676 SourceLocation CCLoc,
1677 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001678 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001681 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001685 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001686 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001687 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 }
Mike Stump11289f42009-09-09 15:08:12 +00001689
Douglas Gregor882211c2010-04-28 22:16:22 +00001690 /// \brief Build a new builtin offsetof expression.
1691 ///
1692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001695 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001696 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001697 unsigned NumComponents,
1698 SourceLocation RParenLoc) {
1699 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1700 NumComponents, RParenLoc);
1701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001702
1703 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001704 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001705 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001708 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1709 SourceLocation OpLoc,
1710 UnaryExprOrTypeTrait ExprKind,
1711 SourceRange R) {
1712 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 }
1714
Peter Collingbournee190dee2011-03-11 19:24:49 +00001715 /// \brief Build a new sizeof, alignof or vec step expression with an
1716 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001720 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1721 UnaryExprOrTypeTrait ExprKind,
1722 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001723 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001724 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001727
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001728 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// \brief Build a new array subscript expression.
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.
John McCalldadc5752010-08-24 06:29:42 +00001735 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001737 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001739 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001740 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 RBracketLoc);
1742 }
1743
1744 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001745 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001750 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001751 Expr *ExecConfig = nullptr) {
1752 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001753 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
1756 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001757 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001761 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001762 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001763 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001764 const DeclarationNameInfo &MemberNameInfo,
1765 ValueDecl *Member,
1766 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001767 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001768 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001769 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1770 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001771 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001772 // We have a reference to an unnamed field. This is always the
1773 // base of an anonymous struct/union member access, i.e. the
1774 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001775 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001776 assert(Member->getType()->isRecordType() &&
1777 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001778
Richard Smithcab9a7d2011-10-26 19:06:56 +00001779 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001780 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001781 QualifierLoc.getNestedNameSpecifier(),
1782 FoundDecl, Member);
1783 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001784 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001785 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001786 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001787 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001788 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001789 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001790 cast<FieldDecl>(Member)->getType(),
1791 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001792 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001793 }
Mike Stump11289f42009-09-09 15:08:12 +00001794
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001795 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001796 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001797
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001798 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001799 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001800
John McCall16df1e52010-03-30 21:47:33 +00001801 // FIXME: this involves duplicating earlier analysis in a lot of
1802 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001803 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001804 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001805 R.resolveKind();
1806
John McCallb268a282010-08-23 23:25:46 +00001807 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001808 SS, TemplateKWLoc,
1809 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001810 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 }
Mike Stump11289f42009-09-09 15:08:12 +00001812
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001814 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001818 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001819 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001820 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 }
1822
1823 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001824 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001828 SourceLocation QuestionLoc,
1829 Expr *LHS,
1830 SourceLocation ColonLoc,
1831 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001832 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1833 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
1835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001837 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001841 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001843 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001844 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001845 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001849 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001853 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001855 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001856 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001857 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 }
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001861 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 SourceLocation OpLoc,
1866 SourceLocation AccessorLoc,
1867 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001868
John McCall10eae182009-11-30 22:42:35 +00001869 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001870 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001871 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001872 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001873 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001874 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001875 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001876 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 }
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001880 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 /// By default, performs semantic analysis to build the new expression.
1882 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001883 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001884 MultiExprArg Inits,
1885 SourceLocation RBraceLoc,
1886 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001887 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001888 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001889 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001890 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001891
Douglas Gregord3d93062009-11-09 17:16:50 +00001892 // Patch in the result type we were given, which may have been computed
1893 // when the initial InitListExpr was built.
1894 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1895 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001896 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001900 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001903 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 MultiExprArg ArrayExprs,
1905 SourceLocation EqualOrColonLoc,
1906 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001907 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001908 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001910 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001913
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001914 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 }
Mike Stump11289f42009-09-09 15:08:12 +00001916
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001918 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// By default, builds the implicit value initialization without performing
1920 /// any semantic analysis. Subclasses may override this routine to provide
1921 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001922 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001923 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 }
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001927 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001931 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001932 SourceLocation RParenLoc) {
1933 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001935 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 }
1937
1938 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001939 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 /// By default, performs semantic analysis to build the new expression.
1941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001942 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001943 MultiExprArg SubExprs,
1944 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001945 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001949 ///
1950 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 /// rather than attempting to map the label statement itself.
1952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001953 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001954 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001955 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001963 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001965 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 }
Mike Stump11289f42009-09-09 15:08:12 +00001967
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// \brief Build a new __builtin_choose_expr expression.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001973 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 SourceLocation RParenLoc) {
1975 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001976 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 RParenLoc);
1978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979
Peter Collingbourne91147592011-04-15 00:35:48 +00001980 /// \brief Build a new generic selection expression.
1981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
1984 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1985 SourceLocation DefaultLoc,
1986 SourceLocation RParenLoc,
1987 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001988 ArrayRef<TypeSourceInfo *> Types,
1989 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001990 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001991 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001992 }
1993
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// \brief Build a new overloaded operator call expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// The semantic analysis provides the behavior of template instantiation,
1998 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001999 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// argument-dependent lookup, etc. Subclasses may override this routine to
2001 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002004 Expr *Callee,
2005 Expr *First,
2006 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002007
2008 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// reinterpret_cast.
2010 ///
2011 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002012 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 Stmt::StmtClass Class,
2016 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002017 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 SourceLocation RAngleLoc,
2019 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002020 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 SourceLocation RParenLoc) {
2022 switch (Class) {
2023 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002024 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002025 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002026 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002027
2028 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002029 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002030 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002031 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002032
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002034 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002035 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002036 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002038
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002040 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002041 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002045 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 }
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 /// \brief Build a new C++ static_cast expression.
2050 ///
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002053 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002055 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 SourceLocation RAngleLoc,
2057 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002058 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002060 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002061 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002062 SourceRange(LAngleLoc, RAngleLoc),
2063 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 }
2065
2066 /// \brief Build a new C++ dynamic_cast expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002070 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002072 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 SourceLocation RAngleLoc,
2074 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002075 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002077 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002078 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002079 SourceRange(LAngleLoc, RAngleLoc),
2080 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 }
2082
2083 /// \brief Build a new C++ reinterpret_cast expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002089 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 SourceLocation RAngleLoc,
2091 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002092 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002094 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002095 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002096 SourceRange(LAngleLoc, RAngleLoc),
2097 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 }
2099
2100 /// \brief Build a new C++ const_cast expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002104 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002106 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 SourceLocation RAngleLoc,
2108 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002109 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002111 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002112 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002113 SourceRange(LAngleLoc, RAngleLoc),
2114 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 }
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 /// \brief Build a new C++ functional-style cast expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002121 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2122 SourceLocation LParenLoc,
2123 Expr *Sub,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002126 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 RParenLoc);
2128 }
Mike Stump11289f42009-09-09 15:08:12 +00002129
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 /// \brief Build a new C++ typeid(type) expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002134 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002135 SourceLocation TypeidLoc,
2136 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002138 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002139 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
Francois Pichet9f4f2072010-09-08 12:20:18 +00002142
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 /// \brief Build a new C++ typeid(expr) expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002147 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002148 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002149 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002151 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002152 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002153 }
2154
Francois Pichet9f4f2072010-09-08 12:20:18 +00002155 /// \brief Build a new C++ __uuidof(type) expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
2159 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2160 SourceLocation TypeidLoc,
2161 TypeSourceInfo *Operand,
2162 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002163 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002164 RParenLoc);
2165 }
2166
2167 /// \brief Build a new C++ __uuidof(expr) expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
2171 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2172 SourceLocation TypeidLoc,
2173 Expr *Operand,
2174 SourceLocation RParenLoc) {
2175 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2176 RParenLoc);
2177 }
2178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 /// \brief Build a new C++ "this" expression.
2180 ///
2181 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002182 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002185 QualType ThisType,
2186 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002187 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002188 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
2190
2191 /// \brief Build a new C++ throw expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002195 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2196 bool IsThrownVariableInScope) {
2197 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 }
2199
2200 /// \brief Build a new C++ default-argument expression.
2201 ///
2202 /// By default, builds a new default-argument expression, which does not
2203 /// require any semantic analysis. Subclasses may override this routine to
2204 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002205 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002206 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002207 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
2209
Richard Smith852c9db2013-04-20 22:23:05 +00002210 /// \brief Build a new C++11 default-initialization expression.
2211 ///
2212 /// By default, builds a new default field initialization expression, which
2213 /// does not require any semantic analysis. Subclasses may override this
2214 /// routine to provide different behavior.
2215 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2216 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002217 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002218 }
2219
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 /// \brief Build a new C++ zero-initialization expression.
2221 ///
2222 /// By default, performs semantic analysis to build the new expression.
2223 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002224 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2225 SourceLocation LParenLoc,
2226 SourceLocation RParenLoc) {
2227 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002228 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 }
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 /// \brief Build a new C++ "new" expression.
2232 ///
2233 /// By default, performs semantic analysis to build the new expression.
2234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002235 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002236 bool UseGlobal,
2237 SourceLocation PlacementLParen,
2238 MultiExprArg PlacementArgs,
2239 SourceLocation PlacementRParen,
2240 SourceRange TypeIdParens,
2241 QualType AllocatedType,
2242 TypeSourceInfo *AllocatedTypeInfo,
2243 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002244 SourceRange DirectInitRange,
2245 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002246 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002250 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002251 AllocatedType,
2252 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002253 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002254 DirectInitRange,
2255 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 }
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "delete" expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002262 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 bool IsGlobalDelete,
2264 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002265 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002267 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
Mike Stump11289f42009-09-09 15:08:12 +00002269
Douglas Gregor29c42f22012-02-24 07:38:34 +00002270 /// \brief Build a new type trait expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
2274 ExprResult RebuildTypeTrait(TypeTrait Trait,
2275 SourceLocation StartLoc,
2276 ArrayRef<TypeSourceInfo *> Args,
2277 SourceLocation RParenLoc) {
2278 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002280
John Wiegley6242b6a2011-04-28 00:16:57 +00002281 /// \brief Build a new array type trait expression.
2282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
2285 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2286 SourceLocation StartLoc,
2287 TypeSourceInfo *TSInfo,
2288 Expr *DimExpr,
2289 SourceLocation RParenLoc) {
2290 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2291 }
2292
John Wiegleyf9f65842011-04-25 06:54:41 +00002293 /// \brief Build a new expression trait expression.
2294 ///
2295 /// By default, performs semantic analysis to build the new expression.
2296 /// Subclasses may override this routine to provide different behavior.
2297 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2298 SourceLocation StartLoc,
2299 Expr *Queried,
2300 SourceLocation RParenLoc) {
2301 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2302 }
2303
Mike Stump11289f42009-09-09 15:08:12 +00002304 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002309 ExprResult RebuildDependentScopeDeclRefExpr(
2310 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002311 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002312 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002313 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002314 bool IsAddressOfOperand,
2315 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002317 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002318
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002319 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002320 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2321 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002322
Reid Kleckner32506ed2014-06-12 23:03:48 +00002323 return getSema().BuildQualifiedDeclarationNameExpr(
2324 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 }
2326
2327 /// \brief Build a new template-id expression.
2328 ///
2329 /// By default, performs semantic analysis to build the new expression.
2330 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002331 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002332 SourceLocation TemplateKWLoc,
2333 LookupResult &R,
2334 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002335 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002336 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2337 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 }
2339
2340 /// \brief Build a new object-construction expression.
2341 ///
2342 /// By default, performs semantic analysis to build the new expression.
2343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002344 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002345 SourceLocation Loc,
2346 CXXConstructorDecl *Constructor,
2347 bool IsElidable,
2348 MultiExprArg Args,
2349 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002350 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002351 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002352 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002353 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002354 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002355 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002356 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002357 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002358
Douglas Gregordb121ba2009-12-14 16:27:04 +00002359 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002360 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002361 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002362 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002363 RequiresZeroInit, ConstructKind,
2364 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 }
2366
2367 /// \brief Build a new object-construction expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002371 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2372 SourceLocation LParenLoc,
2373 MultiExprArg Args,
2374 SourceLocation RParenLoc) {
2375 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002377 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 RParenLoc);
2379 }
2380
2381 /// \brief Build a new object-construction expression.
2382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002385 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2386 SourceLocation LParenLoc,
2387 MultiExprArg Args,
2388 SourceLocation RParenLoc) {
2389 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002391 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 RParenLoc);
2393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 /// \brief Build a new member reference expression.
2396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002399 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002400 QualType BaseType,
2401 bool IsArrow,
2402 SourceLocation OperatorLoc,
2403 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002404 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002405 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002406 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002407 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002409 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002410
John McCallb268a282010-08-23 23:25:46 +00002411 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002412 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002413 SS, TemplateKWLoc,
2414 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002415 MemberNameInfo,
2416 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
John McCall10eae182009-11-30 22:42:35 +00002419 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002423 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2424 SourceLocation OperatorLoc,
2425 bool IsArrow,
2426 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002427 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002428 NamedDecl *FirstQualifierInScope,
2429 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002430 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002431 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002432 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002433
John McCallb268a282010-08-23 23:25:46 +00002434 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002435 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002436 SS, TemplateKWLoc,
2437 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002438 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002441 /// \brief Build a new noexcept expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
2445 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2446 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2447 }
2448
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002449 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002450 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2451 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002452 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002453 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002454 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002455 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2456 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002457 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002458
2459 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2460 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002461 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002462 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002463
Patrick Beard0caa3942012-04-19 00:25:12 +00002464 /// \brief Build a new Objective-C boxed expression.
2465 ///
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// Subclasses may override this routine to provide different behavior.
2468 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2469 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002471
Ted Kremeneke65b0862012-03-06 20:05:56 +00002472 /// \brief Build a new Objective-C array literal.
2473 ///
2474 /// By default, performs semantic analysis to build the new expression.
2475 /// Subclasses may override this routine to provide different behavior.
2476 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2477 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002478 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002479 MultiExprArg(Elements, NumElements));
2480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002481
2482 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002483 Expr *Base, Expr *Key,
2484 ObjCMethodDecl *getterMethod,
2485 ObjCMethodDecl *setterMethod) {
2486 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2487 getterMethod, setterMethod);
2488 }
2489
2490 /// \brief Build a new Objective-C dictionary literal.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2495 ObjCDictionaryElement *Elements,
2496 unsigned NumElements) {
2497 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002499
James Dennett2a4d13c2012-06-15 07:13:21 +00002500 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002504 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002505 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002507 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002508 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002509
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002510 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002511 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002512 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002513 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002514 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002515 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002516 MultiExprArg Args,
2517 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002518 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2519 ReceiverTypeInfo->getType(),
2520 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002521 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002522 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002523 }
2524
2525 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
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) {
John McCallb268a282010-08-23 23:25:46 +00002533 return SemaRef.BuildInstanceMessage(Receiver,
2534 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002535 /*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
Douglas Gregord51d90d2010-04-26 20:11:03 +00002540 /// \brief Build a new Objective-C ivar reference expression.
2541 ///
2542 /// By default, performs semantic analysis to build the new expression.
2543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002544 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002545 SourceLocation IvarLoc,
2546 bool IsArrow, bool IsFreeIvar) {
2547 // FIXME: We lose track of the IsFreeIvar bit.
2548 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002549 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2550 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002551 /*FIXME:*/IvarLoc, IsArrow,
2552 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002553 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002554 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002555 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002556 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002557
2558 /// \brief Build a new Objective-C property reference expression.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002562 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002563 ObjCPropertyDecl *Property,
2564 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002565 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002566 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2567 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2568 /*FIXME:*/PropertyLoc,
2569 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002570 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002571 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002572 NameInfo,
2573 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002575
John McCallb7bd14f2010-12-02 01:19:52 +00002576 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002577 ///
2578 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002579 /// Subclasses may override this routine to provide different behavior.
2580 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2581 ObjCMethodDecl *Getter,
2582 ObjCMethodDecl *Setter,
2583 SourceLocation PropertyLoc) {
2584 // Since these expressions can only be value-dependent, we do not
2585 // need to perform semantic analysis again.
2586 return Owned(
2587 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2588 VK_LValue, OK_ObjCProperty,
2589 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002590 }
2591
Douglas Gregord51d90d2010-04-26 20:11:03 +00002592 /// \brief Build a new Objective-C "isa" expression.
2593 ///
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002596 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002597 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002598 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002599 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2600 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002601 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002602 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002603 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002604 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002605 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002606 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002607
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 /// \brief Build a new shuffle vector expression.
2609 ///
2610 /// By default, performs semantic analysis to build the new expression.
2611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002612 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002613 MultiExprArg SubExprs,
2614 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002616 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2618 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2619 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002620 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002621
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002623 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002624 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2625 SemaRef.Context.BuiltinFnTy,
2626 VK_RValue, BuiltinLoc);
2627 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2628 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002629 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002630
2631 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002632 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002633 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002634 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregora16548e2009-08-11 05:31:07 +00002636 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002637 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002638 }
John McCall31f82722010-11-12 08:19:04 +00002639
Hal Finkelc4d7c822013-09-18 03:29:45 +00002640 /// \brief Build a new convert vector expression.
2641 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2642 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2643 SourceLocation RParenLoc) {
2644 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2645 BuiltinLoc, RParenLoc);
2646 }
2647
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002648 /// \brief Build a new template argument pack expansion.
2649 ///
2650 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002651 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002652 /// different behavior.
2653 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002654 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002655 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002656 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002657 case TemplateArgument::Expression: {
2658 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002659 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2660 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002661 if (Result.isInvalid())
2662 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002663
Douglas Gregor98318c22011-01-03 21:37:45 +00002664 return TemplateArgumentLoc(Result.get(), Result.get());
2665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002666
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002667 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002668 return TemplateArgumentLoc(TemplateArgument(
2669 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002670 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002671 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002672 Pattern.getTemplateNameLoc(),
2673 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002674
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002675 case TemplateArgument::Null:
2676 case TemplateArgument::Integral:
2677 case TemplateArgument::Declaration:
2678 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002679 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002680 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002681 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002682
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002683 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002684 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002685 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002686 EllipsisLoc,
2687 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002688 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2689 Expansion);
2690 break;
2691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002692
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002693 return TemplateArgumentLoc();
2694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002695
Douglas Gregor968f23a2011-01-03 19:31:53 +00002696 /// \brief Build a new expression pack expansion.
2697 ///
2698 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002699 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002700 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002701 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002702 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002703 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002704 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002705
2706 /// \brief Build a new atomic operation expression.
2707 ///
2708 /// By default, performs semantic analysis to build the new expression.
2709 /// Subclasses may override this routine to provide different behavior.
2710 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2711 MultiExprArg SubExprs,
2712 QualType RetTy,
2713 AtomicExpr::AtomicOp Op,
2714 SourceLocation RParenLoc) {
2715 // Just create the expression; there is not any interesting semantic
2716 // analysis here because we can't actually build an AtomicExpr until
2717 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002718 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002719 RParenLoc);
2720 }
2721
John McCall31f82722010-11-12 08:19:04 +00002722private:
Douglas Gregor14454802011-02-25 02:25:35 +00002723 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2724 QualType ObjectType,
2725 NamedDecl *FirstQualifierInScope,
2726 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002727
2728 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2729 QualType ObjectType,
2730 NamedDecl *FirstQualifierInScope,
2731 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002732
2733 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2734 NamedDecl *FirstQualifierInScope,
2735 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736};
Douglas Gregora16548e2009-08-11 05:31:07 +00002737
Douglas Gregorebe10102009-08-20 07:17:43 +00002738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002739StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002740 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002741 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregorebe10102009-08-20 07:17:43 +00002743 switch (S->getStmtClass()) {
2744 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002745
Douglas Gregorebe10102009-08-20 07:17:43 +00002746 // Transform individual statement nodes
2747#define STMT(Node, Parent) \
2748 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002749#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002750#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002751#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregorebe10102009-08-20 07:17:43 +00002753 // Transform expressions by calling TransformExpr.
2754#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002755#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002756#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002757#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002758 {
John McCalldadc5752010-08-24 06:29:42 +00002759 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002760 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002761 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002762
Richard Smith945f8d32013-01-14 22:39:08 +00002763 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002764 }
Mike Stump11289f42009-09-09 15:08:12 +00002765 }
2766
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002767 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002768}
Mike Stump11289f42009-09-09 15:08:12 +00002769
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002770template<typename Derived>
2771OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2772 if (!S)
2773 return S;
2774
2775 switch (S->getClauseKind()) {
2776 default: break;
2777 // Transform individual clause nodes
2778#define OPENMP_CLAUSE(Name, Class) \
2779 case OMPC_ ## Name : \
2780 return getDerived().Transform ## Class(cast<Class>(S));
2781#include "clang/Basic/OpenMPKinds.def"
2782 }
2783
2784 return S;
2785}
2786
Mike Stump11289f42009-09-09 15:08:12 +00002787
Douglas Gregore922c772009-08-04 22:27:00 +00002788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002789ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002790 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002791 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002792
2793 switch (E->getStmtClass()) {
2794 case Stmt::NoStmtClass: break;
2795#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002796#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002797#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002798 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002799#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002800 }
2801
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002802 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002803}
2804
2805template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002806ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2807 bool CXXDirectInit) {
2808 // Initializers are instantiated like expressions, except that various outer
2809 // layers are stripped.
2810 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002811 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002812
2813 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2814 Init = ExprTemp->getSubExpr();
2815
Richard Smithe6ca4752013-05-30 22:40:16 +00002816 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2817 Init = MTE->GetTemporaryExpr();
2818
Richard Smithd59b8322012-12-19 01:39:02 +00002819 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2820 Init = Binder->getSubExpr();
2821
2822 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2823 Init = ICE->getSubExprAsWritten();
2824
Richard Smithcc1b96d2013-06-12 22:31:48 +00002825 if (CXXStdInitializerListExpr *ILE =
2826 dyn_cast<CXXStdInitializerListExpr>(Init))
2827 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2828
Richard Smith38a549b2012-12-21 08:13:35 +00002829 // If this is not a direct-initializer, we only need to reconstruct
2830 // InitListExprs. Other forms of copy-initialization will be a no-op if
2831 // the initializer is already the right type.
2832 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2833 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2834 return getDerived().TransformExpr(Init);
2835
2836 // Revert value-initialization back to empty parens.
2837 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2838 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002839 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002840 Parens.getEnd());
2841 }
2842
2843 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2844 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002845 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002846 SourceLocation());
2847
2848 // Revert initialization by constructor back to a parenthesized or braced list
2849 // of expressions. Any other form of initializer can just be reused directly.
2850 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002851 return getDerived().TransformExpr(Init);
2852
2853 SmallVector<Expr*, 8> NewArgs;
2854 bool ArgChanged = false;
2855 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2856 /*IsCall*/true, NewArgs, &ArgChanged))
2857 return ExprError();
2858
2859 // If this was list initialization, revert to list form.
2860 if (Construct->isListInitialization())
2861 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2862 Construct->getLocEnd(),
2863 Construct->getType());
2864
Richard Smithd59b8322012-12-19 01:39:02 +00002865 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002866 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002867 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2868 Parens.getEnd());
2869}
2870
2871template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002872bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2873 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002874 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002875 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002876 bool *ArgChanged) {
2877 for (unsigned I = 0; I != NumInputs; ++I) {
2878 // If requested, drop call arguments that need to be dropped.
2879 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2880 if (ArgChanged)
2881 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002882
Douglas Gregora3efea12011-01-03 19:04:46 +00002883 break;
2884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002885
Douglas Gregor968f23a2011-01-03 19:31:53 +00002886 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2887 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002888
Chris Lattner01cf8db2011-07-20 06:58:45 +00002889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002890 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2891 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002892
Douglas Gregor968f23a2011-01-03 19:31:53 +00002893 // Determine whether the set of unexpanded parameter packs can and should
2894 // be expanded.
2895 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002896 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002897 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2898 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002899 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2900 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002901 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002902 Expand, RetainExpansion,
2903 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002904 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002905
Douglas Gregor968f23a2011-01-03 19:31:53 +00002906 if (!Expand) {
2907 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002908 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002909 // expansion.
2910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2911 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2912 if (OutPattern.isInvalid())
2913 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
2915 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002916 Expansion->getEllipsisLoc(),
2917 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002918 if (Out.isInvalid())
2919 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002920
Douglas Gregor968f23a2011-01-03 19:31:53 +00002921 if (ArgChanged)
2922 *ArgChanged = true;
2923 Outputs.push_back(Out.get());
2924 continue;
2925 }
John McCall542e7c62011-07-06 07:30:07 +00002926
2927 // Record right away that the argument was changed. This needs
2928 // to happen even if the array expands to nothing.
2929 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregor968f23a2011-01-03 19:31:53 +00002931 // The transform has determined that we should perform an elementwise
2932 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002933 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002934 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2935 ExprResult Out = getDerived().TransformExpr(Pattern);
2936 if (Out.isInvalid())
2937 return true;
2938
Richard Smith9467be42014-06-06 17:33:35 +00002939 // FIXME: Can this happen? We should not try to expand the pack
2940 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002941 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002942 Out = getDerived().RebuildPackExpansion(
2943 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002944 if (Out.isInvalid())
2945 return true;
2946 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002947
Douglas Gregor968f23a2011-01-03 19:31:53 +00002948 Outputs.push_back(Out.get());
2949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002950
Richard Smith9467be42014-06-06 17:33:35 +00002951 // If we're supposed to retain a pack expansion, do so by temporarily
2952 // forgetting the partially-substituted parameter pack.
2953 if (RetainExpansion) {
2954 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2955
2956 ExprResult Out = getDerived().TransformExpr(Pattern);
2957 if (Out.isInvalid())
2958 return true;
2959
2960 Out = getDerived().RebuildPackExpansion(
2961 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
2962 if (Out.isInvalid())
2963 return true;
2964
2965 Outputs.push_back(Out.get());
2966 }
2967
Douglas Gregor968f23a2011-01-03 19:31:53 +00002968 continue;
2969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002970
Richard Smithd59b8322012-12-19 01:39:02 +00002971 ExprResult Result =
2972 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2973 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002974 if (Result.isInvalid())
2975 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002976
Douglas Gregora3efea12011-01-03 19:04:46 +00002977 if (Result.get() != Inputs[I] && ArgChanged)
2978 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002979
2980 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002982
Douglas Gregora3efea12011-01-03 19:04:46 +00002983 return false;
2984}
2985
2986template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002987NestedNameSpecifierLoc
2988TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2989 NestedNameSpecifierLoc NNS,
2990 QualType ObjectType,
2991 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002992 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002993 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002994 Qualifier = Qualifier.getPrefix())
2995 Qualifiers.push_back(Qualifier);
2996
2997 CXXScopeSpec SS;
2998 while (!Qualifiers.empty()) {
2999 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3000 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003001
Douglas Gregor14454802011-02-25 02:25:35 +00003002 switch (QNNS->getKind()) {
3003 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003004 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003005 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003006 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003007 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003008 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003009 FirstQualifierInScope, false))
3010 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003011
Douglas Gregor14454802011-02-25 02:25:35 +00003012 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor14454802011-02-25 02:25:35 +00003014 case NestedNameSpecifier::Namespace: {
3015 NamespaceDecl *NS
3016 = cast_or_null<NamespaceDecl>(
3017 getDerived().TransformDecl(
3018 Q.getLocalBeginLoc(),
3019 QNNS->getAsNamespace()));
3020 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3021 break;
3022 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor14454802011-02-25 02:25:35 +00003024 case NestedNameSpecifier::NamespaceAlias: {
3025 NamespaceAliasDecl *Alias
3026 = cast_or_null<NamespaceAliasDecl>(
3027 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3028 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003029 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003030 Q.getLocalEndLoc());
3031 break;
3032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
Douglas Gregor14454802011-02-25 02:25:35 +00003034 case NestedNameSpecifier::Global:
3035 // There is no meaningful transformation that one could perform on the
3036 // global scope.
3037 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3038 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Douglas Gregor14454802011-02-25 02:25:35 +00003040 case NestedNameSpecifier::TypeSpecWithTemplate:
3041 case NestedNameSpecifier::TypeSpec: {
3042 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3043 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor14454802011-02-25 02:25:35 +00003045 if (!TL)
3046 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003047
Douglas Gregor14454802011-02-25 02:25:35 +00003048 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003049 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003050 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003051 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003052 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003053 if (TL.getType()->isEnumeralType())
3054 SemaRef.Diag(TL.getBeginLoc(),
3055 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003056 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3057 Q.getLocalEndLoc());
3058 break;
3059 }
Richard Trieude756fb2011-05-07 01:36:37 +00003060 // If the nested-name-specifier is an invalid type def, don't emit an
3061 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003062 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3063 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003064 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003065 << TL.getType() << SS.getRange();
3066 }
Douglas Gregor14454802011-02-25 02:25:35 +00003067 return NestedNameSpecifierLoc();
3068 }
Douglas Gregore16af532011-02-28 18:50:33 +00003069 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003070
Douglas Gregore16af532011-02-28 18:50:33 +00003071 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003072 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003073 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregor14454802011-02-25 02:25:35 +00003076 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003077 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003078 !getDerived().AlwaysRebuild())
3079 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003080
3081 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003082 // nested-name-specifier, do so.
3083 if (SS.location_size() == NNS.getDataLength() &&
3084 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3085 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3086
3087 // Allocate new nested-name-specifier location information.
3088 return SS.getWithLocInContext(SemaRef.Context);
3089}
3090
3091template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003092DeclarationNameInfo
3093TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003094::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003095 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003096 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003097 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003098
3099 switch (Name.getNameKind()) {
3100 case DeclarationName::Identifier:
3101 case DeclarationName::ObjCZeroArgSelector:
3102 case DeclarationName::ObjCOneArgSelector:
3103 case DeclarationName::ObjCMultiArgSelector:
3104 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003105 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003106 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003107 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003108
Douglas Gregorf816bd72009-09-03 22:13:48 +00003109 case DeclarationName::CXXConstructorName:
3110 case DeclarationName::CXXDestructorName:
3111 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003112 TypeSourceInfo *NewTInfo;
3113 CanQualType NewCanTy;
3114 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003115 NewTInfo = getDerived().TransformType(OldTInfo);
3116 if (!NewTInfo)
3117 return DeclarationNameInfo();
3118 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003119 }
3120 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003121 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003122 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003123 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003124 if (NewT.isNull())
3125 return DeclarationNameInfo();
3126 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3127 }
Mike Stump11289f42009-09-09 15:08:12 +00003128
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003129 DeclarationName NewName
3130 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3131 NewCanTy);
3132 DeclarationNameInfo NewNameInfo(NameInfo);
3133 NewNameInfo.setName(NewName);
3134 NewNameInfo.setNamedTypeInfo(NewTInfo);
3135 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003136 }
Mike Stump11289f42009-09-09 15:08:12 +00003137 }
3138
David Blaikie83d382b2011-09-23 05:06:16 +00003139 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003140}
3141
3142template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003143TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003144TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3145 TemplateName Name,
3146 SourceLocation NameLoc,
3147 QualType ObjectType,
3148 NamedDecl *FirstQualifierInScope) {
3149 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3150 TemplateDecl *Template = QTN->getTemplateDecl();
3151 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
Douglas Gregor9db53502011-03-02 18:07:45 +00003153 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003154 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003155 Template));
3156 if (!TransTemplate)
3157 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003158
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 if (!getDerived().AlwaysRebuild() &&
3160 SS.getScopeRep() == QTN->getQualifier() &&
3161 TransTemplate == Template)
3162 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor9db53502011-03-02 18:07:45 +00003164 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3165 TransTemplate);
3166 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003167
Douglas Gregor9db53502011-03-02 18:07:45 +00003168 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3169 if (SS.getScopeRep()) {
3170 // These apply to the scope specifier, not the template.
3171 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003172 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003173 }
3174
Douglas Gregor9db53502011-03-02 18:07:45 +00003175 if (!getDerived().AlwaysRebuild() &&
3176 SS.getScopeRep() == DTN->getQualifier() &&
3177 ObjectType.isNull())
3178 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003179
Douglas Gregor9db53502011-03-02 18:07:45 +00003180 if (DTN->isIdentifier()) {
3181 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003182 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003183 NameLoc,
3184 ObjectType,
3185 FirstQualifierInScope);
3186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
Douglas Gregor9db53502011-03-02 18:07:45 +00003188 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3189 ObjectType);
3190 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
Douglas Gregor9db53502011-03-02 18:07:45 +00003192 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3193 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003194 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003195 Template));
3196 if (!TransTemplate)
3197 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003198
Douglas Gregor9db53502011-03-02 18:07:45 +00003199 if (!getDerived().AlwaysRebuild() &&
3200 TransTemplate == Template)
3201 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
Douglas Gregor9db53502011-03-02 18:07:45 +00003203 return TemplateName(TransTemplate);
3204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
Douglas Gregor9db53502011-03-02 18:07:45 +00003206 if (SubstTemplateTemplateParmPackStorage *SubstPack
3207 = Name.getAsSubstTemplateTemplateParmPack()) {
3208 TemplateTemplateParmDecl *TransParam
3209 = cast_or_null<TemplateTemplateParmDecl>(
3210 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3211 if (!TransParam)
3212 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003213
Douglas Gregor9db53502011-03-02 18:07:45 +00003214 if (!getDerived().AlwaysRebuild() &&
3215 TransParam == SubstPack->getParameterPack())
3216 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
3218 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003219 SubstPack->getArgumentPack());
3220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregor9db53502011-03-02 18:07:45 +00003222 // These should be getting filtered out before they reach the AST.
3223 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003224}
3225
3226template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003227void TreeTransform<Derived>::InventTemplateArgumentLoc(
3228 const TemplateArgument &Arg,
3229 TemplateArgumentLoc &Output) {
3230 SourceLocation Loc = getDerived().getBaseLocation();
3231 switch (Arg.getKind()) {
3232 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003233 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003234 break;
3235
3236 case TemplateArgument::Type:
3237 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003238 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
John McCall0ad16662009-10-29 08:12:44 +00003240 break;
3241
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003242 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003243 case TemplateArgument::TemplateExpansion: {
3244 NestedNameSpecifierLocBuilder Builder;
3245 TemplateName Template = Arg.getAsTemplate();
3246 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3247 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3248 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3249 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor9d802122011-03-02 17:09:35 +00003251 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003252 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003253 Builder.getWithLocInContext(SemaRef.Context),
3254 Loc);
3255 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003256 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003257 Builder.getWithLocInContext(SemaRef.Context),
3258 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003260 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003261 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003262
John McCall0ad16662009-10-29 08:12:44 +00003263 case TemplateArgument::Expression:
3264 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3265 break;
3266
3267 case TemplateArgument::Declaration:
3268 case TemplateArgument::Integral:
3269 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003270 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003271 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003272 break;
3273 }
3274}
3275
3276template<typename Derived>
3277bool TreeTransform<Derived>::TransformTemplateArgument(
3278 const TemplateArgumentLoc &Input,
3279 TemplateArgumentLoc &Output) {
3280 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003281 switch (Arg.getKind()) {
3282 case TemplateArgument::Null:
3283 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003284 case TemplateArgument::Pack:
3285 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003286 case TemplateArgument::NullPtr:
3287 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003288
Douglas Gregore922c772009-08-04 22:27:00 +00003289 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003290 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003291 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003292 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003293
3294 DI = getDerived().TransformType(DI);
3295 if (!DI) return true;
3296
3297 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3298 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003299 }
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003301 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003302 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3303 if (QualifierLoc) {
3304 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3305 if (!QualifierLoc)
3306 return true;
3307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregordf846d12011-03-02 18:46:51 +00003309 CXXScopeSpec SS;
3310 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003311 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003312 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3313 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003314 if (Template.isNull())
3315 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregor9d802122011-03-02 17:09:35 +00003317 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003318 Input.getTemplateNameLoc());
3319 return false;
3320 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003321
3322 case TemplateArgument::TemplateExpansion:
3323 llvm_unreachable("Caller should expand pack expansions");
3324
Douglas Gregore922c772009-08-04 22:27:00 +00003325 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003326 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003327 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003328 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003329
John McCall0ad16662009-10-29 08:12:44 +00003330 Expr *InputExpr = Input.getSourceExpression();
3331 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3332
Chris Lattnercdb591a2011-04-25 20:37:58 +00003333 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003334 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003335 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003336 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003337 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003338 }
Douglas Gregore922c772009-08-04 22:27:00 +00003339 }
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregore922c772009-08-04 22:27:00 +00003341 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003342 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003343}
3344
Douglas Gregorfe921a72010-12-20 23:36:19 +00003345/// \brief Iterator adaptor that invents template argument location information
3346/// for each of the template arguments in its underlying iterator.
3347template<typename Derived, typename InputIterator>
3348class TemplateArgumentLocInventIterator {
3349 TreeTransform<Derived> &Self;
3350 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregorfe921a72010-12-20 23:36:19 +00003352public:
3353 typedef TemplateArgumentLoc value_type;
3354 typedef TemplateArgumentLoc reference;
3355 typedef typename std::iterator_traits<InputIterator>::difference_type
3356 difference_type;
3357 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003358
Douglas Gregorfe921a72010-12-20 23:36:19 +00003359 class pointer {
3360 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Douglas Gregorfe921a72010-12-20 23:36:19 +00003362 public:
3363 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregorfe921a72010-12-20 23:36:19 +00003365 const TemplateArgumentLoc *operator->() const { return &Arg; }
3366 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregorfe921a72010-12-20 23:36:19 +00003368 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregorfe921a72010-12-20 23:36:19 +00003370 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3371 InputIterator Iter)
3372 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregorfe921a72010-12-20 23:36:19 +00003374 TemplateArgumentLocInventIterator &operator++() {
3375 ++Iter;
3376 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
Douglas Gregorfe921a72010-12-20 23:36:19 +00003379 TemplateArgumentLocInventIterator operator++(int) {
3380 TemplateArgumentLocInventIterator Old(*this);
3381 ++(*this);
3382 return Old;
3383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregorfe921a72010-12-20 23:36:19 +00003385 reference operator*() const {
3386 TemplateArgumentLoc Result;
3387 Self.InventTemplateArgumentLoc(*Iter, Result);
3388 return Result;
3389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003390
Douglas Gregorfe921a72010-12-20 23:36:19 +00003391 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregorfe921a72010-12-20 23:36:19 +00003393 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3394 const TemplateArgumentLocInventIterator &Y) {
3395 return X.Iter == Y.Iter;
3396 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003397
Douglas Gregorfe921a72010-12-20 23:36:19 +00003398 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3399 const TemplateArgumentLocInventIterator &Y) {
3400 return X.Iter != Y.Iter;
3401 }
3402};
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor42cafa82010-12-20 17:42:22 +00003404template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003405template<typename InputIterator>
3406bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3407 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003408 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003409 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003410 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003411 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003413 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3414 // Unpack argument packs, which we translate them into separate
3415 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003416 // FIXME: We could do much better if we could guarantee that the
3417 // TemplateArgumentLocInfo for the pack expansion would be usable for
3418 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003419 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003420 TemplateArgument::pack_iterator>
3421 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003422 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003423 In.getArgument().pack_begin()),
3424 PackLocIterator(*this,
3425 In.getArgument().pack_end()),
3426 Outputs))
3427 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003429 continue;
3430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003432 if (In.getArgument().isPackExpansion()) {
3433 // We have a pack expansion, for which we will be substituting into
3434 // the pattern.
3435 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003436 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003437 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003438 = getSema().getTemplateArgumentPackExpansionPattern(
3439 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Chris Lattner01cf8db2011-07-20 06:58:45 +00003441 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003442 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3443 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003445 // Determine whether the set of unexpanded parameter packs can and should
3446 // be expanded.
3447 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003448 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003449 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003450 if (getDerived().TryExpandParameterPacks(Ellipsis,
3451 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003452 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003453 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003454 RetainExpansion,
3455 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003456 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003458 if (!Expand) {
3459 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003460 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003461 // expansion.
3462 TemplateArgumentLoc OutPattern;
3463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3464 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3465 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003467 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3468 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003469 if (Out.getArgument().isNull())
3470 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003471
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003472 Outputs.addArgument(Out);
3473 continue;
3474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003476 // The transform has determined that we should perform an elementwise
3477 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003478 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3480
3481 if (getDerived().TransformTemplateArgument(Pattern, Out))
3482 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003484 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003485 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3486 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003487 if (Out.getArgument().isNull())
3488 return true;
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003491 Outputs.addArgument(Out);
3492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregor48d24112011-01-10 20:53:55 +00003494 // If we're supposed to retain a pack expansion, do so by temporarily
3495 // forgetting the partially-substituted parameter pack.
3496 if (RetainExpansion) {
3497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor48d24112011-01-10 20:53:55 +00003499 if (getDerived().TransformTemplateArgument(Pattern, Out))
3500 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003501
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003502 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3503 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003504 if (Out.getArgument().isNull())
3505 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregor48d24112011-01-10 20:53:55 +00003507 Outputs.addArgument(Out);
3508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003510 continue;
3511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
3513 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003514 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003515 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregor42cafa82010-12-20 17:42:22 +00003517 Outputs.addArgument(Out);
3518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregor42cafa82010-12-20 17:42:22 +00003520 return false;
3521
3522}
3523
Douglas Gregord6ff3322009-08-04 16:50:30 +00003524//===----------------------------------------------------------------------===//
3525// Type transformation
3526//===----------------------------------------------------------------------===//
3527
3528template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003529QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003530 if (getDerived().AlreadyTransformed(T))
3531 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003532
John McCall550e0c22009-10-21 00:40:46 +00003533 // Temporary workaround. All of these transformations should
3534 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003535 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3536 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
John McCall31f82722010-11-12 08:19:04 +00003538 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003539
John McCall550e0c22009-10-21 00:40:46 +00003540 if (!NewDI)
3541 return QualType();
3542
3543 return NewDI->getType();
3544}
3545
3546template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003547TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003548 // Refine the base location to the type's location.
3549 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3550 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003551 if (getDerived().AlreadyTransformed(DI->getType()))
3552 return DI;
3553
3554 TypeLocBuilder TLB;
3555
3556 TypeLoc TL = DI->getTypeLoc();
3557 TLB.reserve(TL.getFullDataSize());
3558
John McCall31f82722010-11-12 08:19:04 +00003559 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003560 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003561 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003562
John McCallbcd03502009-12-07 02:54:59 +00003563 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003564}
3565
3566template<typename Derived>
3567QualType
John McCall31f82722010-11-12 08:19:04 +00003568TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003569 switch (T.getTypeLocClass()) {
3570#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003571#define TYPELOC(CLASS, PARENT) \
3572 case TypeLoc::CLASS: \
3573 return getDerived().Transform##CLASS##Type(TLB, \
3574 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003575#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576 }
Mike Stump11289f42009-09-09 15:08:12 +00003577
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003578 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003579}
3580
3581/// FIXME: By default, this routine adds type qualifiers only to types
3582/// that can have qualifiers, and silently suppresses those qualifiers
3583/// that are not permitted (e.g., qualifiers on reference or function
3584/// types). This is the right thing for template instantiation, but
3585/// probably not for other clients.
3586template<typename Derived>
3587QualType
3588TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003589 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003590 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003591
John McCall31f82722010-11-12 08:19:04 +00003592 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003593 if (Result.isNull())
3594 return QualType();
3595
3596 // Silently suppress qualifiers if the result type can't be qualified.
3597 // FIXME: this is the right thing for template instantiation, but
3598 // probably not for other clients.
3599 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003600 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003601
John McCall31168b02011-06-15 23:02:42 +00003602 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003603 // resulting type.
3604 if (Quals.hasObjCLifetime()) {
3605 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3606 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003607 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003608 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003609 // A lifetime qualifier applied to a substituted template parameter
3610 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003611 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003612 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003613 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3614 QualType Replacement = SubstTypeParam->getReplacementType();
3615 Qualifiers Qs = Replacement.getQualifiers();
3616 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003617 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003618 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3619 Qs);
3620 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003621 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003622 Replacement);
3623 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003624 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3625 // 'auto' types behave the same way as template parameters.
3626 QualType Deduced = AutoTy->getDeducedType();
3627 Qualifiers Qs = Deduced.getQualifiers();
3628 Qs.removeObjCLifetime();
3629 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3630 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003631 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3632 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003633 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003634 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003635 // Otherwise, complain about the addition of a qualifier to an
3636 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003637 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003638 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003639 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Douglas Gregore46db902011-06-17 22:11:49 +00003641 Quals.removeObjCLifetime();
3642 }
3643 }
3644 }
John McCallcb0f89a2010-06-05 06:41:15 +00003645 if (!Quals.empty()) {
3646 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003647 // BuildQualifiedType might not add qualifiers if they are invalid.
3648 if (Result.hasLocalQualifiers())
3649 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003650 // No location information to preserve.
3651 }
John McCall550e0c22009-10-21 00:40:46 +00003652
3653 return Result;
3654}
3655
Douglas Gregor14454802011-02-25 02:25:35 +00003656template<typename Derived>
3657TypeLoc
3658TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3659 QualType ObjectType,
3660 NamedDecl *UnqualLookup,
3661 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003662 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003663 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003665 TypeSourceInfo *TSI =
3666 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3667 if (TSI)
3668 return TSI->getTypeLoc();
3669 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003670}
3671
Douglas Gregor579c15f2011-03-02 18:32:08 +00003672template<typename Derived>
3673TypeSourceInfo *
3674TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3675 QualType ObjectType,
3676 NamedDecl *UnqualLookup,
3677 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003678 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003681 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3682 UnqualLookup, SS);
3683}
3684
3685template <typename Derived>
3686TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3687 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3688 CXXScopeSpec &SS) {
3689 QualType T = TL.getType();
3690 assert(!getDerived().AlreadyTransformed(T));
3691
Douglas Gregor579c15f2011-03-02 18:32:08 +00003692 TypeLocBuilder TLB;
3693 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregor579c15f2011-03-02 18:32:08 +00003695 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003696 TemplateSpecializationTypeLoc SpecTL =
3697 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor579c15f2011-03-02 18:32:08 +00003699 TemplateName Template
3700 = getDerived().TransformTemplateName(SS,
3701 SpecTL.getTypePtr()->getTemplateName(),
3702 SpecTL.getTemplateNameLoc(),
3703 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003704 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003705 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
3707 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003708 Template);
3709 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003710 DependentTemplateSpecializationTypeLoc SpecTL =
3711 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003712
Douglas Gregor579c15f2011-03-02 18:32:08 +00003713 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003714 = getDerived().RebuildTemplateName(SS,
3715 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003716 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003717 ObjectType, UnqualLookup);
3718 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003719 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
3721 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003722 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003723 Template,
3724 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003725 } else {
3726 // Nothing special needs to be done for these.
3727 Result = getDerived().TransformType(TLB, TL);
3728 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003729
3730 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003731 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Douglas Gregor579c15f2011-03-02 18:32:08 +00003733 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3734}
3735
John McCall550e0c22009-10-21 00:40:46 +00003736template <class TyLoc> static inline
3737QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3738 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3739 NewT.setNameLoc(T.getNameLoc());
3740 return T.getType();
3741}
3742
John McCall550e0c22009-10-21 00:40:46 +00003743template<typename Derived>
3744QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003745 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003746 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3747 NewT.setBuiltinLoc(T.getBuiltinLoc());
3748 if (T.needsExtraLocalData())
3749 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3750 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751}
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregord6ff3322009-08-04 16:50:30 +00003753template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003754QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003755 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003756 // FIXME: recurse?
3757 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003758}
Mike Stump11289f42009-09-09 15:08:12 +00003759
Reid Kleckner0503a872013-12-05 01:23:43 +00003760template <typename Derived>
3761QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3762 AdjustedTypeLoc TL) {
3763 // Adjustments applied during transformation are handled elsewhere.
3764 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3765}
3766
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003768QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3769 DecayedTypeLoc TL) {
3770 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3771 if (OriginalType.isNull())
3772 return QualType();
3773
3774 QualType Result = TL.getType();
3775 if (getDerived().AlwaysRebuild() ||
3776 OriginalType != TL.getOriginalLoc().getType())
3777 Result = SemaRef.Context.getDecayedType(OriginalType);
3778 TLB.push<DecayedTypeLoc>(Result);
3779 // Nothing to set for DecayedTypeLoc.
3780 return Result;
3781}
3782
3783template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003784QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003785 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003786 QualType PointeeType
3787 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003788 if (PointeeType.isNull())
3789 return QualType();
3790
3791 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003792 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003793 // A dependent pointer type 'T *' has is being transformed such
3794 // that an Objective-C class type is being replaced for 'T'. The
3795 // resulting pointer type is an ObjCObjectPointerType, not a
3796 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003797 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
John McCall8b07ec22010-05-15 11:32:37 +00003799 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3800 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003801 return Result;
3802 }
John McCall31f82722010-11-12 08:19:04 +00003803
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003804 if (getDerived().AlwaysRebuild() ||
3805 PointeeType != TL.getPointeeLoc().getType()) {
3806 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3807 if (Result.isNull())
3808 return QualType();
3809 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
John McCall31168b02011-06-15 23:02:42 +00003811 // Objective-C ARC can add lifetime qualifiers to the type that we're
3812 // pointing to.
3813 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003815 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3816 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003817 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
3820template<typename Derived>
3821QualType
John McCall550e0c22009-10-21 00:40:46 +00003822TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003823 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003824 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003825 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3826 if (PointeeType.isNull())
3827 return QualType();
3828
3829 QualType Result = TL.getType();
3830 if (getDerived().AlwaysRebuild() ||
3831 PointeeType != TL.getPointeeLoc().getType()) {
3832 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003833 TL.getSigilLoc());
3834 if (Result.isNull())
3835 return QualType();
3836 }
3837
Douglas Gregor049211a2010-04-22 16:50:51 +00003838 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003839 NewT.setSigilLoc(TL.getSigilLoc());
3840 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003841}
3842
John McCall70dd5f62009-10-30 00:06:24 +00003843/// Transforms a reference type. Note that somewhat paradoxically we
3844/// don't care whether the type itself is an l-value type or an r-value
3845/// type; we only care if the type was *written* as an l-value type
3846/// or an r-value type.
3847template<typename Derived>
3848QualType
3849TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003850 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003851 const ReferenceType *T = TL.getTypePtr();
3852
3853 // Note that this works with the pointee-as-written.
3854 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3855 if (PointeeType.isNull())
3856 return QualType();
3857
3858 QualType Result = TL.getType();
3859 if (getDerived().AlwaysRebuild() ||
3860 PointeeType != T->getPointeeTypeAsWritten()) {
3861 Result = getDerived().RebuildReferenceType(PointeeType,
3862 T->isSpelledAsLValue(),
3863 TL.getSigilLoc());
3864 if (Result.isNull())
3865 return QualType();
3866 }
3867
John McCall31168b02011-06-15 23:02:42 +00003868 // Objective-C ARC can add lifetime qualifiers to the type that we're
3869 // referring to.
3870 TLB.TypeWasModifiedSafely(
3871 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3872
John McCall70dd5f62009-10-30 00:06:24 +00003873 // r-value references can be rebuilt as l-value references.
3874 ReferenceTypeLoc NewTL;
3875 if (isa<LValueReferenceType>(Result))
3876 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3877 else
3878 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3879 NewTL.setSigilLoc(TL.getSigilLoc());
3880
3881 return Result;
3882}
3883
Mike Stump11289f42009-09-09 15:08:12 +00003884template<typename Derived>
3885QualType
John McCall550e0c22009-10-21 00:40:46 +00003886TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003887 LValueReferenceTypeLoc TL) {
3888 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889}
3890
Mike Stump11289f42009-09-09 15:08:12 +00003891template<typename Derived>
3892QualType
John McCall550e0c22009-10-21 00:40:46 +00003893TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003894 RValueReferenceTypeLoc TL) {
3895 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003896}
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregord6ff3322009-08-04 16:50:30 +00003898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003899QualType
John McCall550e0c22009-10-21 00:40:46 +00003900TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003901 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003902 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003903 if (PointeeType.isNull())
3904 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003905
Abramo Bagnara509357842011-03-05 14:42:21 +00003906 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003907 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003908 if (OldClsTInfo) {
3909 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3910 if (!NewClsTInfo)
3911 return QualType();
3912 }
3913
3914 const MemberPointerType *T = TL.getTypePtr();
3915 QualType OldClsType = QualType(T->getClass(), 0);
3916 QualType NewClsType;
3917 if (NewClsTInfo)
3918 NewClsType = NewClsTInfo->getType();
3919 else {
3920 NewClsType = getDerived().TransformType(OldClsType);
3921 if (NewClsType.isNull())
3922 return QualType();
3923 }
Mike Stump11289f42009-09-09 15:08:12 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 QualType Result = TL.getType();
3926 if (getDerived().AlwaysRebuild() ||
3927 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003928 NewClsType != OldClsType) {
3929 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003930 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003931 if (Result.isNull())
3932 return QualType();
3933 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934
Reid Kleckner0503a872013-12-05 01:23:43 +00003935 // If we had to adjust the pointee type when building a member pointer, make
3936 // sure to push TypeLoc info for it.
3937 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3938 if (MPT && PointeeType != MPT->getPointeeType()) {
3939 assert(isa<AdjustedType>(MPT->getPointeeType()));
3940 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3941 }
3942
John McCall550e0c22009-10-21 00:40:46 +00003943 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3944 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003945 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003946
3947 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948}
3949
Mike Stump11289f42009-09-09 15:08:12 +00003950template<typename Derived>
3951QualType
John McCall550e0c22009-10-21 00:40:46 +00003952TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003953 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003954 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003955 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003956 if (ElementType.isNull())
3957 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003958
John McCall550e0c22009-10-21 00:40:46 +00003959 QualType Result = TL.getType();
3960 if (getDerived().AlwaysRebuild() ||
3961 ElementType != T->getElementType()) {
3962 Result = getDerived().RebuildConstantArrayType(ElementType,
3963 T->getSizeModifier(),
3964 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003965 T->getIndexTypeCVRQualifiers(),
3966 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003967 if (Result.isNull())
3968 return QualType();
3969 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003970
3971 // We might have either a ConstantArrayType or a VariableArrayType now:
3972 // a ConstantArrayType is allowed to have an element type which is a
3973 // VariableArrayType if the type is dependent. Fortunately, all array
3974 // types have the same location layout.
3975 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003976 NewTL.setLBracketLoc(TL.getLBracketLoc());
3977 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003978
John McCall550e0c22009-10-21 00:40:46 +00003979 Expr *Size = TL.getSizeExpr();
3980 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003981 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3982 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003983 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3984 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003985 }
3986 NewTL.setSizeExpr(Size);
3987
3988 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989}
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregord6ff3322009-08-04 16:50:30 +00003991template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003993 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003994 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003995 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003996 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997 if (ElementType.isNull())
3998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall550e0c22009-10-21 00:40:46 +00004000 QualType Result = TL.getType();
4001 if (getDerived().AlwaysRebuild() ||
4002 ElementType != T->getElementType()) {
4003 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004004 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004005 T->getIndexTypeCVRQualifiers(),
4006 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004007 if (Result.isNull())
4008 return QualType();
4009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004010
John McCall550e0c22009-10-21 00:40:46 +00004011 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4012 NewTL.setLBracketLoc(TL.getLBracketLoc());
4013 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004014 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004015
4016 return Result;
4017}
4018
4019template<typename Derived>
4020QualType
4021TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004022 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004023 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004024 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4025 if (ElementType.isNull())
4026 return QualType();
4027
John McCalldadc5752010-08-24 06:29:42 +00004028 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004029 = getDerived().TransformExpr(T->getSizeExpr());
4030 if (SizeResult.isInvalid())
4031 return QualType();
4032
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004033 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004034
4035 QualType Result = TL.getType();
4036 if (getDerived().AlwaysRebuild() ||
4037 ElementType != T->getElementType() ||
4038 Size != T->getSizeExpr()) {
4039 Result = getDerived().RebuildVariableArrayType(ElementType,
4040 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004041 Size,
John McCall550e0c22009-10-21 00:40:46 +00004042 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004043 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004044 if (Result.isNull())
4045 return QualType();
4046 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004047
Serge Pavlov774c6d02014-02-06 03:49:11 +00004048 // We might have constant size array now, but fortunately it has the same
4049 // location layout.
4050 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004051 NewTL.setLBracketLoc(TL.getLBracketLoc());
4052 NewTL.setRBracketLoc(TL.getRBracketLoc());
4053 NewTL.setSizeExpr(Size);
4054
4055 return Result;
4056}
4057
4058template<typename Derived>
4059QualType
4060TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004061 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004062 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004063 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4064 if (ElementType.isNull())
4065 return QualType();
4066
Richard Smith764d2fe2011-12-20 02:08:33 +00004067 // Array bounds are constant expressions.
4068 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4069 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004070
John McCall33ddac02011-01-19 10:06:00 +00004071 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4072 Expr *origSize = TL.getSizeExpr();
4073 if (!origSize) origSize = T->getSizeExpr();
4074
4075 ExprResult sizeResult
4076 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004077 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004078 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004079 return QualType();
4080
John McCall33ddac02011-01-19 10:06:00 +00004081 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004082
4083 QualType Result = TL.getType();
4084 if (getDerived().AlwaysRebuild() ||
4085 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004086 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004087 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4088 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004089 size,
John McCall550e0c22009-10-21 00:40:46 +00004090 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004091 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004092 if (Result.isNull())
4093 return QualType();
4094 }
John McCall550e0c22009-10-21 00:40:46 +00004095
4096 // We might have any sort of array type now, but fortunately they
4097 // all have the same location layout.
4098 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4099 NewTL.setLBracketLoc(TL.getLBracketLoc());
4100 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004101 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004102
4103 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
4106template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004108 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004109 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004110 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004111
4112 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004113 QualType ElementType = getDerived().TransformType(T->getElementType());
4114 if (ElementType.isNull())
4115 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004116
Richard Smith764d2fe2011-12-20 02:08:33 +00004117 // Vector sizes are constant expressions.
4118 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4119 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004120
John McCalldadc5752010-08-24 06:29:42 +00004121 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004122 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123 if (Size.isInvalid())
4124 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004128 ElementType != T->getElementType() ||
4129 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004130 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004131 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004133 if (Result.isNull())
4134 return QualType();
4135 }
John McCall550e0c22009-10-21 00:40:46 +00004136
4137 // Result might be dependent or not.
4138 if (isa<DependentSizedExtVectorType>(Result)) {
4139 DependentSizedExtVectorTypeLoc NewTL
4140 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4141 NewTL.setNameLoc(TL.getNameLoc());
4142 } else {
4143 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4144 NewTL.setNameLoc(TL.getNameLoc());
4145 }
4146
4147 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148}
Mike Stump11289f42009-09-09 15:08:12 +00004149
4150template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004151QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004152 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004153 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004154 QualType ElementType = getDerived().TransformType(T->getElementType());
4155 if (ElementType.isNull())
4156 return QualType();
4157
John McCall550e0c22009-10-21 00:40:46 +00004158 QualType Result = TL.getType();
4159 if (getDerived().AlwaysRebuild() ||
4160 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004161 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004162 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004163 if (Result.isNull())
4164 return QualType();
4165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004166
John McCall550e0c22009-10-21 00:40:46 +00004167 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4168 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004169
John McCall550e0c22009-10-21 00:40:46 +00004170 return Result;
4171}
4172
4173template<typename Derived>
4174QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004175 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004176 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004177 QualType ElementType = getDerived().TransformType(T->getElementType());
4178 if (ElementType.isNull())
4179 return QualType();
4180
4181 QualType Result = TL.getType();
4182 if (getDerived().AlwaysRebuild() ||
4183 ElementType != T->getElementType()) {
4184 Result = getDerived().RebuildExtVectorType(ElementType,
4185 T->getNumElements(),
4186 /*FIXME*/ SourceLocation());
4187 if (Result.isNull())
4188 return QualType();
4189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004190
John McCall550e0c22009-10-21 00:40:46 +00004191 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4192 NewTL.setNameLoc(TL.getNameLoc());
4193
4194 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195}
Mike Stump11289f42009-09-09 15:08:12 +00004196
David Blaikie05785d12013-02-20 22:23:23 +00004197template <typename Derived>
4198ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4199 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4200 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004201 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004202 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004203
Douglas Gregor715e4612011-01-14 22:40:04 +00004204 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004205 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004206 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004207 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004208 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004209
Douglas Gregor715e4612011-01-14 22:40:04 +00004210 TypeLocBuilder TLB;
4211 TypeLoc NewTL = OldDI->getTypeLoc();
4212 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004213
4214 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004215 OldExpansionTL.getPatternLoc());
4216 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004217 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004218
4219 Result = RebuildPackExpansionType(Result,
4220 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004221 OldExpansionTL.getEllipsisLoc(),
4222 NumExpansions);
4223 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004224 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004225
Douglas Gregor715e4612011-01-14 22:40:04 +00004226 PackExpansionTypeLoc NewExpansionTL
4227 = TLB.push<PackExpansionTypeLoc>(Result);
4228 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4229 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4230 } else
4231 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004232 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004233 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004234
John McCall8fb0d9d2011-05-01 22:35:37 +00004235 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004236 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004237
4238 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4239 OldParm->getDeclContext(),
4240 OldParm->getInnerLocStart(),
4241 OldParm->getLocation(),
4242 OldParm->getIdentifier(),
4243 NewDI->getType(),
4244 NewDI,
4245 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004246 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004247 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4248 OldParm->getFunctionScopeIndex() + indexAdjustment);
4249 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004250}
4251
4252template<typename Derived>
4253bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004254 TransformFunctionTypeParams(SourceLocation Loc,
4255 ParmVarDecl **Params, unsigned NumParams,
4256 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004257 SmallVectorImpl<QualType> &OutParamTypes,
4258 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004259 int indexAdjustment = 0;
4260
Douglas Gregordd472162011-01-07 00:20:55 +00004261 for (unsigned i = 0; i != NumParams; ++i) {
4262 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004263 assert(OldParm->getFunctionScopeIndex() == i);
4264
David Blaikie05785d12013-02-20 22:23:23 +00004265 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004266 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004267 if (OldParm->isParameterPack()) {
4268 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004269 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004270
Douglas Gregor5499af42011-01-05 23:12:31 +00004271 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004272 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004273 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004274 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4275 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004276 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4277
Douglas Gregor5499af42011-01-05 23:12:31 +00004278 // Determine whether we should expand the parameter packs.
4279 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004280 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004281 Optional<unsigned> OrigNumExpansions =
4282 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004283 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004284 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4285 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004286 Unexpanded,
4287 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004288 RetainExpansion,
4289 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004290 return true;
4291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004292
Douglas Gregor5499af42011-01-05 23:12:31 +00004293 if (ShouldExpand) {
4294 // Expand the function parameter pack into multiple, separate
4295 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004296 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004297 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004298 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004299 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004300 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004301 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004302 OrigNumExpansions,
4303 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004304 if (!NewParm)
4305 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004306
Douglas Gregordd472162011-01-07 00:20:55 +00004307 OutParamTypes.push_back(NewParm->getType());
4308 if (PVars)
4309 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004310 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004311
4312 // If we're supposed to retain a pack expansion, do so by temporarily
4313 // forgetting the partially-substituted parameter pack.
4314 if (RetainExpansion) {
4315 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004316 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004317 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004318 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004319 OrigNumExpansions,
4320 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004321 if (!NewParm)
4322 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004323
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004324 OutParamTypes.push_back(NewParm->getType());
4325 if (PVars)
4326 PVars->push_back(NewParm);
4327 }
4328
John McCall8fb0d9d2011-05-01 22:35:37 +00004329 // The next parameter should have the same adjustment as the
4330 // last thing we pushed, but we post-incremented indexAdjustment
4331 // on every push. Also, if we push nothing, the adjustment should
4332 // go down by one.
4333 indexAdjustment--;
4334
Douglas Gregor5499af42011-01-05 23:12:31 +00004335 // We're done with the pack expansion.
4336 continue;
4337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004338
4339 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004340 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004341 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4342 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004343 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004344 NumExpansions,
4345 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004346 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004347 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004348 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004349 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004350
John McCall58f10c32010-03-11 09:03:00 +00004351 if (!NewParm)
4352 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004353
Douglas Gregordd472162011-01-07 00:20:55 +00004354 OutParamTypes.push_back(NewParm->getType());
4355 if (PVars)
4356 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004357 continue;
4358 }
John McCall58f10c32010-03-11 09:03:00 +00004359
4360 // Deal with the possibility that we don't have a parameter
4361 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004362 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004363 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004364 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004365 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004367 = dyn_cast<PackExpansionType>(OldType)) {
4368 // We have a function parameter pack that may need to be expanded.
4369 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004370 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004371 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor5499af42011-01-05 23:12:31 +00004373 // Determine whether we should expand the parameter packs.
4374 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004375 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004376 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004377 Unexpanded,
4378 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004379 RetainExpansion,
4380 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004381 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004383
Douglas Gregor5499af42011-01-05 23:12:31 +00004384 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004385 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004386 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004387 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004388 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4389 QualType NewType = getDerived().TransformType(Pattern);
4390 if (NewType.isNull())
4391 return true;
John McCall58f10c32010-03-11 09:03:00 +00004392
Douglas Gregordd472162011-01-07 00:20:55 +00004393 OutParamTypes.push_back(NewType);
4394 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004395 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004397
Douglas Gregor5499af42011-01-05 23:12:31 +00004398 // We're done with the pack expansion.
4399 continue;
4400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
Douglas Gregor48d24112011-01-10 20:53:55 +00004402 // If we're supposed to retain a pack expansion, do so by temporarily
4403 // forgetting the partially-substituted parameter pack.
4404 if (RetainExpansion) {
4405 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4406 QualType NewType = getDerived().TransformType(Pattern);
4407 if (NewType.isNull())
4408 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004409
Douglas Gregor48d24112011-01-10 20:53:55 +00004410 OutParamTypes.push_back(NewType);
4411 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004412 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004413 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004414
Chad Rosier1dcde962012-08-08 18:46:20 +00004415 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004416 // expansion.
4417 OldType = Expansion->getPattern();
4418 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004419 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4420 NewType = getDerived().TransformType(OldType);
4421 } else {
4422 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 if (NewType.isNull())
4426 return true;
4427
4428 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004429 NewType = getSema().Context.getPackExpansionType(NewType,
4430 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004431
Douglas Gregordd472162011-01-07 00:20:55 +00004432 OutParamTypes.push_back(NewType);
4433 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004434 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004435 }
4436
John McCall8fb0d9d2011-05-01 22:35:37 +00004437#ifndef NDEBUG
4438 if (PVars) {
4439 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4440 if (ParmVarDecl *parm = (*PVars)[i])
4441 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004442 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004443#endif
4444
4445 return false;
4446}
John McCall58f10c32010-03-11 09:03:00 +00004447
4448template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004449QualType
John McCall550e0c22009-10-21 00:40:46 +00004450TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004451 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004452 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004453}
4454
4455template<typename Derived>
4456QualType
4457TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4458 FunctionProtoTypeLoc TL,
4459 CXXRecordDecl *ThisContext,
4460 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004461 // Transform the parameters and return type.
4462 //
Richard Smithf623c962012-04-17 00:58:00 +00004463 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004464 // When the function has a trailing return type, we instantiate the
4465 // parameters before the return type, since the return type can then refer
4466 // to the parameters themselves (via decltype, sizeof, etc.).
4467 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004468 SmallVector<QualType, 4> ParamTypes;
4469 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004470 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004471
Douglas Gregor7fb25412010-10-01 18:44:50 +00004472 QualType ResultType;
4473
Richard Smith1226c602012-08-14 22:51:13 +00004474 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004475 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004476 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004477 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004478 return QualType();
4479
Douglas Gregor3024f072012-04-16 07:05:22 +00004480 {
4481 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004482 // If a declaration declares a member function or member function
4483 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004484 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004485 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004486 // declarator.
4487 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
Alp Toker42a16a62014-01-25 23:51:36 +00004489 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004490 if (ResultType.isNull())
4491 return QualType();
4492 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004493 }
4494 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004495 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004496 if (ResultType.isNull())
4497 return QualType();
4498
Alp Toker9cacbab2014-01-20 20:26:09 +00004499 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004500 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004501 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004502 return QualType();
4503 }
4504
Richard Smithf623c962012-04-17 00:58:00 +00004505 // FIXME: Need to transform the exception-specification too.
4506
John McCall550e0c22009-10-21 00:40:46 +00004507 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004508 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004509 T->getNumParams() != ParamTypes.size() ||
4510 !std::equal(T->param_type_begin(), T->param_type_end(),
4511 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004512 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004513 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004514 if (Result.isNull())
4515 return QualType();
4516 }
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCall550e0c22009-10-21 00:40:46 +00004518 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004519 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004520 NewTL.setLParenLoc(TL.getLParenLoc());
4521 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004522 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004523 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4524 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004525
4526 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004527}
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529template<typename Derived>
4530QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004531 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004532 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004533 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004534 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004535 if (ResultType.isNull())
4536 return QualType();
4537
4538 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004539 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004540 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4541
4542 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004543 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004544 NewTL.setLParenLoc(TL.getLParenLoc());
4545 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004546 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004547
4548 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549}
Mike Stump11289f42009-09-09 15:08:12 +00004550
John McCallb96ec562009-12-04 22:46:56 +00004551template<typename Derived> QualType
4552TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004553 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004554 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004555 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004556 if (!D)
4557 return QualType();
4558
4559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4561 Result = getDerived().RebuildUnresolvedUsingType(D);
4562 if (Result.isNull())
4563 return QualType();
4564 }
4565
4566 // We might get an arbitrary type spec type back. We should at
4567 // least always get a type spec type, though.
4568 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570
4571 return Result;
4572}
4573
Douglas Gregord6ff3322009-08-04 16:50:30 +00004574template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004575QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004576 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004577 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004578 TypedefNameDecl *Typedef
4579 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4580 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004581 if (!Typedef)
4582 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004583
John McCall550e0c22009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 Typedef != T->getDecl()) {
4587 Result = getDerived().RebuildTypedefType(Typedef);
4588 if (Result.isNull())
4589 return QualType();
4590 }
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall550e0c22009-10-21 00:40:46 +00004592 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4593 NewTL.setNameLoc(TL.getNameLoc());
4594
4595 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004596}
Mike Stump11289f42009-09-09 15:08:12 +00004597
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004599QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004600 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004601 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004602 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4603 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004604
John McCalldadc5752010-08-24 06:29:42 +00004605 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004606 if (E.isInvalid())
4607 return QualType();
4608
Eli Friedmane4f22df2012-02-29 04:03:55 +00004609 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4610 if (E.isInvalid())
4611 return QualType();
4612
John McCall550e0c22009-10-21 00:40:46 +00004613 QualType Result = TL.getType();
4614 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004615 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004616 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004617 if (Result.isNull())
4618 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004619 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004620 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCall550e0c22009-10-21 00:40:46 +00004622 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004623 NewTL.setTypeofLoc(TL.getTypeofLoc());
4624 NewTL.setLParenLoc(TL.getLParenLoc());
4625 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004626
4627 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628}
Mike Stump11289f42009-09-09 15:08:12 +00004629
4630template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004631QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004632 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004633 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4634 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4635 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004637
John McCall550e0c22009-10-21 00:40:46 +00004638 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004639 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4640 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004641 if (Result.isNull())
4642 return QualType();
4643 }
Mike Stump11289f42009-09-09 15:08:12 +00004644
John McCall550e0c22009-10-21 00:40:46 +00004645 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004646 NewTL.setTypeofLoc(TL.getTypeofLoc());
4647 NewTL.setLParenLoc(TL.getLParenLoc());
4648 NewTL.setRParenLoc(TL.getRParenLoc());
4649 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004650
4651 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652}
Mike Stump11289f42009-09-09 15:08:12 +00004653
4654template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004655QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004657 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004658
Douglas Gregore922c772009-08-04 22:27:00 +00004659 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4661 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCalldadc5752010-08-24 06:29:42 +00004663 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004664 if (E.isInvalid())
4665 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004666
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004667 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004668 if (E.isInvalid())
4669 return QualType();
4670
John McCall550e0c22009-10-21 00:40:46 +00004671 QualType Result = TL.getType();
4672 if (getDerived().AlwaysRebuild() ||
4673 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004674 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004675 if (Result.isNull())
4676 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004677 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004678 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004679
John McCall550e0c22009-10-21 00:40:46 +00004680 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4681 NewTL.setNameLoc(TL.getNameLoc());
4682
4683 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004684}
4685
4686template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004687QualType TreeTransform<Derived>::TransformUnaryTransformType(
4688 TypeLocBuilder &TLB,
4689 UnaryTransformTypeLoc TL) {
4690 QualType Result = TL.getType();
4691 if (Result->isDependentType()) {
4692 const UnaryTransformType *T = TL.getTypePtr();
4693 QualType NewBase =
4694 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4695 Result = getDerived().RebuildUnaryTransformType(NewBase,
4696 T->getUTTKind(),
4697 TL.getKWLoc());
4698 if (Result.isNull())
4699 return QualType();
4700 }
4701
4702 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4703 NewTL.setKWLoc(TL.getKWLoc());
4704 NewTL.setParensRange(TL.getParensRange());
4705 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4706 return Result;
4707}
4708
4709template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004710QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4711 AutoTypeLoc TL) {
4712 const AutoType *T = TL.getTypePtr();
4713 QualType OldDeduced = T->getDeducedType();
4714 QualType NewDeduced;
4715 if (!OldDeduced.isNull()) {
4716 NewDeduced = getDerived().TransformType(OldDeduced);
4717 if (NewDeduced.isNull())
4718 return QualType();
4719 }
4720
4721 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004722 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4723 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004724 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004725 if (Result.isNull())
4726 return QualType();
4727 }
4728
4729 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4730 NewTL.setNameLoc(TL.getNameLoc());
4731
4732 return Result;
4733}
4734
4735template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004736QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004737 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004738 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004740 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4741 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742 if (!Record)
4743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004744
John McCall550e0c22009-10-21 00:40:46 +00004745 QualType Result = TL.getType();
4746 if (getDerived().AlwaysRebuild() ||
4747 Record != T->getDecl()) {
4748 Result = getDerived().RebuildRecordType(Record);
4749 if (Result.isNull())
4750 return QualType();
4751 }
Mike Stump11289f42009-09-09 15:08:12 +00004752
John McCall550e0c22009-10-21 00:40:46 +00004753 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4754 NewTL.setNameLoc(TL.getNameLoc());
4755
4756 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757}
Mike Stump11289f42009-09-09 15:08:12 +00004758
4759template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004760QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004761 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004762 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004763 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004764 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4765 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004766 if (!Enum)
4767 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004768
John McCall550e0c22009-10-21 00:40:46 +00004769 QualType Result = TL.getType();
4770 if (getDerived().AlwaysRebuild() ||
4771 Enum != T->getDecl()) {
4772 Result = getDerived().RebuildEnumType(Enum);
4773 if (Result.isNull())
4774 return QualType();
4775 }
Mike Stump11289f42009-09-09 15:08:12 +00004776
John McCall550e0c22009-10-21 00:40:46 +00004777 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4778 NewTL.setNameLoc(TL.getNameLoc());
4779
4780 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004781}
John McCallfcc33b02009-09-05 00:15:47 +00004782
John McCalle78aac42010-03-10 03:28:59 +00004783template<typename Derived>
4784QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4785 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004786 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004787 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4788 TL.getTypePtr()->getDecl());
4789 if (!D) return QualType();
4790
4791 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4792 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4793 return T;
4794}
4795
Douglas Gregord6ff3322009-08-04 16:50:30 +00004796template<typename Derived>
4797QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004798 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004799 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004800 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004801}
4802
Mike Stump11289f42009-09-09 15:08:12 +00004803template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004804QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004805 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004806 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004807 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004808
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004809 // Substitute into the replacement type, which itself might involve something
4810 // that needs to be transformed. This only tends to occur with default
4811 // template arguments of template template parameters.
4812 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4813 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4814 if (Replacement.isNull())
4815 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004816
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004817 // Always canonicalize the replacement type.
4818 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4819 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004820 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004821 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004822
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004823 // Propagate type-source information.
4824 SubstTemplateTypeParmTypeLoc NewTL
4825 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4826 NewTL.setNameLoc(TL.getNameLoc());
4827 return Result;
4828
John McCallcebee162009-10-18 09:09:24 +00004829}
4830
4831template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004832QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4833 TypeLocBuilder &TLB,
4834 SubstTemplateTypeParmPackTypeLoc TL) {
4835 return TransformTypeSpecType(TLB, TL);
4836}
4837
4838template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004839QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004840 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004841 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004842 const TemplateSpecializationType *T = TL.getTypePtr();
4843
Douglas Gregordf846d12011-03-02 18:46:51 +00004844 // The nested-name-specifier never matters in a TemplateSpecializationType,
4845 // because we can't have a dependent nested-name-specifier anyway.
4846 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004847 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004848 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4849 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004850 if (Template.isNull())
4851 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004852
John McCall31f82722010-11-12 08:19:04 +00004853 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4854}
4855
Eli Friedman0dfb8892011-10-06 23:00:33 +00004856template<typename Derived>
4857QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4858 AtomicTypeLoc TL) {
4859 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4860 if (ValueType.isNull())
4861 return QualType();
4862
4863 QualType Result = TL.getType();
4864 if (getDerived().AlwaysRebuild() ||
4865 ValueType != TL.getValueLoc().getType()) {
4866 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4867 if (Result.isNull())
4868 return QualType();
4869 }
4870
4871 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4872 NewTL.setKWLoc(TL.getKWLoc());
4873 NewTL.setLParenLoc(TL.getLParenLoc());
4874 NewTL.setRParenLoc(TL.getRParenLoc());
4875
4876 return Result;
4877}
4878
Chad Rosier1dcde962012-08-08 18:46:20 +00004879 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004880 /// container that provides a \c getArgLoc() member function.
4881 ///
4882 /// This iterator is intended to be used with the iterator form of
4883 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4884 template<typename ArgLocContainer>
4885 class TemplateArgumentLocContainerIterator {
4886 ArgLocContainer *Container;
4887 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregorfe921a72010-12-20 23:36:19 +00004889 public:
4890 typedef TemplateArgumentLoc value_type;
4891 typedef TemplateArgumentLoc reference;
4892 typedef int difference_type;
4893 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004894
Douglas Gregorfe921a72010-12-20 23:36:19 +00004895 class pointer {
4896 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004897
Douglas Gregorfe921a72010-12-20 23:36:19 +00004898 public:
4899 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004900
Douglas Gregorfe921a72010-12-20 23:36:19 +00004901 const TemplateArgumentLoc *operator->() const {
4902 return &Arg;
4903 }
4904 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004905
4906
Douglas Gregorfe921a72010-12-20 23:36:19 +00004907 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
Douglas Gregorfe921a72010-12-20 23:36:19 +00004909 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4910 unsigned Index)
4911 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
Douglas Gregorfe921a72010-12-20 23:36:19 +00004913 TemplateArgumentLocContainerIterator &operator++() {
4914 ++Index;
4915 return *this;
4916 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004917
Douglas Gregorfe921a72010-12-20 23:36:19 +00004918 TemplateArgumentLocContainerIterator operator++(int) {
4919 TemplateArgumentLocContainerIterator Old(*this);
4920 ++(*this);
4921 return Old;
4922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004923
Douglas Gregorfe921a72010-12-20 23:36:19 +00004924 TemplateArgumentLoc operator*() const {
4925 return Container->getArgLoc(Index);
4926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004927
Douglas Gregorfe921a72010-12-20 23:36:19 +00004928 pointer operator->() const {
4929 return pointer(Container->getArgLoc(Index));
4930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004931
Douglas Gregorfe921a72010-12-20 23:36:19 +00004932 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004933 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004934 return X.Container == Y.Container && X.Index == Y.Index;
4935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
Douglas Gregorfe921a72010-12-20 23:36:19 +00004937 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004938 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004939 return !(X == Y);
4940 }
4941 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004942
4943
John McCall31f82722010-11-12 08:19:04 +00004944template <typename Derived>
4945QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4946 TypeLocBuilder &TLB,
4947 TemplateSpecializationTypeLoc TL,
4948 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004949 TemplateArgumentListInfo NewTemplateArgs;
4950 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4951 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004952 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4953 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004954 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004955 ArgIterator(TL, TL.getNumArgs()),
4956 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004957 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004958
John McCall0ad16662009-10-29 08:12:44 +00004959 // FIXME: maybe don't rebuild if all the template arguments are the same.
4960
4961 QualType Result =
4962 getDerived().RebuildTemplateSpecializationType(Template,
4963 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004964 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004965
4966 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004967 // Specializations of template template parameters are represented as
4968 // TemplateSpecializationTypes, and substitution of type alias templates
4969 // within a dependent context can transform them into
4970 // DependentTemplateSpecializationTypes.
4971 if (isa<DependentTemplateSpecializationType>(Result)) {
4972 DependentTemplateSpecializationTypeLoc NewTL
4973 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004974 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004975 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004976 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004977 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004978 NewTL.setLAngleLoc(TL.getLAngleLoc());
4979 NewTL.setRAngleLoc(TL.getRAngleLoc());
4980 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4981 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4982 return Result;
4983 }
4984
John McCall0ad16662009-10-29 08:12:44 +00004985 TemplateSpecializationTypeLoc NewTL
4986 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004987 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004988 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4989 NewTL.setLAngleLoc(TL.getLAngleLoc());
4990 NewTL.setRAngleLoc(TL.getRAngleLoc());
4991 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4992 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004993 }
Mike Stump11289f42009-09-09 15:08:12 +00004994
John McCall0ad16662009-10-29 08:12:44 +00004995 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004996}
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregor5a064722011-02-28 17:23:35 +00004998template <typename Derived>
4999QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5000 TypeLocBuilder &TLB,
5001 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005002 TemplateName Template,
5003 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005004 TemplateArgumentListInfo NewTemplateArgs;
5005 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5006 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5007 typedef TemplateArgumentLocContainerIterator<
5008 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005009 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005010 ArgIterator(TL, TL.getNumArgs()),
5011 NewTemplateArgs))
5012 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005013
Douglas Gregor5a064722011-02-28 17:23:35 +00005014 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005015
Douglas Gregor5a064722011-02-28 17:23:35 +00005016 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5017 QualType Result
5018 = getSema().Context.getDependentTemplateSpecializationType(
5019 TL.getTypePtr()->getKeyword(),
5020 DTN->getQualifier(),
5021 DTN->getIdentifier(),
5022 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005023
Douglas Gregor5a064722011-02-28 17:23:35 +00005024 DependentTemplateSpecializationTypeLoc NewTL
5025 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005026 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005027 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005028 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005029 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005030 NewTL.setLAngleLoc(TL.getLAngleLoc());
5031 NewTL.setRAngleLoc(TL.getRAngleLoc());
5032 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5033 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5034 return Result;
5035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005036
5037 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005038 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005039 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005040 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005041
Douglas Gregor5a064722011-02-28 17:23:35 +00005042 if (!Result.isNull()) {
5043 /// FIXME: Wrap this in an elaborated-type-specifier?
5044 TemplateSpecializationTypeLoc NewTL
5045 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005046 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005047 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005048 NewTL.setLAngleLoc(TL.getLAngleLoc());
5049 NewTL.setRAngleLoc(TL.getRAngleLoc());
5050 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5051 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005053
Douglas Gregor5a064722011-02-28 17:23:35 +00005054 return Result;
5055}
5056
Mike Stump11289f42009-09-09 15:08:12 +00005057template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005058QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005059TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005060 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005061 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005062
Douglas Gregor844cb502011-03-01 18:12:44 +00005063 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005064 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005065 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005066 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005067 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5068 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005069 return QualType();
5070 }
Mike Stump11289f42009-09-09 15:08:12 +00005071
John McCall31f82722010-11-12 08:19:04 +00005072 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5073 if (NamedT.isNull())
5074 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005075
Richard Smith3f1b5d02011-05-05 21:57:07 +00005076 // C++0x [dcl.type.elab]p2:
5077 // If the identifier resolves to a typedef-name or the simple-template-id
5078 // resolves to an alias template specialization, the
5079 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005080 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5081 if (const TemplateSpecializationType *TST =
5082 NamedT->getAs<TemplateSpecializationType>()) {
5083 TemplateName Template = TST->getTemplateName();
5084 if (TypeAliasTemplateDecl *TAT =
5085 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5086 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5087 diag::err_tag_reference_non_tag) << 4;
5088 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5089 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005090 }
5091 }
5092
John McCall550e0c22009-10-21 00:40:46 +00005093 QualType Result = TL.getType();
5094 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005095 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005096 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005097 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005098 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005099 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005100 if (Result.isNull())
5101 return QualType();
5102 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103
Abramo Bagnara6150c882010-05-11 21:36:43 +00005104 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005105 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005106 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005108}
Mike Stump11289f42009-09-09 15:08:12 +00005109
5110template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005111QualType TreeTransform<Derived>::TransformAttributedType(
5112 TypeLocBuilder &TLB,
5113 AttributedTypeLoc TL) {
5114 const AttributedType *oldType = TL.getTypePtr();
5115 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5116 if (modifiedType.isNull())
5117 return QualType();
5118
5119 QualType result = TL.getType();
5120
5121 // FIXME: dependent operand expressions?
5122 if (getDerived().AlwaysRebuild() ||
5123 modifiedType != oldType->getModifiedType()) {
5124 // TODO: this is really lame; we should really be rebuilding the
5125 // equivalent type from first principles.
5126 QualType equivalentType
5127 = getDerived().TransformType(oldType->getEquivalentType());
5128 if (equivalentType.isNull())
5129 return QualType();
5130 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5131 modifiedType,
5132 equivalentType);
5133 }
5134
5135 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5136 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5137 if (TL.hasAttrOperand())
5138 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5139 if (TL.hasAttrExprOperand())
5140 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5141 else if (TL.hasAttrEnumOperand())
5142 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5143
5144 return result;
5145}
5146
5147template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005148QualType
5149TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5150 ParenTypeLoc TL) {
5151 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5152 if (Inner.isNull())
5153 return QualType();
5154
5155 QualType Result = TL.getType();
5156 if (getDerived().AlwaysRebuild() ||
5157 Inner != TL.getInnerLoc().getType()) {
5158 Result = getDerived().RebuildParenType(Inner);
5159 if (Result.isNull())
5160 return QualType();
5161 }
5162
5163 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5164 NewTL.setLParenLoc(TL.getLParenLoc());
5165 NewTL.setRParenLoc(TL.getRParenLoc());
5166 return Result;
5167}
5168
5169template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005170QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005171 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005172 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005173
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005174 NestedNameSpecifierLoc QualifierLoc
5175 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5176 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005177 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005178
John McCallc392f372010-06-11 00:33:02 +00005179 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005180 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005181 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005182 QualifierLoc,
5183 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005184 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005185 if (Result.isNull())
5186 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005187
Abramo Bagnarad7548482010-05-19 21:37:53 +00005188 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5189 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005190 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5191
Abramo Bagnarad7548482010-05-19 21:37:53 +00005192 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005193 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005194 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005195 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005196 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005197 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005198 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005199 NewTL.setNameLoc(TL.getNameLoc());
5200 }
John McCall550e0c22009-10-21 00:40:46 +00005201 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005202}
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregord6ff3322009-08-04 16:50:30 +00005204template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005205QualType TreeTransform<Derived>::
5206 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005207 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005208 NestedNameSpecifierLoc QualifierLoc;
5209 if (TL.getQualifierLoc()) {
5210 QualifierLoc
5211 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5212 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005213 return QualType();
5214 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005215
John McCall31f82722010-11-12 08:19:04 +00005216 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005217 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005218}
5219
5220template<typename Derived>
5221QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005222TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5223 DependentTemplateSpecializationTypeLoc TL,
5224 NestedNameSpecifierLoc QualifierLoc) {
5225 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005226
Douglas Gregora7a795b2011-03-01 20:11:18 +00005227 TemplateArgumentListInfo NewTemplateArgs;
5228 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5229 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
Douglas Gregora7a795b2011-03-01 20:11:18 +00005231 typedef TemplateArgumentLocContainerIterator<
5232 DependentTemplateSpecializationTypeLoc> ArgIterator;
5233 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5234 ArgIterator(TL, TL.getNumArgs()),
5235 NewTemplateArgs))
5236 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005237
Douglas Gregora7a795b2011-03-01 20:11:18 +00005238 QualType Result
5239 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5240 QualifierLoc,
5241 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005242 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005243 NewTemplateArgs);
5244 if (Result.isNull())
5245 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005246
Douglas Gregora7a795b2011-03-01 20:11:18 +00005247 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5248 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005249
Douglas Gregora7a795b2011-03-01 20:11:18 +00005250 // Copy information relevant to the template specialization.
5251 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005252 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005253 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005254 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005255 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5256 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005257 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005258 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005259
Douglas Gregora7a795b2011-03-01 20:11:18 +00005260 // Copy information relevant to the elaborated type.
5261 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005262 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005263 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005264 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5265 DependentTemplateSpecializationTypeLoc SpecTL
5266 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005267 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005268 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005269 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005270 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005271 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5272 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005273 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005274 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005275 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005276 TemplateSpecializationTypeLoc SpecTL
5277 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005278 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005279 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005280 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5281 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005282 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005283 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005284 }
5285 return Result;
5286}
5287
5288template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005289QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5290 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005291 QualType Pattern
5292 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005293 if (Pattern.isNull())
5294 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
5296 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005297 if (getDerived().AlwaysRebuild() ||
5298 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005299 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005300 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005301 TL.getEllipsisLoc(),
5302 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005303 if (Result.isNull())
5304 return QualType();
5305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005306
Douglas Gregor822d0302011-01-12 17:07:58 +00005307 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5308 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5309 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005310}
5311
5312template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005313QualType
5314TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005315 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005316 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005317 TLB.pushFullCopy(TL);
5318 return TL.getType();
5319}
5320
5321template<typename Derived>
5322QualType
5323TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005324 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005325 // ObjCObjectType is never dependent.
5326 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005327 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005328}
Mike Stump11289f42009-09-09 15:08:12 +00005329
5330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType
5332TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005333 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005334 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005335 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005336 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005337}
5338
Douglas Gregord6ff3322009-08-04 16:50:30 +00005339//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005340// Statement transformation
5341//===----------------------------------------------------------------------===//
5342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005343StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005344TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005345 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005346}
5347
5348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005350TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5351 return getDerived().TransformCompoundStmt(S, false);
5352}
5353
5354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005355StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005356TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005357 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005358 Sema::CompoundScopeRAII CompoundScope(getSema());
5359
John McCall1ababa62010-08-27 19:56:05 +00005360 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005361 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005362 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005363 for (auto *B : S->body()) {
5364 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005365 if (Result.isInvalid()) {
5366 // Immediately fail if this was a DeclStmt, since it's very
5367 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005368 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005369 return StmtError();
5370
5371 // Otherwise, just keep processing substatements and fail later.
5372 SubStmtInvalid = true;
5373 continue;
5374 }
Mike Stump11289f42009-09-09 15:08:12 +00005375
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005376 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005377 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 }
Mike Stump11289f42009-09-09 15:08:12 +00005379
John McCall1ababa62010-08-27 19:56:05 +00005380 if (SubStmtInvalid)
5381 return StmtError();
5382
Douglas Gregorebe10102009-08-20 07:17:43 +00005383 if (!getDerived().AlwaysRebuild() &&
5384 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005385 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005386
5387 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005388 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005389 S->getRBracLoc(),
5390 IsStmtExpr);
5391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregorebe10102009-08-20 07:17:43 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005396 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005397 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005398 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5399 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005400
Eli Friedman06577382009-11-19 03:14:00 +00005401 // Transform the left-hand case value.
5402 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005403 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005404 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005406
Eli Friedman06577382009-11-19 03:14:00 +00005407 // Transform the right-hand case value (for the GNU case-range extension).
5408 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005409 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005410 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005412 }
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregorebe10102009-08-20 07:17:43 +00005414 // Build the case statement.
5415 // Case statements are always rebuilt so that they will attached to their
5416 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005417 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005418 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005419 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005420 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 S->getColonLoc());
5422 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregorebe10102009-08-20 07:17:43 +00005425 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005426 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005427 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005428 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005429
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005431 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005432}
5433
5434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005435StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005436TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005437 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005438 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005439 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 // Default statements are always rebuilt
5443 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005444 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregorebe10102009-08-20 07:17:43 +00005447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005449TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005450 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005451 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005452 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005453
Chris Lattnercab02a62011-02-17 20:34:02 +00005454 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5455 S->getDecl());
5456 if (!LD)
5457 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005458
5459
Douglas Gregorebe10102009-08-20 07:17:43 +00005460 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005461 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005462 cast<LabelDecl>(LD), SourceLocation(),
5463 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005464}
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorebe10102009-08-20 07:17:43 +00005466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005467StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005468TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5469 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5470 if (SubStmt.isInvalid())
5471 return StmtError();
5472
5473 // TODO: transform attributes
5474 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5475 return S;
5476
5477 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5478 S->getAttrs(),
5479 SubStmt.get());
5480}
5481
5482template<typename Derived>
5483StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005484TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005486 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005487 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005488 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005489 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005490 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005491 getDerived().TransformDefinition(
5492 S->getConditionVariable()->getLocation(),
5493 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005494 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005496 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005497 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005498
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005499 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005500 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005501
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005502 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005503 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005504 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005505 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005506 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005507 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
John McCallb268a282010-08-23 23:25:46 +00005509 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005510 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005512
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005513 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005514 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregorebe10102009-08-20 07:17:43 +00005522 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005523 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005528 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005529 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 Then.get() == S->getThen() &&
5531 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005532 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005534 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005535 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005536 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005537}
5538
5539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005540StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005541TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005543 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005544 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005545 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005546 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005547 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005548 getDerived().TransformDefinition(
5549 S->getConditionVariable()->getLocation(),
5550 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005551 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005553 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005554 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005555
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005556 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregorebe10102009-08-20 07:17:43 +00005560 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005561 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005562 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005563 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005565 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005566
Douglas Gregorebe10102009-08-20 07:17:43 +00005567 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005568 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregorebe10102009-08-20 07:17:43 +00005572 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005573 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5574 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005575}
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregorebe10102009-08-20 07:17:43 +00005577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005578StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005579TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005580 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005581 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005582 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005583 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005584 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005585 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005586 getDerived().TransformDefinition(
5587 S->getConditionVariable()->getLocation(),
5588 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005589 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005591 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005592 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005593
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005594 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005596
5597 if (S->getCond()) {
5598 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005599 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5600 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005601 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005602 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005604 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005605 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005606 }
Mike Stump11289f42009-09-09 15:08:12 +00005607
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005608 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005609 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005611
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005618 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005619 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005621 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005623 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005624 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005625}
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregorebe10102009-08-20 07:17:43 +00005627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005628StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005629TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005630 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005631 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005635 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005636 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005637 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005638 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 if (!getDerived().AlwaysRebuild() &&
5641 Cond.get() == S->getCond() &&
5642 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005643 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005644
John McCallb268a282010-08-23 23:25:46 +00005645 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5646 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 S->getRParenLoc());
5648}
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorebe10102009-08-20 07:17:43 +00005650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005651StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005652TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005654 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005659 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005660 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005661 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005662 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005663 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005664 getDerived().TransformDefinition(
5665 S->getConditionVariable()->getLocation(),
5666 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005667 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005668 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005669 } else {
5670 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005671
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005672 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005673 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005674
5675 if (S->getCond()) {
5676 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005677 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5678 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005679 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005680 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005682
John McCallb268a282010-08-23 23:25:46 +00005683 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005684 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005685 }
Mike Stump11289f42009-09-09 15:08:12 +00005686
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005687 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005688 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005689 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005692 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005693 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005694 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005695
Richard Smith945f8d32013-01-14 22:39:08 +00005696 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005697 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005698 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005699
Douglas Gregorebe10102009-08-20 07:17:43 +00005700 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005701 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005702 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005703 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 if (!getDerived().AlwaysRebuild() &&
5706 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005707 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005708 Inc.get() == S->getInc() &&
5709 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005710 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregorebe10102009-08-20 07:17:43 +00005712 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005713 Init.get(), FullCond, ConditionVar,
5714 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005715}
5716
5717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005718StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005719TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005720 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5721 S->getLabel());
5722 if (!LD)
5723 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005724
Douglas Gregorebe10102009-08-20 07:17:43 +00005725 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005726 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005727 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005728}
5729
5730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005732TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005733 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005734 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005736 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregorebe10102009-08-20 07:17:43 +00005738 if (!getDerived().AlwaysRebuild() &&
5739 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005740 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005741
5742 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005743 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005744}
5745
5746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005747StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005748TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005749 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005750}
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregorebe10102009-08-20 07:17:43 +00005752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005753StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005754TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005755 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005756}
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregorebe10102009-08-20 07:17:43 +00005758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005759StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005760TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005761 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005762 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005763 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005764
Mike Stump11289f42009-09-09 15:08:12 +00005765 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005767 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005768}
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregorebe10102009-08-20 07:17:43 +00005770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005771StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005772TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005773 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005774 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005775 for (auto *D : S->decls()) {
5776 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005777 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005780 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005781 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregorebe10102009-08-20 07:17:43 +00005783 Decls.push_back(Transformed);
5784 }
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregorebe10102009-08-20 07:17:43 +00005786 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005787 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005788
Rafael Espindolaab417692013-07-09 12:05:01 +00005789 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005790}
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorebe10102009-08-20 07:17:43 +00005792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005793StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005794TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Benjamin Kramerf0623432012-08-23 22:51:59 +00005796 SmallVector<Expr*, 8> Constraints;
5797 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005798 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005799
John McCalldadc5752010-08-24 06:29:42 +00005800 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005801 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005802
5803 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005804
Anders Carlssonaaeef072010-01-24 05:50:09 +00005805 // Go through the outputs.
5806 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005807 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005808
Anders Carlssonaaeef072010-01-24 05:50:09 +00005809 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005810 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Anders Carlssonaaeef072010-01-24 05:50:09 +00005812 // Transform the output expr.
5813 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005814 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005815 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005816 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005817
Anders Carlssonaaeef072010-01-24 05:50:09 +00005818 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
John McCallb268a282010-08-23 23:25:46 +00005820 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Anders Carlssonaaeef072010-01-24 05:50:09 +00005823 // Go through the inputs.
5824 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005825 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
Anders Carlssonaaeef072010-01-24 05:50:09 +00005827 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005828 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005829
Anders Carlssonaaeef072010-01-24 05:50:09 +00005830 // Transform the input expr.
5831 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005832 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005833 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005834 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005835
Anders Carlssonaaeef072010-01-24 05:50:09 +00005836 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
John McCallb268a282010-08-23 23:25:46 +00005838 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005840
Anders Carlssonaaeef072010-01-24 05:50:09 +00005841 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005842 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005843
5844 // Go through the clobbers.
5845 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005846 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005847
5848 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005849 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005850 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5851 S->isVolatile(), S->getNumOutputs(),
5852 S->getNumInputs(), Names.data(),
5853 Constraints, Exprs, AsmString.get(),
5854 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005855}
5856
Chad Rosier32503022012-06-11 20:47:18 +00005857template<typename Derived>
5858StmtResult
5859TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005860 ArrayRef<Token> AsmToks =
5861 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005862
John McCallf413f5e2013-05-03 00:10:13 +00005863 bool HadError = false, HadChange = false;
5864
5865 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5866 SmallVector<Expr*, 8> TransformedExprs;
5867 TransformedExprs.reserve(SrcExprs.size());
5868 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5869 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5870 if (!Result.isUsable()) {
5871 HadError = true;
5872 } else {
5873 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005874 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005875 }
5876 }
5877
5878 if (HadError) return StmtError();
5879 if (!HadChange && !getDerived().AlwaysRebuild())
5880 return Owned(S);
5881
Chad Rosierb6f46c12012-08-15 16:53:30 +00005882 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005883 AsmToks, S->getAsmString(),
5884 S->getNumOutputs(), S->getNumInputs(),
5885 S->getAllConstraints(), S->getClobbers(),
5886 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005887}
Douglas Gregorebe10102009-08-20 07:17:43 +00005888
5889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005890StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005891TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005892 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005893 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005894 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005896
Douglas Gregor96c79492010-04-23 22:50:49 +00005897 // Transform the @catch statements (if present).
5898 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005899 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005900 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005901 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005902 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005904 if (Catch.get() != S->getCatchStmt(I))
5905 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005906 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
Douglas Gregor306de2f2010-04-22 23:59:56 +00005909 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005910 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005911 if (S->getFinallyStmt()) {
5912 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5913 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005914 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005915 }
5916
5917 // If nothing changed, just retain this statement.
5918 if (!getDerived().AlwaysRebuild() &&
5919 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005920 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005921 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005922 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005923
Douglas Gregor306de2f2010-04-22 23:59:56 +00005924 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005925 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005926 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005927}
Mike Stump11289f42009-09-09 15:08:12 +00005928
Douglas Gregorebe10102009-08-20 07:17:43 +00005929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005930StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005931TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005932 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005933 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005934 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005935 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005936 if (FromVar->getTypeSourceInfo()) {
5937 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5938 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005941
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005942 QualType T;
5943 if (TSInfo)
5944 T = TSInfo->getType();
5945 else {
5946 T = getDerived().TransformType(FromVar->getType());
5947 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005948 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005950
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005951 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5952 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005953 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
John McCalldadc5752010-08-24 06:29:42 +00005956 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005957 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
5960 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005961 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005962 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005963}
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregorebe10102009-08-20 07:17:43 +00005965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005966StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005967TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005968 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005969 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005970 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 // If nothing changed, just retain this statement.
5974 if (!getDerived().AlwaysRebuild() &&
5975 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005976 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005977
5978 // Build a new statement.
5979 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005980 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005981}
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregorebe10102009-08-20 07:17:43 +00005983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005984StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005985TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005986 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005987 if (S->getThrowExpr()) {
5988 Operand = getDerived().TransformExpr(S->getThrowExpr());
5989 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005990 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005992
Douglas Gregor2900c162010-04-22 21:44:01 +00005993 if (!getDerived().AlwaysRebuild() &&
5994 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005995 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005996
John McCallb268a282010-08-23 23:25:46 +00005997 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005998}
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregorebe10102009-08-20 07:17:43 +00006000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006002TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006003 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006004 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006005 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006006 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006008 Object =
6009 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6010 Object.get());
6011 if (Object.isInvalid())
6012 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregor6148de72010-04-22 22:01:21 +00006014 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006015 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006016 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006018
Douglas Gregor6148de72010-04-22 22:01:21 +00006019 // If nothing change, just retain the current statement.
6020 if (!getDerived().AlwaysRebuild() &&
6021 Object.get() == S->getSynchExpr() &&
6022 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006023 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006024
6025 // Build a new statement.
6026 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006027 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006028}
6029
6030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031StmtResult
John McCall31168b02011-06-15 23:02:42 +00006032TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6033 ObjCAutoreleasePoolStmt *S) {
6034 // Transform the body.
6035 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6036 if (Body.isInvalid())
6037 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006038
John McCall31168b02011-06-15 23:02:42 +00006039 // If nothing changed, just retain this statement.
6040 if (!getDerived().AlwaysRebuild() &&
6041 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006042 return S;
John McCall31168b02011-06-15 23:02:42 +00006043
6044 // Build a new statement.
6045 return getDerived().RebuildObjCAutoreleasePoolStmt(
6046 S->getAtLoc(), Body.get());
6047}
6048
6049template<typename Derived>
6050StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006051TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006052 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006053 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006054 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006055 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006057
Douglas Gregorf68a5082010-04-22 23:10:45 +00006058 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006059 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006060 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006062
Douglas Gregorf68a5082010-04-22 23:10:45 +00006063 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006064 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006065 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006067
Douglas Gregorf68a5082010-04-22 23:10:45 +00006068 // If nothing changed, just retain this statement.
6069 if (!getDerived().AlwaysRebuild() &&
6070 Element.get() == S->getElement() &&
6071 Collection.get() == S->getCollection() &&
6072 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006073 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006074
Douglas Gregorf68a5082010-04-22 23:10:45 +00006075 // Build a new statement.
6076 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006077 Element.get(),
6078 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006079 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006080 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006081}
6082
David Majnemer5f7efef2013-10-15 09:50:08 +00006083template <typename Derived>
6084StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006086 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006087 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6088 TypeSourceInfo *T =
6089 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006090 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006092
David Majnemer5f7efef2013-10-15 09:50:08 +00006093 Var = getDerived().RebuildExceptionDecl(
6094 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6095 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006096 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 }
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006101 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006102 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006103 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006104
David Majnemer5f7efef2013-10-15 09:50:08 +00006105 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006106 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006107 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006108
David Majnemer5f7efef2013-10-15 09:50:08 +00006109 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
David Majnemer5f7efef2013-10-15 09:50:08 +00006112template <typename Derived>
6113StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006114 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006115 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006116 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006118
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 // Transform the handlers.
6120 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006121 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006122 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006123 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006124 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006126
Douglas Gregorebe10102009-08-20 07:17:43 +00006127 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006128 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006129 }
Mike Stump11289f42009-09-09 15:08:12 +00006130
David Majnemer5f7efef2013-10-15 09:50:08 +00006131 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006132 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006133 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006134
John McCallb268a282010-08-23 23:25:46 +00006135 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006136 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006137}
Mike Stump11289f42009-09-09 15:08:12 +00006138
Richard Smith02e85f32011-04-14 22:09:26 +00006139template<typename Derived>
6140StmtResult
6141TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6142 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6143 if (Range.isInvalid())
6144 return StmtError();
6145
6146 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6147 if (BeginEnd.isInvalid())
6148 return StmtError();
6149
6150 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6151 if (Cond.isInvalid())
6152 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006153 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006154 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006155 if (Cond.isInvalid())
6156 return StmtError();
6157 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006158 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006159
6160 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6161 if (Inc.isInvalid())
6162 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006163 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006164 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006165
6166 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6167 if (LoopVar.isInvalid())
6168 return StmtError();
6169
6170 StmtResult NewStmt = S;
6171 if (getDerived().AlwaysRebuild() ||
6172 Range.get() != S->getRangeStmt() ||
6173 BeginEnd.get() != S->getBeginEndStmt() ||
6174 Cond.get() != S->getCond() ||
6175 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006176 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006177 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6178 S->getColonLoc(), Range.get(),
6179 BeginEnd.get(), Cond.get(),
6180 Inc.get(), LoopVar.get(),
6181 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006182 if (NewStmt.isInvalid())
6183 return StmtError();
6184 }
Richard Smith02e85f32011-04-14 22:09:26 +00006185
6186 StmtResult Body = getDerived().TransformStmt(S->getBody());
6187 if (Body.isInvalid())
6188 return StmtError();
6189
6190 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6191 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006192 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006193 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6194 S->getColonLoc(), Range.get(),
6195 BeginEnd.get(), Cond.get(),
6196 Inc.get(), LoopVar.get(),
6197 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006198 if (NewStmt.isInvalid())
6199 return StmtError();
6200 }
Richard Smith02e85f32011-04-14 22:09:26 +00006201
6202 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006203 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006204
6205 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6206}
6207
John Wiegley1c0675e2011-04-28 01:08:34 +00006208template<typename Derived>
6209StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006210TreeTransform<Derived>::TransformMSDependentExistsStmt(
6211 MSDependentExistsStmt *S) {
6212 // Transform the nested-name-specifier, if any.
6213 NestedNameSpecifierLoc QualifierLoc;
6214 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006215 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006216 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6217 if (!QualifierLoc)
6218 return StmtError();
6219 }
6220
6221 // Transform the declaration name.
6222 DeclarationNameInfo NameInfo = S->getNameInfo();
6223 if (NameInfo.getName()) {
6224 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6225 if (!NameInfo.getName())
6226 return StmtError();
6227 }
6228
6229 // Check whether anything changed.
6230 if (!getDerived().AlwaysRebuild() &&
6231 QualifierLoc == S->getQualifierLoc() &&
6232 NameInfo.getName() == S->getNameInfo().getName())
6233 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006234
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006235 // Determine whether this name exists, if we can.
6236 CXXScopeSpec SS;
6237 SS.Adopt(QualifierLoc);
6238 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006239 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006240 case Sema::IER_Exists:
6241 if (S->isIfExists())
6242 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006243
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006244 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6245
6246 case Sema::IER_DoesNotExist:
6247 if (S->isIfNotExists())
6248 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006249
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006250 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006251
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006252 case Sema::IER_Dependent:
6253 Dependent = true;
6254 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006255
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006256 case Sema::IER_Error:
6257 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006260 // We need to continue with the instantiation, so do so now.
6261 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6262 if (SubStmt.isInvalid())
6263 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006265 // If we have resolved the name, just transform to the substatement.
6266 if (!Dependent)
6267 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006268
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006269 // The name is still dependent, so build a dependent expression again.
6270 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6271 S->isIfExists(),
6272 QualifierLoc,
6273 NameInfo,
6274 SubStmt.get());
6275}
6276
6277template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006278ExprResult
6279TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6280 NestedNameSpecifierLoc QualifierLoc;
6281 if (E->getQualifierLoc()) {
6282 QualifierLoc
6283 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6284 if (!QualifierLoc)
6285 return ExprError();
6286 }
6287
6288 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6289 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6290 if (!PD)
6291 return ExprError();
6292
6293 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6294 if (Base.isInvalid())
6295 return ExprError();
6296
6297 return new (SemaRef.getASTContext())
6298 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6299 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6300 QualifierLoc, E->getMemberLoc());
6301}
6302
David Majnemerfad8f482013-10-15 09:33:02 +00006303template <typename Derived>
6304StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006305 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006306 if (TryBlock.isInvalid())
6307 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006308
6309 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006310 if (Handler.isInvalid())
6311 return StmtError();
6312
David Majnemerfad8f482013-10-15 09:33:02 +00006313 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6314 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006315 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006316
David Majnemerfad8f482013-10-15 09:33:02 +00006317 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006318 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006319}
6320
David Majnemerfad8f482013-10-15 09:33:02 +00006321template <typename Derived>
6322StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006323 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006324 if (Block.isInvalid())
6325 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006326
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006327 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006328}
6329
David Majnemerfad8f482013-10-15 09:33:02 +00006330template <typename Derived>
6331StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006332 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006333 if (FilterExpr.isInvalid())
6334 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006335
David Majnemer7e755502013-10-15 09:30:14 +00006336 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006337 if (Block.isInvalid())
6338 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006339
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006340 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6341 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006342}
6343
David Majnemerfad8f482013-10-15 09:33:02 +00006344template <typename Derived>
6345StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6346 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006347 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6348 else
6349 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6350}
6351
Alexander Musman64d33f12014-06-04 07:53:32 +00006352//===----------------------------------------------------------------------===//
6353// OpenMP directive transformation
6354//===----------------------------------------------------------------------===//
6355template <typename Derived>
6356StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6357 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006358
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006359 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006360 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006361 ArrayRef<OMPClause *> Clauses = D->clauses();
6362 TClauses.reserve(Clauses.size());
6363 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6364 I != E; ++I) {
6365 if (*I) {
6366 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006367 if (Clause)
6368 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006369 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006370 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006371 }
6372 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006373 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006374 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006375 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006376 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006377 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataevc5e02582014-06-16 07:08:35 +00006378 if (AssociatedStmt.isInvalid() || TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006379 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006380 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006381
Alexander Musman64d33f12014-06-04 07:53:32 +00006382 return getDerived().RebuildOMPExecutableDirective(
6383 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6384 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006385}
6386
Alexander Musman64d33f12014-06-04 07:53:32 +00006387template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006388StmtResult
6389TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6390 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006391 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006392 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6393 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6394 return Res;
6395}
6396
Alexander Musman64d33f12014-06-04 07:53:32 +00006397template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006398StmtResult
6399TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6400 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006401 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006402 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6403 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006404 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006405}
6406
Alexey Bataevf29276e2014-06-18 04:14:57 +00006407template <typename Derived>
6408StmtResult
6409TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6410 DeclarationNameInfo DirName;
6411 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr);
6412 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6413 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6414 return Res;
6415}
6416
Alexander Musman64d33f12014-06-04 07:53:32 +00006417//===----------------------------------------------------------------------===//
6418// OpenMP clause transformation
6419//===----------------------------------------------------------------------===//
6420template <typename Derived>
6421OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006422 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6423 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006424 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006425 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006426 C->getLParenLoc(), C->getLocEnd());
6427}
6428
Alexander Musman64d33f12014-06-04 07:53:32 +00006429template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006430OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006431TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6432 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6433 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006434 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006435 return getDerived().RebuildOMPNumThreadsClause(
6436 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006437}
6438
Alexey Bataev62c87d22014-03-21 04:51:18 +00006439template <typename Derived>
6440OMPClause *
6441TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6442 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6443 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006444 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006445 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006446 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006447}
6448
Alexander Musman8bd31e62014-05-27 15:12:19 +00006449template <typename Derived>
6450OMPClause *
6451TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6452 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6453 if (E.isInvalid())
6454 return 0;
6455 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006456 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006457}
6458
Alexander Musman64d33f12014-06-04 07:53:32 +00006459template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006460OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006461TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006462 return getDerived().RebuildOMPDefaultClause(
6463 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6464 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006465}
6466
Alexander Musman64d33f12014-06-04 07:53:32 +00006467template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006468OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006469TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006470 return getDerived().RebuildOMPProcBindClause(
6471 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6472 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006473}
6474
Alexander Musman64d33f12014-06-04 07:53:32 +00006475template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006476OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006477TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006478 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006479 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006480 for (auto *VE : C->varlists()) {
6481 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006482 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006483 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006484 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006485 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006486 return getDerived().RebuildOMPPrivateClause(
6487 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006488}
6489
Alexander Musman64d33f12014-06-04 07:53:32 +00006490template <typename Derived>
6491OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6492 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006493 llvm::SmallVector<Expr *, 16> Vars;
6494 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006495 for (auto *VE : C->varlists()) {
6496 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006497 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006498 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006499 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006500 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006501 return getDerived().RebuildOMPFirstprivateClause(
6502 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006503}
6504
Alexander Musman64d33f12014-06-04 07:53:32 +00006505template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006506OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006507TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6508 llvm::SmallVector<Expr *, 16> Vars;
6509 Vars.reserve(C->varlist_size());
6510 for (auto *VE : C->varlists()) {
6511 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6512 if (EVar.isInvalid())
6513 return nullptr;
6514 Vars.push_back(EVar.get());
6515 }
6516 return getDerived().RebuildOMPLastprivateClause(
6517 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6518}
6519
6520template <typename Derived>
6521OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006522TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6523 llvm::SmallVector<Expr *, 16> Vars;
6524 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006525 for (auto *VE : C->varlists()) {
6526 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006527 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006528 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006529 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006530 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006531 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6532 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006533}
6534
Alexander Musman64d33f12014-06-04 07:53:32 +00006535template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006536OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006537TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6538 llvm::SmallVector<Expr *, 16> Vars;
6539 Vars.reserve(C->varlist_size());
6540 for (auto *VE : C->varlists()) {
6541 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6542 if (EVar.isInvalid())
6543 return nullptr;
6544 Vars.push_back(EVar.get());
6545 }
6546 CXXScopeSpec ReductionIdScopeSpec;
6547 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6548
6549 DeclarationNameInfo NameInfo = C->getNameInfo();
6550 if (NameInfo.getName()) {
6551 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6552 if (!NameInfo.getName())
6553 return nullptr;
6554 }
6555 return getDerived().RebuildOMPReductionClause(
6556 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6557 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6558}
6559
6560template <typename Derived>
6561OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006562TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6563 llvm::SmallVector<Expr *, 16> Vars;
6564 Vars.reserve(C->varlist_size());
6565 for (auto *VE : C->varlists()) {
6566 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6567 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006568 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006569 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006570 }
6571 ExprResult Step = getDerived().TransformExpr(C->getStep());
6572 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006573 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006574 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6575 C->getLParenLoc(),
6576 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006577}
6578
Alexander Musman64d33f12014-06-04 07:53:32 +00006579template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006580OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006581TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6582 llvm::SmallVector<Expr *, 16> Vars;
6583 Vars.reserve(C->varlist_size());
6584 for (auto *VE : C->varlists()) {
6585 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6586 if (EVar.isInvalid())
6587 return nullptr;
6588 Vars.push_back(EVar.get());
6589 }
6590 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6591 if (Alignment.isInvalid())
6592 return nullptr;
6593 return getDerived().RebuildOMPAlignedClause(
6594 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6595 C->getColonLoc(), C->getLocEnd());
6596}
6597
Alexander Musman64d33f12014-06-04 07:53:32 +00006598template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006599OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006600TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6601 llvm::SmallVector<Expr *, 16> Vars;
6602 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006603 for (auto *VE : C->varlists()) {
6604 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006605 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006606 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006607 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006608 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006609 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6610 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006611}
6612
Douglas Gregorebe10102009-08-20 07:17:43 +00006613//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006614// Expression transformation
6615//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006619 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006620}
Mike Stump11289f42009-09-09 15:08:12 +00006621
6622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006625 NestedNameSpecifierLoc QualifierLoc;
6626 if (E->getQualifierLoc()) {
6627 QualifierLoc
6628 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6629 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006630 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006631 }
John McCallce546572009-12-08 09:08:17 +00006632
6633 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006634 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6635 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006636 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
John McCall815039a2010-08-17 21:27:17 +00006639 DeclarationNameInfo NameInfo = E->getNameInfo();
6640 if (NameInfo.getName()) {
6641 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6642 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006644 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006645
6646 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006647 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006648 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006649 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006650 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006651
6652 // Mark it referenced in the new context regardless.
6653 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006654 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006655
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006656 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006657 }
John McCallce546572009-12-08 09:08:17 +00006658
Craig Topperc3ec1492014-05-26 06:22:03 +00006659 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006660 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006661 TemplateArgs = &TransArgs;
6662 TransArgs.setLAngleLoc(E->getLAngleLoc());
6663 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006664 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6665 E->getNumTemplateArgs(),
6666 TransArgs))
6667 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006668 }
6669
Chad Rosier1dcde962012-08-08 18:46:20 +00006670 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006671 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006672}
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregora16548e2009-08-11 05:31:07 +00006674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006677 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006678}
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006683 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006684}
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregora16548e2009-08-11 05:31:07 +00006686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006688TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006689 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006690}
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006695 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006696}
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregora16548e2009-08-11 05:31:07 +00006698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006701 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006702}
6703
6704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006706TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006707 if (FunctionDecl *FD = E->getDirectCallee())
6708 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006709 return SemaRef.MaybeBindToTemporary(E);
6710}
6711
6712template<typename Derived>
6713ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006714TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6715 ExprResult ControllingExpr =
6716 getDerived().TransformExpr(E->getControllingExpr());
6717 if (ControllingExpr.isInvalid())
6718 return ExprError();
6719
Chris Lattner01cf8db2011-07-20 06:58:45 +00006720 SmallVector<Expr *, 4> AssocExprs;
6721 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006722 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6723 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6724 if (TS) {
6725 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6726 if (!AssocType)
6727 return ExprError();
6728 AssocTypes.push_back(AssocType);
6729 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006730 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006731 }
6732
6733 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6734 if (AssocExpr.isInvalid())
6735 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006736 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006737 }
6738
6739 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6740 E->getDefaultLoc(),
6741 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006742 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006743 AssocTypes,
6744 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006745}
6746
6747template<typename Derived>
6748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006749TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006750 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006753
Douglas Gregora16548e2009-08-11 05:31:07 +00006754 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006755 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006756
John McCallb268a282010-08-23 23:25:46 +00006757 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006758 E->getRParen());
6759}
6760
Richard Smithdb2630f2012-10-21 03:28:35 +00006761/// \brief The operand of a unary address-of operator has special rules: it's
6762/// allowed to refer to a non-static member of a class even if there's no 'this'
6763/// object available.
6764template<typename Derived>
6765ExprResult
6766TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6767 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006768 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006769 else
6770 return getDerived().TransformExpr(E);
6771}
6772
Mike Stump11289f42009-09-09 15:08:12 +00006773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006775TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006776 ExprResult SubExpr;
6777 if (E->getOpcode() == UO_AddrOf)
6778 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6779 else
6780 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006783
Douglas Gregora16548e2009-08-11 05:31:07 +00006784 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006785 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006786
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6788 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006789 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006790}
Mike Stump11289f42009-09-09 15:08:12 +00006791
Douglas Gregora16548e2009-08-11 05:31:07 +00006792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006793ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006794TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6795 // Transform the type.
6796 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6797 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006798 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006799
Douglas Gregor882211c2010-04-28 22:16:22 +00006800 // Transform all of the components into components similar to what the
6801 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006802 // FIXME: It would be slightly more efficient in the non-dependent case to
6803 // just map FieldDecls, rather than requiring the rebuilder to look for
6804 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006805 // template code that we don't care.
6806 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006807 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006808 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006809 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006810 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6811 const Node &ON = E->getComponent(I);
6812 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006813 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006814 Comp.LocStart = ON.getSourceRange().getBegin();
6815 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006816 switch (ON.getKind()) {
6817 case Node::Array: {
6818 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006819 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006820 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006821 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006822
Douglas Gregor882211c2010-04-28 22:16:22 +00006823 ExprChanged = ExprChanged || Index.get() != FromIndex;
6824 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006825 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006826 break;
6827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006828
Douglas Gregor882211c2010-04-28 22:16:22 +00006829 case Node::Field:
6830 case Node::Identifier:
6831 Comp.isBrackets = false;
6832 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006833 if (!Comp.U.IdentInfo)
6834 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006835
Douglas Gregor882211c2010-04-28 22:16:22 +00006836 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006837
Douglas Gregord1702062010-04-29 00:18:15 +00006838 case Node::Base:
6839 // Will be recomputed during the rebuild.
6840 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006842
Douglas Gregor882211c2010-04-28 22:16:22 +00006843 Components.push_back(Comp);
6844 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006845
Douglas Gregor882211c2010-04-28 22:16:22 +00006846 // If nothing changed, retain the existing expression.
6847 if (!getDerived().AlwaysRebuild() &&
6848 Type == E->getTypeSourceInfo() &&
6849 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006850 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006851
Douglas Gregor882211c2010-04-28 22:16:22 +00006852 // Build a new offsetof expression.
6853 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6854 Components.data(), Components.size(),
6855 E->getRParenLoc());
6856}
6857
6858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006859ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006860TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6861 assert(getDerived().AlreadyTransformed(E->getType()) &&
6862 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006863 return E;
John McCall8d69a212010-11-15 23:31:06 +00006864}
6865
6866template<typename Derived>
6867ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006868TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006869 // Rebuild the syntactic form. The original syntactic form has
6870 // opaque-value expressions in it, so strip those away and rebuild
6871 // the result. This is a really awful way of doing this, but the
6872 // better solution (rebuilding the semantic expressions and
6873 // rebinding OVEs as necessary) doesn't work; we'd need
6874 // TreeTransform to not strip away implicit conversions.
6875 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6876 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006877 if (result.isInvalid()) return ExprError();
6878
6879 // If that gives us a pseudo-object result back, the pseudo-object
6880 // expression must have been an lvalue-to-rvalue conversion which we
6881 // should reapply.
6882 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006883 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006884
6885 return result;
6886}
6887
6888template<typename Derived>
6889ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006890TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6891 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006893 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006894
John McCallbcd03502009-12-07 02:54:59 +00006895 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006896 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006897 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006898
John McCall4c98fd82009-11-04 07:28:41 +00006899 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006900 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006901
Peter Collingbournee190dee2011-03-11 19:24:49 +00006902 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6903 E->getKind(),
6904 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 }
Mike Stump11289f42009-09-09 15:08:12 +00006906
Eli Friedmane4f22df2012-02-29 04:03:55 +00006907 // C++0x [expr.sizeof]p1:
6908 // The operand is either an expression, which is an unevaluated operand
6909 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006910 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6911 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006912
Reid Kleckner32506ed2014-06-12 23:03:48 +00006913 // Try to recover if we have something like sizeof(T::X) where X is a type.
6914 // Notably, there must be *exactly* one set of parens if X is a type.
6915 TypeSourceInfo *RecoveryTSI = nullptr;
6916 ExprResult SubExpr;
6917 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
6918 if (auto *DRE =
6919 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
6920 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
6921 PE, DRE, false, &RecoveryTSI);
6922 else
6923 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6924
6925 if (RecoveryTSI) {
6926 return getDerived().RebuildUnaryExprOrTypeTrait(
6927 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
6928 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00006929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006930
Eli Friedmane4f22df2012-02-29 04:03:55 +00006931 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006932 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006933
Peter Collingbournee190dee2011-03-11 19:24:49 +00006934 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6935 E->getOperatorLoc(),
6936 E->getKind(),
6937 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006938}
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006943 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006944 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006945 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006946
John McCalldadc5752010-08-24 06:29:42 +00006947 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006948 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006950
6951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
6953 LHS.get() == E->getLHS() &&
6954 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006955 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006956
John McCallb268a282010-08-23 23:25:46 +00006957 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006959 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006960 E->getRBracketLoc());
6961}
Mike Stump11289f42009-09-09 15:08:12 +00006962
6963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006966 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006967 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006968 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006970
6971 // Transform arguments.
6972 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006973 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006974 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006975 &ArgChanged))
6976 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006977
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 if (!getDerived().AlwaysRebuild() &&
6979 Callee.get() == E->getCallee() &&
6980 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006981 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006982
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006984 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006986 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006987 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 E->getRParenLoc());
6989}
Mike Stump11289f42009-09-09 15:08:12 +00006990
6991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006994 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006995 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006997
Douglas Gregorea972d32011-02-28 21:54:11 +00006998 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006999 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007000 QualifierLoc
7001 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007002
Douglas Gregorea972d32011-02-28 21:54:11 +00007003 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007004 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007005 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007006 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007007
Eli Friedman2cfcef62009-12-04 06:40:45 +00007008 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007009 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7010 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007013
John McCall16df1e52010-03-30 21:47:33 +00007014 NamedDecl *FoundDecl = E->getFoundDecl();
7015 if (FoundDecl == E->getMemberDecl()) {
7016 FoundDecl = Member;
7017 } else {
7018 FoundDecl = cast_or_null<NamedDecl>(
7019 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7020 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007021 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007022 }
7023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 if (!getDerived().AlwaysRebuild() &&
7025 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007026 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007027 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007028 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007029 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007030
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007031 // Mark it referenced in the new context regardless.
7032 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007033 SemaRef.MarkMemberReferenced(E);
7034
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007035 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007036 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007037
John McCall6b51f282009-11-23 01:53:49 +00007038 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007039 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007040 TransArgs.setLAngleLoc(E->getLAngleLoc());
7041 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007042 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7043 E->getNumTemplateArgs(),
7044 TransArgs))
7045 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007046 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007047
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007049 SourceLocation FakeOperatorLoc =
7050 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007051
John McCall38836f02010-01-15 08:34:02 +00007052 // FIXME: to do this check properly, we will need to preserve the
7053 // first-qualifier-in-scope here, just in case we had a dependent
7054 // base (and therefore couldn't do the check) and a
7055 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007056 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007057
John McCallb268a282010-08-23 23:25:46 +00007058 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007060 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007061 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007062 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007063 Member,
John McCall16df1e52010-03-30 21:47:33 +00007064 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007065 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007066 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007067 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007068}
Mike Stump11289f42009-09-09 15:08:12 +00007069
Douglas Gregora16548e2009-08-11 05:31:07 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007076
John McCalldadc5752010-08-24 06:29:42 +00007077 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007080
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 if (!getDerived().AlwaysRebuild() &&
7082 LHS.get() == E->getLHS() &&
7083 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007084 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007085
Lang Hames5de91cc2012-10-02 04:45:10 +00007086 Sema::FPContractStateRAII FPContractState(getSema());
7087 getSema().FPFeatures.fp_contract = E->isFPContractable();
7088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007090 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007091}
7092
Mike Stump11289f42009-09-09 15:08:12 +00007093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007094ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007095TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007096 CompoundAssignOperator *E) {
7097 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007098}
Mike Stump11289f42009-09-09 15:08:12 +00007099
Douglas Gregora16548e2009-08-11 05:31:07 +00007100template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007101ExprResult TreeTransform<Derived>::
7102TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7103 // Just rebuild the common and RHS expressions and see whether we
7104 // get any changes.
7105
7106 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7107 if (commonExpr.isInvalid())
7108 return ExprError();
7109
7110 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7111 if (rhs.isInvalid())
7112 return ExprError();
7113
7114 if (!getDerived().AlwaysRebuild() &&
7115 commonExpr.get() == e->getCommon() &&
7116 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007117 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007118
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007119 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007120 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007121 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007122 e->getColonLoc(),
7123 rhs.get());
7124}
7125
7126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007128TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007129 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007132
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 Cond.get() == E->getCond() &&
7143 LHS.get() == E->getLHS() &&
7144 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007145 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007146
John McCallb268a282010-08-23 23:25:46 +00007147 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007148 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007149 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007150 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007151 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007152}
Mike Stump11289f42009-09-09 15:08:12 +00007153
7154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007155ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007156TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007157 // Implicit casts are eliminated during transformation, since they
7158 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007159 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007160}
Mike Stump11289f42009-09-09 15:08:12 +00007161
Douglas Gregora16548e2009-08-11 05:31:07 +00007162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007165 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7166 if (!Type)
7167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007168
John McCalldadc5752010-08-24 06:29:42 +00007169 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007170 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007175 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007176 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007177 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007178
John McCall97513962010-01-15 18:39:57 +00007179 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007180 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007182 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007183}
Mike Stump11289f42009-09-09 15:08:12 +00007184
Douglas Gregora16548e2009-08-11 05:31:07 +00007185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007187TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007188 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7189 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7190 if (!NewT)
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 Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007196
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007198 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007199 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007200 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007201
John McCall5d7aa7f2010-01-19 22:33:45 +00007202 // Note: the expression type doesn't necessarily match the
7203 // type-as-written, but that's okay, because it should always be
7204 // derivable from the initializer.
7205
John McCalle15bbff2010-01-18 19:35:47 +00007206 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007208 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007209}
Mike Stump11289f42009-09-09 15:08:12 +00007210
Douglas Gregora16548e2009-08-11 05:31:07 +00007211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007213TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007214 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007217
Douglas Gregora16548e2009-08-11 05:31:07 +00007218 if (!getDerived().AlwaysRebuild() &&
7219 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007220 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007221
Douglas Gregora16548e2009-08-11 05:31:07 +00007222 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007223 SourceLocation FakeOperatorLoc =
7224 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007225 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 E->getAccessorLoc(),
7227 E->getAccessor());
7228}
Mike Stump11289f42009-09-09 15:08:12 +00007229
Douglas Gregora16548e2009-08-11 05:31:07 +00007230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007232TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007233 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007234
Benjamin Kramerf0623432012-08-23 22:51:59 +00007235 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007236 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007237 Inits, &InitChanged))
7238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007239
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007241 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007242
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007243 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007244 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007245}
Mike Stump11289f42009-09-09 15:08:12 +00007246
Douglas Gregora16548e2009-08-11 05:31:07 +00007247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007249TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007250 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007251
Douglas Gregorebe10102009-08-20 07:17:43 +00007252 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007253 ExprResult Init = getDerived().TransformExpr(E->getInit());
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 Gregorebe10102009-08-20 07:17:43 +00007257 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007258 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007259 bool ExprChanged = false;
7260 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7261 DEnd = E->designators_end();
7262 D != DEnd; ++D) {
7263 if (D->isFieldDesignator()) {
7264 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7265 D->getDotLoc(),
7266 D->getFieldLoc()));
7267 continue;
7268 }
Mike Stump11289f42009-09-09 15:08:12 +00007269
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007271 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007272 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007273 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007274
7275 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007277
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007279 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007280 continue;
7281 }
Mike Stump11289f42009-09-09 15:08:12 +00007282
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007284 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007285 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7286 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007288
John McCalldadc5752010-08-24 06:29:42 +00007289 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007292
7293 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 End.get(),
7295 D->getLBracketLoc(),
7296 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007297
Douglas Gregora16548e2009-08-11 05:31:07 +00007298 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7299 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007300
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007301 ArrayExprs.push_back(Start.get());
7302 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 }
Mike Stump11289f42009-09-09 15:08:12 +00007304
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 if (!getDerived().AlwaysRebuild() &&
7306 Init.get() == E->getInit() &&
7307 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007308 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007309
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007310 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007311 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007312 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007313}
Mike Stump11289f42009-09-09 15:08:12 +00007314
Douglas Gregora16548e2009-08-11 05:31:07 +00007315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007316ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007317TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007318 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007319 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007320
Douglas Gregor3da3c062009-10-28 00:29:27 +00007321 // FIXME: Will we ever have proper type location here? Will we actually
7322 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007323 QualType T = getDerived().TransformType(E->getType());
7324 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007326
Douglas Gregora16548e2009-08-11 05:31:07 +00007327 if (!getDerived().AlwaysRebuild() &&
7328 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007329 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007330
Douglas Gregora16548e2009-08-11 05:31:07 +00007331 return getDerived().RebuildImplicitValueInitExpr(T);
7332}
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007336TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007337 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7338 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007340
John McCalldadc5752010-08-24 06:29:42 +00007341 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007342 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007343 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007344
Douglas Gregora16548e2009-08-11 05:31:07 +00007345 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007346 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007347 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007348 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007349
John McCallb268a282010-08-23 23:25:46 +00007350 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007351 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007352}
7353
7354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007356TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007358 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007359 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7360 &ArgumentChanged))
7361 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007362
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007364 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 E->getRParenLoc());
7366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregora16548e2009-08-11 05:31:07 +00007368/// \brief Transform an address-of-label expression.
7369///
7370/// By default, the transformation of an address-of-label expression always
7371/// rebuilds the expression, so that the label identifier can be resolved to
7372/// the corresponding label statement by semantic analysis.
7373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007376 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7377 E->getLabel());
7378 if (!LD)
7379 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007380
Douglas Gregora16548e2009-08-11 05:31:07 +00007381 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007382 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007383}
Mike Stump11289f42009-09-09 15:08:12 +00007384
7385template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007387TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007388 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007389 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007391 if (SubStmt.isInvalid()) {
7392 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007393 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007394 }
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007397 SubStmt.get() == E->getSubStmt()) {
7398 // Calling this an 'error' is unintuitive, but it does the right thing.
7399 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007400 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007401 }
Mike Stump11289f42009-09-09 15:08:12 +00007402
7403 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007404 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007405 E->getRParenLoc());
7406}
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregora16548e2009-08-11 05:31:07 +00007408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007410TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007411 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007412 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007414
John McCalldadc5752010-08-24 06:29:42 +00007415 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007416 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007418
John McCalldadc5752010-08-24 06:29:42 +00007419 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007422
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 if (!getDerived().AlwaysRebuild() &&
7424 Cond.get() == E->getCond() &&
7425 LHS.get() == E->getLHS() &&
7426 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007427 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007430 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007431 E->getRParenLoc());
7432}
Mike Stump11289f42009-09-09 15:08:12 +00007433
Douglas Gregora16548e2009-08-11 05:31:07 +00007434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007436TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007437 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007438}
7439
7440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007442TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007443 switch (E->getOperator()) {
7444 case OO_New:
7445 case OO_Delete:
7446 case OO_Array_New:
7447 case OO_Array_Delete:
7448 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007449
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007450 case OO_Call: {
7451 // This is a call to an object's operator().
7452 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7453
7454 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007455 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007456 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007457 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007458
7459 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007460 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7461 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007462
7463 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007464 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007465 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007466 Args))
7467 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007468
John McCallb268a282010-08-23 23:25:46 +00007469 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007470 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007471 E->getLocEnd());
7472 }
7473
7474#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7475 case OO_##Name:
7476#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7477#include "clang/Basic/OperatorKinds.def"
7478 case OO_Subscript:
7479 // Handled below.
7480 break;
7481
7482 case OO_Conditional:
7483 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007484
7485 case OO_None:
7486 case NUM_OVERLOADED_OPERATORS:
7487 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007488 }
7489
John McCalldadc5752010-08-24 06:29:42 +00007490 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007493
Richard Smithdb2630f2012-10-21 03:28:35 +00007494 ExprResult First;
7495 if (E->getOperator() == OO_Amp)
7496 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7497 else
7498 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007499 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007500 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007501
John McCalldadc5752010-08-24 06:29:42 +00007502 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007503 if (E->getNumArgs() == 2) {
7504 Second = getDerived().TransformExpr(E->getArg(1));
7505 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007506 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 }
Mike Stump11289f42009-09-09 15:08:12 +00007508
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 if (!getDerived().AlwaysRebuild() &&
7510 Callee.get() == E->getCallee() &&
7511 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007512 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007513 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007514
Lang Hames5de91cc2012-10-02 04:45:10 +00007515 Sema::FPContractStateRAII FPContractState(getSema());
7516 getSema().FPFeatures.fp_contract = E->isFPContractable();
7517
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7519 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007520 Callee.get(),
7521 First.get(),
7522 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007523}
Mike Stump11289f42009-09-09 15:08:12 +00007524
Douglas Gregora16548e2009-08-11 05:31:07 +00007525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007527TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7528 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007529}
Mike Stump11289f42009-09-09 15:08:12 +00007530
Douglas Gregora16548e2009-08-11 05:31:07 +00007531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007532ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007533TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7534 // Transform the callee.
7535 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7536 if (Callee.isInvalid())
7537 return ExprError();
7538
7539 // Transform exec config.
7540 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7541 if (EC.isInvalid())
7542 return ExprError();
7543
7544 // Transform arguments.
7545 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007546 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007547 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007548 &ArgChanged))
7549 return ExprError();
7550
7551 if (!getDerived().AlwaysRebuild() &&
7552 Callee.get() == E->getCallee() &&
7553 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007554 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007555
7556 // FIXME: Wrong source location information for the '('.
7557 SourceLocation FakeLParenLoc
7558 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7559 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007560 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007561 E->getRParenLoc(), EC.get());
7562}
7563
7564template<typename Derived>
7565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007566TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007567 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7568 if (!Type)
7569 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007570
John McCalldadc5752010-08-24 06:29:42 +00007571 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007572 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007575
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007577 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007579 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007581 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007582 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007583 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007584 E->getAngleBrackets().getEnd(),
7585 // FIXME. this should be '(' location
7586 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007587 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007588 E->getRParenLoc());
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
John McCall47f29ea2009-12-08 09:21:05 +00007593TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7594 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007595}
Mike Stump11289f42009-09-09 15:08:12 +00007596
7597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007598ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007599TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7600 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007601}
7602
Douglas Gregora16548e2009-08-11 05:31:07 +00007603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007604ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007605TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007606 CXXReinterpretCastExpr *E) {
7607 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007608}
Mike Stump11289f42009-09-09 15:08:12 +00007609
Douglas Gregora16548e2009-08-11 05:31:07 +00007610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007612TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7613 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007614}
Mike Stump11289f42009-09-09 15:08:12 +00007615
Douglas Gregora16548e2009-08-11 05:31:07 +00007616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007617ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007618TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007619 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007620 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7621 if (!Type)
7622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007623
John McCalldadc5752010-08-24 06:29:42 +00007624 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007625 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007626 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007628
Douglas Gregora16548e2009-08-11 05:31:07 +00007629 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007630 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007632 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007633
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007634 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007635 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007636 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007637 E->getRParenLoc());
7638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregora16548e2009-08-11 05:31:07 +00007640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007642TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007643 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007644 TypeSourceInfo *TInfo
7645 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7646 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregora16548e2009-08-11 05:31:07 +00007649 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007650 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007651 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregor9da64192010-04-26 22:37:10 +00007653 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7654 E->getLocStart(),
7655 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 E->getLocEnd());
7657 }
Mike Stump11289f42009-09-09 15:08:12 +00007658
Eli Friedman456f0182012-01-20 01:26:23 +00007659 // We don't know whether the subexpression is potentially evaluated until
7660 // after we perform semantic analysis. We speculatively assume it is
7661 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007663 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7664 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007665
John McCalldadc5752010-08-24 06:29:42 +00007666 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregora16548e2009-08-11 05:31:07 +00007670 if (!getDerived().AlwaysRebuild() &&
7671 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007672 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregor9da64192010-04-26 22:37:10 +00007674 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7675 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007676 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007677 E->getLocEnd());
7678}
7679
7680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007681ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007682TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7683 if (E->isTypeOperand()) {
7684 TypeSourceInfo *TInfo
7685 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7686 if (!TInfo)
7687 return ExprError();
7688
7689 if (!getDerived().AlwaysRebuild() &&
7690 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007691 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007692
Douglas Gregor69735112011-03-06 17:40:41 +00007693 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007694 E->getLocStart(),
7695 TInfo,
7696 E->getLocEnd());
7697 }
7698
Francois Pichet9f4f2072010-09-08 12:20:18 +00007699 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7700
7701 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7702 if (SubExpr.isInvalid())
7703 return ExprError();
7704
7705 if (!getDerived().AlwaysRebuild() &&
7706 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007707 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007708
7709 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7710 E->getLocStart(),
7711 SubExpr.get(),
7712 E->getLocEnd());
7713}
7714
7715template<typename Derived>
7716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007717TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007718 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007719}
Mike Stump11289f42009-09-09 15:08:12 +00007720
Douglas Gregora16548e2009-08-11 05:31:07 +00007721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007722ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007723TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007724 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007725 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007726}
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007730TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007731 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007732
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007733 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7734 // Make sure that we capture 'this'.
7735 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007736 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007738
Douglas Gregorb15af892010-01-07 23:12:05 +00007739 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007740}
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregora16548e2009-08-11 05:31:07 +00007742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007744TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007745 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007748
Douglas Gregora16548e2009-08-11 05:31:07 +00007749 if (!getDerived().AlwaysRebuild() &&
7750 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007751 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007752
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007753 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7754 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007755}
Mike Stump11289f42009-09-09 15:08:12 +00007756
Douglas Gregora16548e2009-08-11 05:31:07 +00007757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007758ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007759TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007760 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007761 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7762 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007763 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007765
Chandler Carruth794da4c2010-02-08 06:42:49 +00007766 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007768 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregor033f6752009-12-23 23:03:06 +00007770 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007771}
Mike Stump11289f42009-09-09 15:08:12 +00007772
Douglas Gregora16548e2009-08-11 05:31:07 +00007773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007774ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007775TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7776 FieldDecl *Field
7777 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7778 E->getField()));
7779 if (!Field)
7780 return ExprError();
7781
7782 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007783 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007784
7785 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7786}
7787
7788template<typename Derived>
7789ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007790TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7791 CXXScalarValueInitExpr *E) {
7792 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7793 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007794 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007795
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007797 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007798 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007799
Chad Rosier1dcde962012-08-08 18:46:20 +00007800 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007801 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007802 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007803}
Mike Stump11289f42009-09-09 15:08:12 +00007804
Douglas Gregora16548e2009-08-11 05:31:07 +00007805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007807TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007808 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007809 TypeSourceInfo *AllocTypeInfo
7810 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7811 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007813
Douglas Gregora16548e2009-08-11 05:31:07 +00007814 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007815 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007816 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregora16548e2009-08-11 05:31:07 +00007819 // Transform the placement arguments (if any).
7820 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007821 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007822 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007823 E->getNumPlacementArgs(), true,
7824 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007826
Sebastian Redl6047f072012-02-16 12:22:20 +00007827 // Transform the initializer (if any).
7828 Expr *OldInit = E->getInitializer();
7829 ExprResult NewInit;
7830 if (OldInit)
7831 NewInit = getDerived().TransformExpr(OldInit);
7832 if (NewInit.isInvalid())
7833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007834
Sebastian Redl6047f072012-02-16 12:22:20 +00007835 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007836 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007837 if (E->getOperatorNew()) {
7838 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007839 getDerived().TransformDecl(E->getLocStart(),
7840 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007841 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007842 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007843 }
7844
Craig Topperc3ec1492014-05-26 06:22:03 +00007845 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007846 if (E->getOperatorDelete()) {
7847 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007848 getDerived().TransformDecl(E->getLocStart(),
7849 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007850 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007851 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007853
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007855 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007856 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007857 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007858 OperatorNew == E->getOperatorNew() &&
7859 OperatorDelete == E->getOperatorDelete() &&
7860 !ArgumentChanged) {
7861 // Mark any declarations we need as referenced.
7862 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007863 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007864 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007865 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007866 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007867
Sebastian Redl6047f072012-02-16 12:22:20 +00007868 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007869 QualType ElementType
7870 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7871 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7872 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7873 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007874 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007875 }
7876 }
7877 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007878
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007879 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007880 }
Mike Stump11289f42009-09-09 15:08:12 +00007881
Douglas Gregor0744ef62010-09-07 21:49:58 +00007882 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007883 if (!ArraySize.get()) {
7884 // If no array size was specified, but the new expression was
7885 // instantiated with an array type (e.g., "new T" where T is
7886 // instantiated with "int[4]"), extract the outer bound from the
7887 // array type as our array size. We do this with constant and
7888 // dependently-sized array types.
7889 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7890 if (!ArrayT) {
7891 // Do nothing
7892 } else if (const ConstantArrayType *ConsArrayT
7893 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007894 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7895 SemaRef.Context.getSizeType(),
7896 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007897 AllocType = ConsArrayT->getElementType();
7898 } else if (const DependentSizedArrayType *DepArrayT
7899 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7900 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007901 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007902 AllocType = DepArrayT->getElementType();
7903 }
7904 }
7905 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007906
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7908 E->isGlobalNew(),
7909 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007910 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007911 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007912 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007913 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007914 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007915 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007916 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007917 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007918}
Mike Stump11289f42009-09-09 15:08:12 +00007919
Douglas Gregora16548e2009-08-11 05:31:07 +00007920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007922TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007923 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007926
Douglas Gregord2d9da02010-02-26 00:38:10 +00007927 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007928 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007929 if (E->getOperatorDelete()) {
7930 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007931 getDerived().TransformDecl(E->getLocStart(),
7932 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007933 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007934 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007936
Douglas Gregora16548e2009-08-11 05:31:07 +00007937 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007938 Operand.get() == E->getArgument() &&
7939 OperatorDelete == E->getOperatorDelete()) {
7940 // Mark any declarations we need as referenced.
7941 // FIXME: instantiation-specific.
7942 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007943 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007944
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007945 if (!E->getArgument()->isTypeDependent()) {
7946 QualType Destroyed = SemaRef.Context.getBaseElementType(
7947 E->getDestroyedType());
7948 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7949 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007950 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007951 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007952 }
7953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007954
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007955 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007956 }
Mike Stump11289f42009-09-09 15:08:12 +00007957
Douglas Gregora16548e2009-08-11 05:31:07 +00007958 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7959 E->isGlobalDelete(),
7960 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007961 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007962}
Mike Stump11289f42009-09-09 15:08:12 +00007963
Douglas Gregora16548e2009-08-11 05:31:07 +00007964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007965ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007966TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007967 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007968 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007969 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007971
John McCallba7bf592010-08-24 05:47:05 +00007972 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007973 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007974 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007975 E->getOperatorLoc(),
7976 E->isArrow()? tok::arrow : tok::period,
7977 ObjectTypePtr,
7978 MayBePseudoDestructor);
7979 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007980 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007981
John McCallba7bf592010-08-24 05:47:05 +00007982 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007983 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7984 if (QualifierLoc) {
7985 QualifierLoc
7986 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7987 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007988 return ExprError();
7989 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007990 CXXScopeSpec SS;
7991 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007992
Douglas Gregor678f90d2010-02-25 01:56:36 +00007993 PseudoDestructorTypeStorage Destroyed;
7994 if (E->getDestroyedTypeInfo()) {
7995 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007996 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007997 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007998 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007999 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008000 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008001 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008002 // We aren't likely to be able to resolve the identifier down to a type
8003 // now anyway, so just retain the identifier.
8004 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8005 E->getDestroyedTypeLoc());
8006 } else {
8007 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008008 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008009 *E->getDestroyedTypeIdentifier(),
8010 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008011 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008012 SS, ObjectTypePtr,
8013 false);
8014 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008015 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008016
Douglas Gregor678f90d2010-02-25 01:56:36 +00008017 Destroyed
8018 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8019 E->getDestroyedTypeLoc());
8020 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008021
Craig Topperc3ec1492014-05-26 06:22:03 +00008022 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008023 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008024 CXXScopeSpec EmptySS;
8025 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008026 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008027 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008028 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008029 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008030
John McCallb268a282010-08-23 23:25:46 +00008031 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008032 E->getOperatorLoc(),
8033 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008034 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008035 ScopeTypeInfo,
8036 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008037 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008038 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008039}
Mike Stump11289f42009-09-09 15:08:12 +00008040
Douglas Gregorad8a3362009-09-04 17:36:40 +00008041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008043TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008044 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008045 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8046 Sema::LookupOrdinaryName);
8047
8048 // Transform all the decls.
8049 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8050 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008051 NamedDecl *InstD = static_cast<NamedDecl*>(
8052 getDerived().TransformDecl(Old->getNameLoc(),
8053 *I));
John McCall84d87672009-12-10 09:41:52 +00008054 if (!InstD) {
8055 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8056 // This can happen because of dependent hiding.
8057 if (isa<UsingShadowDecl>(*I))
8058 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008059 else {
8060 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008061 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008062 }
John McCall84d87672009-12-10 09:41:52 +00008063 }
John McCalle66edc12009-11-24 19:00:30 +00008064
8065 // Expand using declarations.
8066 if (isa<UsingDecl>(InstD)) {
8067 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008068 for (auto *I : UD->shadows())
8069 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008070 continue;
8071 }
8072
8073 R.addDecl(InstD);
8074 }
8075
8076 // Resolve a kind, but don't do any further analysis. If it's
8077 // ambiguous, the callee needs to deal with it.
8078 R.resolveKind();
8079
8080 // Rebuild the nested-name qualifier, if present.
8081 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008082 if (Old->getQualifierLoc()) {
8083 NestedNameSpecifierLoc QualifierLoc
8084 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8085 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008086 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008087
Douglas Gregor0da1d432011-02-28 20:01:57 +00008088 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008089 }
8090
Douglas Gregor9262f472010-04-27 18:19:34 +00008091 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008092 CXXRecordDecl *NamingClass
8093 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8094 Old->getNameLoc(),
8095 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008096 if (!NamingClass) {
8097 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008098 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
Douglas Gregorda7be082010-04-27 16:10:10 +00008101 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008102 }
8103
Abramo Bagnara7945c982012-01-27 09:46:47 +00008104 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8105
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008106 // If we have neither explicit template arguments, nor the template keyword,
8107 // it's a normal declaration name.
8108 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008109 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8110
8111 // If we have template arguments, rebuild them, then rebuild the
8112 // templateid expression.
8113 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008114 if (Old->hasExplicitTemplateArgs() &&
8115 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008116 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008117 TransArgs)) {
8118 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008119 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008120 }
John McCalle66edc12009-11-24 19:00:30 +00008121
Abramo Bagnara7945c982012-01-27 09:46:47 +00008122 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008123 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008124}
Mike Stump11289f42009-09-09 15:08:12 +00008125
Douglas Gregora16548e2009-08-11 05:31:07 +00008126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008127ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008128TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8129 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008130 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008131 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8132 TypeSourceInfo *From = E->getArg(I);
8133 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008134 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008135 TypeLocBuilder TLB;
8136 TLB.reserve(FromTL.getFullDataSize());
8137 QualType To = getDerived().TransformType(TLB, FromTL);
8138 if (To.isNull())
8139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008140
Douglas Gregor29c42f22012-02-24 07:38:34 +00008141 if (To == From->getType())
8142 Args.push_back(From);
8143 else {
8144 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8145 ArgChanged = true;
8146 }
8147 continue;
8148 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008149
Douglas Gregor29c42f22012-02-24 07:38:34 +00008150 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008151
Douglas Gregor29c42f22012-02-24 07:38:34 +00008152 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008153 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008154 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8155 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8156 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008157
Douglas Gregor29c42f22012-02-24 07:38:34 +00008158 // Determine whether the set of unexpanded parameter packs can and should
8159 // be expanded.
8160 bool Expand = true;
8161 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008162 Optional<unsigned> OrigNumExpansions =
8163 ExpansionTL.getTypePtr()->getNumExpansions();
8164 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008165 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8166 PatternTL.getSourceRange(),
8167 Unexpanded,
8168 Expand, RetainExpansion,
8169 NumExpansions))
8170 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008171
Douglas Gregor29c42f22012-02-24 07:38:34 +00008172 if (!Expand) {
8173 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008174 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008175 // expansion.
8176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008177
Douglas Gregor29c42f22012-02-24 07:38:34 +00008178 TypeLocBuilder TLB;
8179 TLB.reserve(From->getTypeLoc().getFullDataSize());
8180
8181 QualType To = getDerived().TransformType(TLB, PatternTL);
8182 if (To.isNull())
8183 return ExprError();
8184
Chad Rosier1dcde962012-08-08 18:46:20 +00008185 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008186 PatternTL.getSourceRange(),
8187 ExpansionTL.getEllipsisLoc(),
8188 NumExpansions);
8189 if (To.isNull())
8190 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008191
Douglas Gregor29c42f22012-02-24 07:38:34 +00008192 PackExpansionTypeLoc ToExpansionTL
8193 = TLB.push<PackExpansionTypeLoc>(To);
8194 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8195 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8196 continue;
8197 }
8198
8199 // Expand the pack expansion by substituting for each argument in the
8200 // pack(s).
8201 for (unsigned I = 0; I != *NumExpansions; ++I) {
8202 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8203 TypeLocBuilder TLB;
8204 TLB.reserve(PatternTL.getFullDataSize());
8205 QualType To = getDerived().TransformType(TLB, PatternTL);
8206 if (To.isNull())
8207 return ExprError();
8208
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008209 if (To->containsUnexpandedParameterPack()) {
8210 To = getDerived().RebuildPackExpansionType(To,
8211 PatternTL.getSourceRange(),
8212 ExpansionTL.getEllipsisLoc(),
8213 NumExpansions);
8214 if (To.isNull())
8215 return ExprError();
8216
8217 PackExpansionTypeLoc ToExpansionTL
8218 = TLB.push<PackExpansionTypeLoc>(To);
8219 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8220 }
8221
Douglas Gregor29c42f22012-02-24 07:38:34 +00008222 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8223 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008224
Douglas Gregor29c42f22012-02-24 07:38:34 +00008225 if (!RetainExpansion)
8226 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008227
Douglas Gregor29c42f22012-02-24 07:38:34 +00008228 // If we're supposed to retain a pack expansion, do so by temporarily
8229 // forgetting the partially-substituted parameter pack.
8230 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8231
8232 TypeLocBuilder TLB;
8233 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008234
Douglas Gregor29c42f22012-02-24 07:38:34 +00008235 QualType To = getDerived().TransformType(TLB, PatternTL);
8236 if (To.isNull())
8237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008238
8239 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008240 PatternTL.getSourceRange(),
8241 ExpansionTL.getEllipsisLoc(),
8242 NumExpansions);
8243 if (To.isNull())
8244 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008245
Douglas Gregor29c42f22012-02-24 07:38:34 +00008246 PackExpansionTypeLoc ToExpansionTL
8247 = TLB.push<PackExpansionTypeLoc>(To);
8248 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8249 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008251
Douglas Gregor29c42f22012-02-24 07:38:34 +00008252 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008253 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008254
8255 return getDerived().RebuildTypeTrait(E->getTrait(),
8256 E->getLocStart(),
8257 Args,
8258 E->getLocEnd());
8259}
8260
8261template<typename Derived>
8262ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008263TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8264 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8265 if (!T)
8266 return ExprError();
8267
8268 if (!getDerived().AlwaysRebuild() &&
8269 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008270 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008271
8272 ExprResult SubExpr;
8273 {
8274 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8275 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8276 if (SubExpr.isInvalid())
8277 return ExprError();
8278
8279 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008280 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008281 }
8282
8283 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8284 E->getLocStart(),
8285 T,
8286 SubExpr.get(),
8287 E->getLocEnd());
8288}
8289
8290template<typename Derived>
8291ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008292TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8293 ExprResult SubExpr;
8294 {
8295 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8296 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8297 if (SubExpr.isInvalid())
8298 return ExprError();
8299
8300 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008301 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008302 }
8303
8304 return getDerived().RebuildExpressionTrait(
8305 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8306}
8307
Reid Kleckner32506ed2014-06-12 23:03:48 +00008308template <typename Derived>
8309ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8310 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8311 TypeSourceInfo **RecoveryTSI) {
8312 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8313 DRE, AddrTaken, RecoveryTSI);
8314
8315 // Propagate both errors and recovered types, which return ExprEmpty.
8316 if (!NewDRE.isUsable())
8317 return NewDRE;
8318
8319 // We got an expr, wrap it up in parens.
8320 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8321 return PE;
8322 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8323 PE->getRParen());
8324}
8325
8326template <typename Derived>
8327ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8328 DependentScopeDeclRefExpr *E) {
8329 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8330 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008331}
8332
8333template<typename Derived>
8334ExprResult
8335TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8336 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008337 bool IsAddressOfOperand,
8338 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008339 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008340 NestedNameSpecifierLoc QualifierLoc
8341 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8342 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008343 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008344 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008345
John McCall31f82722010-11-12 08:19:04 +00008346 // TODO: If this is a conversion-function-id, verify that the
8347 // destination type name (if present) resolves the same way after
8348 // instantiation as it did in the local scope.
8349
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008350 DeclarationNameInfo NameInfo
8351 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8352 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008354
John McCalle66edc12009-11-24 19:00:30 +00008355 if (!E->hasExplicitTemplateArgs()) {
8356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008357 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008358 // Note: it is sufficient to compare the Name component of NameInfo:
8359 // if name has not changed, DNLoc has not changed either.
8360 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008361 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008362
Reid Kleckner32506ed2014-06-12 23:03:48 +00008363 return getDerived().RebuildDependentScopeDeclRefExpr(
8364 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8365 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008366 }
John McCall6b51f282009-11-23 01:53:49 +00008367
8368 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008369 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8370 E->getNumTemplateArgs(),
8371 TransArgs))
8372 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008373
Reid Kleckner32506ed2014-06-12 23:03:48 +00008374 return getDerived().RebuildDependentScopeDeclRefExpr(
8375 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8376 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008377}
8378
8379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008381TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008382 // CXXConstructExprs other than for list-initialization and
8383 // CXXTemporaryObjectExpr are always implicit, so when we have
8384 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008385 if ((E->getNumArgs() == 1 ||
8386 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008387 (!getDerived().DropCallArgument(E->getArg(0))) &&
8388 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008389 return getDerived().TransformExpr(E->getArg(0));
8390
Douglas Gregora16548e2009-08-11 05:31:07 +00008391 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8392
8393 QualType T = getDerived().TransformType(E->getType());
8394 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008395 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008396
8397 CXXConstructorDecl *Constructor
8398 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008399 getDerived().TransformDecl(E->getLocStart(),
8400 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008401 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008403
Douglas Gregora16548e2009-08-11 05:31:07 +00008404 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008405 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008406 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008407 &ArgumentChanged))
8408 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008409
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 if (!getDerived().AlwaysRebuild() &&
8411 T == E->getType() &&
8412 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008413 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008414 // Mark the constructor as referenced.
8415 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008416 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008417 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008418 }
Mike Stump11289f42009-09-09 15:08:12 +00008419
Douglas Gregordb121ba2009-12-14 16:27:04 +00008420 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8421 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008422 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008423 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008424 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008425 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008426 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008427 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008428}
Mike Stump11289f42009-09-09 15:08:12 +00008429
Douglas Gregora16548e2009-08-11 05:31:07 +00008430/// \brief Transform a C++ temporary-binding expression.
8431///
Douglas Gregor363b1512009-12-24 18:51:59 +00008432/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8433/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008436TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008437 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008438}
Mike Stump11289f42009-09-09 15:08:12 +00008439
John McCall5d413782010-12-06 08:20:24 +00008440/// \brief Transform a C++ expression that contains cleanups that should
8441/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008442///
John McCall5d413782010-12-06 08:20:24 +00008443/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008444/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008446ExprResult
John McCall5d413782010-12-06 08:20:24 +00008447TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008448 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008449}
Mike Stump11289f42009-09-09 15:08:12 +00008450
Douglas Gregora16548e2009-08-11 05:31:07 +00008451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008452ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008453TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008454 CXXTemporaryObjectExpr *E) {
8455 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8456 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008458
Douglas Gregora16548e2009-08-11 05:31:07 +00008459 CXXConstructorDecl *Constructor
8460 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008461 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008462 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008463 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008465
Douglas Gregora16548e2009-08-11 05:31:07 +00008466 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008467 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008468 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008469 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008470 &ArgumentChanged))
8471 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008472
Douglas Gregora16548e2009-08-11 05:31:07 +00008473 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008474 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008475 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008476 !ArgumentChanged) {
8477 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008478 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008479 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008481
Richard Smithd59b8322012-12-19 01:39:02 +00008482 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008483 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8484 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008485 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008486 E->getLocEnd());
8487}
Mike Stump11289f42009-09-09 15:08:12 +00008488
Douglas Gregora16548e2009-08-11 05:31:07 +00008489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008490ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008491TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008492
8493 // Transform any init-capture expressions before entering the scope of the
8494 // lambda body, because they are not semantically within that scope.
8495 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8496 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8497 E->explicit_capture_begin());
8498
8499 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8500 CEnd = E->capture_end();
8501 C != CEnd; ++C) {
8502 if (!C->isInitCapture())
8503 continue;
8504 EnterExpressionEvaluationContext EEEC(getSema(),
8505 Sema::PotentiallyEvaluated);
8506 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8507 C->getCapturedVar()->getInit(),
8508 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8509
8510 if (NewExprInitResult.isInvalid())
8511 return ExprError();
8512 Expr *NewExprInit = NewExprInitResult.get();
8513
8514 VarDecl *OldVD = C->getCapturedVar();
8515 QualType NewInitCaptureType =
8516 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8517 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8518 NewExprInit);
8519 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008520 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8521 std::make_pair(NewExprInitResult, NewInitCaptureType);
8522
8523 }
8524
Faisal Vali524ca282013-11-12 01:40:44 +00008525 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008526 // Transform the template parameters, and add them to the current
8527 // instantiation scope. The null case is handled correctly.
8528 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8529 E->getTemplateParameterList());
8530
8531 // Check to see if the TypeSourceInfo of the call operator needs to
8532 // be transformed, and if so do the transformation in the
8533 // CurrentInstantiationScope.
8534
8535 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8536 FunctionProtoTypeLoc OldCallOpFPTL =
8537 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008538 TypeSourceInfo *NewCallOpTSI = nullptr;
8539
Faisal Vali2cba1332013-10-23 06:44:28 +00008540 const bool CallOpWasAlreadyTransformed =
8541 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8542
8543 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8544 if (CallOpWasAlreadyTransformed)
8545 NewCallOpTSI = OldCallOpTSI;
8546 else {
8547 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8548 // The transformation MUST be done in the CurrentInstantiationScope since
8549 // it introduces a mapping of the original to the newly created
8550 // transformed parameters.
8551
8552 TypeLocBuilder NewCallOpTLBuilder;
8553 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8554 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008555 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008556 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8557 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008558 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008559 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8560 // the vector below - this will be used to synthesize the
8561 // NewCallOperator. Additionally, add the parameters of the untransformed
8562 // lambda call operator to the CurrentInstantiationScope.
8563 SmallVector<ParmVarDecl *, 4> Params;
8564 {
8565 FunctionProtoTypeLoc NewCallOpFPTL =
8566 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8567 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008568 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008569
8570 for (unsigned I = 0; I < NewNumArgs; ++I) {
8571 // If this call operator's type does not require transformation,
8572 // the parameters do not get added to the current instantiation scope,
8573 // - so ADD them! This allows the following to compile when the enclosing
8574 // template is specialized and the entire lambda expression has to be
8575 // transformed.
8576 // template<class T> void foo(T t) {
8577 // auto L = [](auto a) {
8578 // auto M = [](char b) { <-- note: non-generic lambda
8579 // auto N = [](auto c) {
8580 // int x = sizeof(a);
8581 // x = sizeof(b); <-- specifically this line
8582 // x = sizeof(c);
8583 // };
8584 // };
8585 // };
8586 // }
8587 // foo('a')
8588 if (CallOpWasAlreadyTransformed)
8589 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8590 NewParamDeclArray[I]);
8591 // Add to Params array, so these parameters can be used to create
8592 // the newly transformed call operator.
8593 Params.push_back(NewParamDeclArray[I]);
8594 }
8595 }
8596
8597 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008598 return ExprError();
8599
Eli Friedmand564afb2012-09-19 01:18:11 +00008600 // Create the local class that will describe the lambda.
8601 CXXRecordDecl *Class
8602 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008603 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008604 /*KnownDependent=*/false,
8605 E->getCaptureDefault());
8606
Eli Friedmand564afb2012-09-19 01:18:11 +00008607 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8608
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008609 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008610 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008611 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008612 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008613 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008614 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008615 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008616
Faisal Vali2cba1332013-10-23 06:44:28 +00008617 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8618
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008619 return getDerived().TransformLambdaScope(E, NewCallOperator,
8620 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008621}
8622
8623template<typename Derived>
8624ExprResult
8625TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008626 CXXMethodDecl *CallOperator,
8627 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008628 bool Invalid = false;
8629
Douglas Gregorb4328232012-02-14 00:00:48 +00008630 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008631 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8632 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008633
Faisal Vali2b391ab2013-09-26 19:54:12 +00008634 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008635 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008636 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008637 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008638 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008639 E->hasExplicitParameters(),
8640 E->hasExplicitResultType(),
8641 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008642
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008643 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008644 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008645 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008646 CEnd = E->capture_end();
8647 C != CEnd; ++C) {
8648 // When we hit the first implicit capture, tell Sema that we've finished
8649 // the list of explicit captures.
8650 if (!FinishedExplicitCaptures && C->isImplicit()) {
8651 getSema().finishLambdaExplicitCaptures(LSI);
8652 FinishedExplicitCaptures = true;
8653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008654
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008655 // Capturing 'this' is trivial.
8656 if (C->capturesThis()) {
8657 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8658 continue;
8659 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008660
Richard Smithba71c082013-05-16 06:20:58 +00008661 // Rebuild init-captures, including the implied field declaration.
8662 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008663
8664 InitCaptureInfoTy InitExprTypePair =
8665 InitCaptureExprsAndTypes[C - E->capture_begin()];
8666 ExprResult Init = InitExprTypePair.first;
8667 QualType InitQualType = InitExprTypePair.second;
8668 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008669 Invalid = true;
8670 continue;
8671 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008672 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008673 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8674 OldVD->getLocation(), InitExprTypePair.second,
8675 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008676 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008677 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008678 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008679 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008680 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008681 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008682 continue;
8683 }
8684
8685 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8686
Douglas Gregor3e308b12012-02-14 19:27:52 +00008687 // Determine the capture kind for Sema.
8688 Sema::TryCaptureKind Kind
8689 = C->isImplicit()? Sema::TryCapture_Implicit
8690 : C->getCaptureKind() == LCK_ByCopy
8691 ? Sema::TryCapture_ExplicitByVal
8692 : Sema::TryCapture_ExplicitByRef;
8693 SourceLocation EllipsisLoc;
8694 if (C->isPackExpansion()) {
8695 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8696 bool ShouldExpand = false;
8697 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008698 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008699 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8700 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008701 Unexpanded,
8702 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008703 NumExpansions)) {
8704 Invalid = true;
8705 continue;
8706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008707
Douglas Gregor3e308b12012-02-14 19:27:52 +00008708 if (ShouldExpand) {
8709 // The transform has determined that we should perform an expansion;
8710 // transform and capture each of the arguments.
8711 // expansion of the pattern. Do so.
8712 VarDecl *Pack = C->getCapturedVar();
8713 for (unsigned I = 0; I != *NumExpansions; ++I) {
8714 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8715 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008716 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008717 Pack));
8718 if (!CapturedVar) {
8719 Invalid = true;
8720 continue;
8721 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008722
Douglas Gregor3e308b12012-02-14 19:27:52 +00008723 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008724 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8725 }
Richard Smith9467be42014-06-06 17:33:35 +00008726
8727 // FIXME: Retain a pack expansion if RetainExpansion is true.
8728
Douglas Gregor3e308b12012-02-14 19:27:52 +00008729 continue;
8730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008731
Douglas Gregor3e308b12012-02-14 19:27:52 +00008732 EllipsisLoc = C->getEllipsisLoc();
8733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008734
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008735 // Transform the captured variable.
8736 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008737 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008738 C->getCapturedVar()));
8739 if (!CapturedVar) {
8740 Invalid = true;
8741 continue;
8742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008743
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008744 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008745 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008746 }
8747 if (!FinishedExplicitCaptures)
8748 getSema().finishLambdaExplicitCaptures(LSI);
8749
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008750
8751 // Enter a new evaluation context to insulate the lambda from any
8752 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008753 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008754
8755 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008756 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008757 /*IsInstantiation=*/true);
8758 return ExprError();
8759 }
8760
8761 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008762 StmtResult Body = getDerived().TransformStmt(E->getBody());
8763 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008764 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008765 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008766 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008767 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008768
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008769 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008770 /*CurScope=*/nullptr,
8771 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008772}
8773
8774template<typename Derived>
8775ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008776TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008777 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008778 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8779 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008781
Douglas Gregora16548e2009-08-11 05:31:07 +00008782 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008783 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008784 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008785 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008786 &ArgumentChanged))
8787 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008788
Douglas Gregora16548e2009-08-11 05:31:07 +00008789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008790 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008791 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008792 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008793
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008795 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008796 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008797 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 E->getRParenLoc());
8799}
Mike Stump11289f42009-09-09 15:08:12 +00008800
Douglas Gregora16548e2009-08-11 05:31:07 +00008801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008802ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008803TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008804 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008806 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008807 Expr *OldBase;
8808 QualType BaseType;
8809 QualType ObjectType;
8810 if (!E->isImplicitAccess()) {
8811 OldBase = E->getBase();
8812 Base = getDerived().TransformExpr(OldBase);
8813 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008814 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008815
John McCall2d74de92009-12-01 22:10:20 +00008816 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008817 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008818 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008819 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008820 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008821 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008822 ObjectTy,
8823 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008824 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008825 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008826
John McCallba7bf592010-08-24 05:47:05 +00008827 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008828 BaseType = ((Expr*) Base.get())->getType();
8829 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008830 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008831 BaseType = getDerived().TransformType(E->getBaseType());
8832 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8833 }
Mike Stump11289f42009-09-09 15:08:12 +00008834
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008835 // Transform the first part of the nested-name-specifier that qualifies
8836 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008837 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008838 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008839 E->getFirstQualifierFoundInScope(),
8840 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008841
Douglas Gregore16af532011-02-28 18:50:33 +00008842 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008843 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008844 QualifierLoc
8845 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8846 ObjectType,
8847 FirstQualifierInScope);
8848 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008849 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008850 }
Mike Stump11289f42009-09-09 15:08:12 +00008851
Abramo Bagnara7945c982012-01-27 09:46:47 +00008852 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8853
John McCall31f82722010-11-12 08:19:04 +00008854 // TODO: If this is a conversion-function-id, verify that the
8855 // destination type name (if present) resolves the same way after
8856 // instantiation as it did in the local scope.
8857
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008858 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008859 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008860 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008862
John McCall2d74de92009-12-01 22:10:20 +00008863 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008864 // This is a reference to a member without an explicitly-specified
8865 // template argument list. Optimize for this common case.
8866 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008867 Base.get() == OldBase &&
8868 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008869 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008870 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008871 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008872 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008873
John McCallb268a282010-08-23 23:25:46 +00008874 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008875 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008876 E->isArrow(),
8877 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008878 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008879 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008880 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008881 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008882 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008883 }
8884
John McCall6b51f282009-11-23 01:53:49 +00008885 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008886 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8887 E->getNumTemplateArgs(),
8888 TransArgs))
8889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008890
John McCallb268a282010-08-23 23:25:46 +00008891 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008892 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 E->isArrow(),
8894 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008895 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008896 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008897 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008898 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008899 &TransArgs);
8900}
8901
8902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008904TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008905 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008906 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008907 QualType BaseType;
8908 if (!Old->isImplicitAccess()) {
8909 Base = getDerived().TransformExpr(Old->getBase());
8910 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008911 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008912 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008913 Old->isArrow());
8914 if (Base.isInvalid())
8915 return ExprError();
8916 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008917 } else {
8918 BaseType = getDerived().TransformType(Old->getBaseType());
8919 }
John McCall10eae182009-11-30 22:42:35 +00008920
Douglas Gregor0da1d432011-02-28 20:01:57 +00008921 NestedNameSpecifierLoc QualifierLoc;
8922 if (Old->getQualifierLoc()) {
8923 QualifierLoc
8924 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8925 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008926 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008927 }
8928
Abramo Bagnara7945c982012-01-27 09:46:47 +00008929 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8930
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008931 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008932 Sema::LookupOrdinaryName);
8933
8934 // Transform all the decls.
8935 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8936 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008937 NamedDecl *InstD = static_cast<NamedDecl*>(
8938 getDerived().TransformDecl(Old->getMemberLoc(),
8939 *I));
John McCall84d87672009-12-10 09:41:52 +00008940 if (!InstD) {
8941 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8942 // This can happen because of dependent hiding.
8943 if (isa<UsingShadowDecl>(*I))
8944 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008945 else {
8946 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008947 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008948 }
John McCall84d87672009-12-10 09:41:52 +00008949 }
John McCall10eae182009-11-30 22:42:35 +00008950
8951 // Expand using declarations.
8952 if (isa<UsingDecl>(InstD)) {
8953 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008954 for (auto *I : UD->shadows())
8955 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008956 continue;
8957 }
8958
8959 R.addDecl(InstD);
8960 }
8961
8962 R.resolveKind();
8963
Douglas Gregor9262f472010-04-27 18:19:34 +00008964 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008965 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008966 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008967 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008968 Old->getMemberLoc(),
8969 Old->getNamingClass()));
8970 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008972
Douglas Gregorda7be082010-04-27 16:10:10 +00008973 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008975
John McCall10eae182009-11-30 22:42:35 +00008976 TemplateArgumentListInfo TransArgs;
8977 if (Old->hasExplicitTemplateArgs()) {
8978 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8979 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008980 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8981 Old->getNumTemplateArgs(),
8982 TransArgs))
8983 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008984 }
John McCall38836f02010-01-15 08:34:02 +00008985
8986 // FIXME: to do this check properly, we will need to preserve the
8987 // first-qualifier-in-scope here, just in case we had a dependent
8988 // base (and therefore couldn't do the check) and a
8989 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008990 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008991
John McCallb268a282010-08-23 23:25:46 +00008992 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008993 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008994 Old->getOperatorLoc(),
8995 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008996 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008997 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008998 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008999 R,
9000 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009001 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009002}
9003
9004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009005ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009006TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009007 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009008 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9009 if (SubExpr.isInvalid())
9010 return ExprError();
9011
9012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009013 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009014
9015 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9016}
9017
9018template<typename Derived>
9019ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009020TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009021 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9022 if (Pattern.isInvalid())
9023 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009024
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009025 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009026 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009027
Douglas Gregorb8840002011-01-14 21:20:45 +00009028 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9029 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009030}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009031
9032template<typename Derived>
9033ExprResult
9034TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9035 // If E is not value-dependent, then nothing will change when we transform it.
9036 // Note: This is an instantiation-centric view.
9037 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009038 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009039
9040 // Note: None of the implementations of TryExpandParameterPacks can ever
9041 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009042 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009043 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9044 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009045 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009046 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009047 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009048 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009049 ShouldExpand, RetainExpansion,
9050 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009051 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009052
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009053 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009054 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009055
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009056 NamedDecl *Pack = E->getPack();
9057 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009058 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009059 Pack));
9060 if (!Pack)
9061 return ExprError();
9062 }
9063
Chad Rosier1dcde962012-08-08 18:46:20 +00009064
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009065 // We now know the length of the parameter pack, so build a new expression
9066 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009067 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9068 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009069 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009070}
9071
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009072template<typename Derived>
9073ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009074TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9075 SubstNonTypeTemplateParmPackExpr *E) {
9076 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009077 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009078}
9079
9080template<typename Derived>
9081ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009082TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9083 SubstNonTypeTemplateParmExpr *E) {
9084 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009085 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009086}
9087
9088template<typename Derived>
9089ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009090TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9091 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009092 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009093}
9094
9095template<typename Derived>
9096ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009097TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9098 MaterializeTemporaryExpr *E) {
9099 return getDerived().TransformExpr(E->GetTemporaryExpr());
9100}
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
Douglas Gregorfe314812011-06-21 17:03:29 +00009102template<typename Derived>
9103ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009104TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9105 CXXStdInitializerListExpr *E) {
9106 return getDerived().TransformExpr(E->getSubExpr());
9107}
9108
9109template<typename Derived>
9110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009111TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009112 return SemaRef.MaybeBindToTemporary(E);
9113}
9114
9115template<typename Derived>
9116ExprResult
9117TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009118 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009119}
9120
9121template<typename Derived>
9122ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009123TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9124 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9125 if (SubExpr.isInvalid())
9126 return ExprError();
9127
9128 if (!getDerived().AlwaysRebuild() &&
9129 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009130 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009131
9132 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009133}
9134
9135template<typename Derived>
9136ExprResult
9137TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9138 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009139 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009140 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009141 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009142 /*IsCall=*/false, Elements, &ArgChanged))
9143 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009144
Ted Kremeneke65b0862012-03-06 20:05:56 +00009145 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9146 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009147
Ted Kremeneke65b0862012-03-06 20:05:56 +00009148 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9149 Elements.data(),
9150 Elements.size());
9151}
9152
9153template<typename Derived>
9154ExprResult
9155TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009156 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009157 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009158 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009159 bool ArgChanged = false;
9160 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9161 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009162
Ted Kremeneke65b0862012-03-06 20:05:56 +00009163 if (OrigElement.isPackExpansion()) {
9164 // This key/value element is a pack expansion.
9165 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9166 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9167 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9168 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9169
9170 // Determine whether the set of unexpanded parameter packs can
9171 // and should be expanded.
9172 bool Expand = true;
9173 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009174 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9175 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009176 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9177 OrigElement.Value->getLocEnd());
9178 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9179 PatternRange,
9180 Unexpanded,
9181 Expand, RetainExpansion,
9182 NumExpansions))
9183 return ExprError();
9184
9185 if (!Expand) {
9186 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009187 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009188 // expansion.
9189 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9190 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9191 if (Key.isInvalid())
9192 return ExprError();
9193
9194 if (Key.get() != OrigElement.Key)
9195 ArgChanged = true;
9196
9197 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9198 if (Value.isInvalid())
9199 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009200
Ted Kremeneke65b0862012-03-06 20:05:56 +00009201 if (Value.get() != OrigElement.Value)
9202 ArgChanged = true;
9203
Chad Rosier1dcde962012-08-08 18:46:20 +00009204 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009205 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9206 };
9207 Elements.push_back(Expansion);
9208 continue;
9209 }
9210
9211 // Record right away that the argument was changed. This needs
9212 // to happen even if the array expands to nothing.
9213 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009214
Ted Kremeneke65b0862012-03-06 20:05:56 +00009215 // The transform has determined that we should perform an elementwise
9216 // expansion of the pattern. Do so.
9217 for (unsigned I = 0; I != *NumExpansions; ++I) {
9218 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9219 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9220 if (Key.isInvalid())
9221 return ExprError();
9222
9223 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9224 if (Value.isInvalid())
9225 return ExprError();
9226
Chad Rosier1dcde962012-08-08 18:46:20 +00009227 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009228 Key.get(), Value.get(), SourceLocation(), NumExpansions
9229 };
9230
9231 // If any unexpanded parameter packs remain, we still have a
9232 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009233 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009234 if (Key.get()->containsUnexpandedParameterPack() ||
9235 Value.get()->containsUnexpandedParameterPack())
9236 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009237
Ted Kremeneke65b0862012-03-06 20:05:56 +00009238 Elements.push_back(Element);
9239 }
9240
Richard Smith9467be42014-06-06 17:33:35 +00009241 // FIXME: Retain a pack expansion if RetainExpansion is true.
9242
Ted Kremeneke65b0862012-03-06 20:05:56 +00009243 // We've finished with this pack expansion.
9244 continue;
9245 }
9246
9247 // Transform and check key.
9248 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9249 if (Key.isInvalid())
9250 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
Ted Kremeneke65b0862012-03-06 20:05:56 +00009252 if (Key.get() != OrigElement.Key)
9253 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009254
Ted Kremeneke65b0862012-03-06 20:05:56 +00009255 // Transform and check value.
9256 ExprResult Value
9257 = 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;
Chad Rosier1dcde962012-08-08 18:46:20 +00009263
9264 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009265 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009266 };
9267 Elements.push_back(Element);
9268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Ted Kremeneke65b0862012-03-06 20:05:56 +00009270 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9271 return SemaRef.MaybeBindToTemporary(E);
9272
9273 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9274 Elements.data(),
9275 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009276}
9277
Mike Stump11289f42009-09-09 15:08:12 +00009278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009281 TypeSourceInfo *EncodedTypeInfo
9282 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9283 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009285
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009287 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009288 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009289
9290 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009291 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009292 E->getRParenLoc());
9293}
Mike Stump11289f42009-09-09 15:08:12 +00009294
Douglas Gregora16548e2009-08-11 05:31:07 +00009295template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009296ExprResult TreeTransform<Derived>::
9297TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009298 // This is a kind of implicit conversion, and it needs to get dropped
9299 // and recomputed for the same general reasons that ImplicitCastExprs
9300 // do, as well a more specific one: this expression is only valid when
9301 // it appears *immediately* as an argument expression.
9302 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009303}
9304
9305template<typename Derived>
9306ExprResult TreeTransform<Derived>::
9307TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009308 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009309 = getDerived().TransformType(E->getTypeInfoAsWritten());
9310 if (!TSInfo)
9311 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009312
John McCall31168b02011-06-15 23:02:42 +00009313 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009314 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
John McCall31168b02011-06-15 23:02:42 +00009317 if (!getDerived().AlwaysRebuild() &&
9318 TSInfo == E->getTypeInfoAsWritten() &&
9319 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009320 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009321
John McCall31168b02011-06-15 23:02:42 +00009322 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009323 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009324 Result.get());
9325}
9326
9327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009329TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009330 // Transform arguments.
9331 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009332 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009333 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009334 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009335 &ArgChanged))
9336 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009337
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009338 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9339 // Class message: transform the receiver type.
9340 TypeSourceInfo *ReceiverTypeInfo
9341 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9342 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009343 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009345 // If nothing changed, just retain the existing message send.
9346 if (!getDerived().AlwaysRebuild() &&
9347 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009348 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009349
9350 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009351 SmallVector<SourceLocation, 16> SelLocs;
9352 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009353 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9354 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009355 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009356 E->getMethodDecl(),
9357 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009358 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009359 E->getRightLoc());
9360 }
9361
9362 // Instance message: transform the receiver
9363 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9364 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009365 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009366 = getDerived().TransformExpr(E->getInstanceReceiver());
9367 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009368 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009369
9370 // If nothing changed, just retain the existing message send.
9371 if (!getDerived().AlwaysRebuild() &&
9372 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009373 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009374
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009375 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009376 SmallVector<SourceLocation, 16> SelLocs;
9377 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009378 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009379 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009380 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009381 E->getMethodDecl(),
9382 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009383 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009384 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009385}
9386
Mike Stump11289f42009-09-09 15:08:12 +00009387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009389TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009390 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009391}
9392
Mike Stump11289f42009-09-09 15:08:12 +00009393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009395TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009396 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009397}
9398
Mike Stump11289f42009-09-09 15:08:12 +00009399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009401TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009402 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009403 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009404 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009405 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009406
9407 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009408
Douglas Gregord51d90d2010-04-26 20:11:03 +00009409 // If nothing changed, just retain the existing expression.
9410 if (!getDerived().AlwaysRebuild() &&
9411 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009412 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009413
John McCallb268a282010-08-23 23:25:46 +00009414 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009415 E->getLocation(),
9416 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009417}
9418
Mike Stump11289f42009-09-09 15:08:12 +00009419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009421TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009422 // 'super' and types never change. Property never changes. Just
9423 // retain the existing expression.
9424 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009425 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009426
Douglas Gregor9faee212010-04-26 20:47:02 +00009427 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009428 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009429 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009430 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009431
Douglas Gregor9faee212010-04-26 20:47:02 +00009432 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009433
Douglas Gregor9faee212010-04-26 20:47:02 +00009434 // If nothing changed, just retain the existing expression.
9435 if (!getDerived().AlwaysRebuild() &&
9436 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009437 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009438
John McCallb7bd14f2010-12-02 01:19:52 +00009439 if (E->isExplicitProperty())
9440 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9441 E->getExplicitProperty(),
9442 E->getLocation());
9443
9444 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009445 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009446 E->getImplicitPropertyGetter(),
9447 E->getImplicitPropertySetter(),
9448 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009449}
9450
Mike Stump11289f42009-09-09 15:08:12 +00009451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009452ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009453TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9454 // Transform the base expression.
9455 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9456 if (Base.isInvalid())
9457 return ExprError();
9458
9459 // Transform the key expression.
9460 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9461 if (Key.isInvalid())
9462 return ExprError();
9463
9464 // If nothing changed, just retain the existing expression.
9465 if (!getDerived().AlwaysRebuild() &&
9466 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009467 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009468
Chad Rosier1dcde962012-08-08 18:46:20 +00009469 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009470 Base.get(), Key.get(),
9471 E->getAtIndexMethodDecl(),
9472 E->setAtIndexMethodDecl());
9473}
9474
9475template<typename Derived>
9476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009477TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009478 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009479 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009480 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009481 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009482
Douglas Gregord51d90d2010-04-26 20:11:03 +00009483 // If nothing changed, just retain the existing expression.
9484 if (!getDerived().AlwaysRebuild() &&
9485 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009486 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009487
John McCallb268a282010-08-23 23:25:46 +00009488 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009489 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009490 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009491}
9492
Mike Stump11289f42009-09-09 15:08:12 +00009493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009495TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009496 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009497 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009498 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009499 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009500 SubExprs, &ArgumentChanged))
9501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009502
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 if (!getDerived().AlwaysRebuild() &&
9504 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009505 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009506
Douglas Gregora16548e2009-08-11 05:31:07 +00009507 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009508 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009509 E->getRParenLoc());
9510}
9511
Mike Stump11289f42009-09-09 15:08:12 +00009512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009513ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009514TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9515 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9516 if (SrcExpr.isInvalid())
9517 return ExprError();
9518
9519 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9520 if (!Type)
9521 return ExprError();
9522
9523 if (!getDerived().AlwaysRebuild() &&
9524 Type == E->getTypeSourceInfo() &&
9525 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009526 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009527
9528 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9529 SrcExpr.get(), Type,
9530 E->getRParenLoc());
9531}
9532
9533template<typename Derived>
9534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009535TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009536 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009537
Craig Topperc3ec1492014-05-26 06:22:03 +00009538 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009539 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9540
9541 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009542 blockScope->TheDecl->setBlockMissingReturnType(
9543 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009544
Chris Lattner01cf8db2011-07-20 06:58:45 +00009545 SmallVector<ParmVarDecl*, 4> params;
9546 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009547
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009548 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009549 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9550 oldBlock->param_begin(),
9551 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009552 nullptr, paramTypes, &params)) {
9553 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009554 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009555 }
John McCall490112f2011-02-04 18:33:18 +00009556
Jordan Rosea0a86be2013-03-08 22:25:36 +00009557 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009558 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009559 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009560
Jordan Rose5c382722013-03-08 21:51:21 +00009561 QualType functionType =
9562 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009563 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009564 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009565
9566 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009567 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009568 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009569
9570 if (!oldBlock->blockMissingReturnType()) {
9571 blockScope->HasImplicitReturnType = false;
9572 blockScope->ReturnType = exprResultType;
9573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009574
John McCall3882ace2011-01-05 12:14:39 +00009575 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009576 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009577 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009578 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009579 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009580 }
John McCall3882ace2011-01-05 12:14:39 +00009581
John McCall490112f2011-02-04 18:33:18 +00009582#ifndef NDEBUG
9583 // In builds with assertions, make sure that we captured everything we
9584 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009585 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009586 for (const auto &I : oldBlock->captures()) {
9587 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009588
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009589 // Ignore parameter packs.
9590 if (isa<ParmVarDecl>(oldCapture) &&
9591 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9592 continue;
John McCall490112f2011-02-04 18:33:18 +00009593
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009594 VarDecl *newCapture =
9595 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9596 oldCapture));
9597 assert(blockScope->CaptureMap.count(newCapture));
9598 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009599 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009600 }
9601#endif
9602
9603 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009604 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009605}
9606
Mike Stump11289f42009-09-09 15:08:12 +00009607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009608ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009609TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009610 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009611}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009612
9613template<typename Derived>
9614ExprResult
9615TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009616 QualType RetTy = getDerived().TransformType(E->getType());
9617 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009618 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009619 SubExprs.reserve(E->getNumSubExprs());
9620 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9621 SubExprs, &ArgumentChanged))
9622 return ExprError();
9623
9624 if (!getDerived().AlwaysRebuild() &&
9625 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009626 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009627
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009628 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009629 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009630}
Chad Rosier1dcde962012-08-08 18:46:20 +00009631
Douglas Gregora16548e2009-08-11 05:31:07 +00009632//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009633// Type reconstruction
9634//===----------------------------------------------------------------------===//
9635
Mike Stump11289f42009-09-09 15:08:12 +00009636template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009637QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9638 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009639 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009640 getDerived().getBaseEntity());
9641}
9642
Mike Stump11289f42009-09-09 15:08:12 +00009643template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009644QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9645 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009646 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009647 getDerived().getBaseEntity());
9648}
9649
Mike Stump11289f42009-09-09 15:08:12 +00009650template<typename Derived>
9651QualType
John McCall70dd5f62009-10-30 00:06:24 +00009652TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9653 bool WrittenAsLValue,
9654 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009655 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009656 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009657}
9658
9659template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009660QualType
John McCall70dd5f62009-10-30 00:06:24 +00009661TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9662 QualType ClassType,
9663 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009664 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9665 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009666}
9667
9668template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009669QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009670TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9671 ArrayType::ArraySizeModifier SizeMod,
9672 const llvm::APInt *Size,
9673 Expr *SizeExpr,
9674 unsigned IndexTypeQuals,
9675 SourceRange BracketsRange) {
9676 if (SizeExpr || !Size)
9677 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9678 IndexTypeQuals, BracketsRange,
9679 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009680
9681 QualType Types[] = {
9682 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9683 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9684 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009685 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009686 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009687 QualType SizeType;
9688 for (unsigned I = 0; I != NumTypes; ++I)
9689 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9690 SizeType = Types[I];
9691 break;
9692 }
Mike Stump11289f42009-09-09 15:08:12 +00009693
Eli Friedman9562f392012-01-25 23:20:27 +00009694 // Note that we can return a VariableArrayType here in the case where
9695 // the element type was a dependent VariableArrayType.
9696 IntegerLiteral *ArraySize
9697 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9698 /*FIXME*/BracketsRange.getBegin());
9699 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009700 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009701 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009702}
Mike Stump11289f42009-09-09 15:08:12 +00009703
Douglas Gregord6ff3322009-08-04 16:50:30 +00009704template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009705QualType
9706TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009707 ArrayType::ArraySizeModifier SizeMod,
9708 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009709 unsigned IndexTypeQuals,
9710 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009711 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009712 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009713}
9714
9715template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009716QualType
Mike Stump11289f42009-09-09 15:08:12 +00009717TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009718 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009719 unsigned IndexTypeQuals,
9720 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009721 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009722 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009723}
Mike Stump11289f42009-09-09 15:08:12 +00009724
Douglas Gregord6ff3322009-08-04 16:50:30 +00009725template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009726QualType
9727TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009728 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009729 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009730 unsigned IndexTypeQuals,
9731 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009732 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009733 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009734 IndexTypeQuals, BracketsRange);
9735}
9736
9737template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009738QualType
9739TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009740 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009741 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009742 unsigned IndexTypeQuals,
9743 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009744 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009745 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009746 IndexTypeQuals, BracketsRange);
9747}
9748
9749template<typename Derived>
9750QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009751 unsigned NumElements,
9752 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009753 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009754 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009755}
Mike Stump11289f42009-09-09 15:08:12 +00009756
Douglas Gregord6ff3322009-08-04 16:50:30 +00009757template<typename Derived>
9758QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9759 unsigned NumElements,
9760 SourceLocation AttributeLoc) {
9761 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9762 NumElements, true);
9763 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009764 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9765 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009766 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009767}
Mike Stump11289f42009-09-09 15:08:12 +00009768
Douglas Gregord6ff3322009-08-04 16:50:30 +00009769template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009770QualType
9771TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009772 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009773 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009774 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009775}
Mike Stump11289f42009-09-09 15:08:12 +00009776
Douglas Gregord6ff3322009-08-04 16:50:30 +00009777template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009778QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9779 QualType T,
9780 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009781 const FunctionProtoType::ExtProtoInfo &EPI) {
9782 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009783 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009784 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009785 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009786}
Mike Stump11289f42009-09-09 15:08:12 +00009787
Douglas Gregord6ff3322009-08-04 16:50:30 +00009788template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009789QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9790 return SemaRef.Context.getFunctionNoProtoType(T);
9791}
9792
9793template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009794QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9795 assert(D && "no decl found");
9796 if (D->isInvalidDecl()) return QualType();
9797
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009798 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009799 TypeDecl *Ty;
9800 if (isa<UsingDecl>(D)) {
9801 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009802 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009803 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9804
9805 // A valid resolved using typename decl points to exactly one type decl.
9806 assert(++Using->shadow_begin() == Using->shadow_end());
9807 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009808
John McCallb96ec562009-12-04 22:46:56 +00009809 } else {
9810 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9811 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9812 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9813 }
9814
9815 return SemaRef.Context.getTypeDeclType(Ty);
9816}
9817
9818template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009819QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9820 SourceLocation Loc) {
9821 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009822}
9823
9824template<typename Derived>
9825QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9826 return SemaRef.Context.getTypeOfType(Underlying);
9827}
9828
9829template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009830QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9831 SourceLocation Loc) {
9832 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009833}
9834
9835template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009836QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9837 UnaryTransformType::UTTKind UKind,
9838 SourceLocation Loc) {
9839 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9840}
9841
9842template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009843QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009844 TemplateName Template,
9845 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009846 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009847 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009848}
Mike Stump11289f42009-09-09 15:08:12 +00009849
Douglas Gregor1135c352009-08-06 05:28:30 +00009850template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009851QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9852 SourceLocation KWLoc) {
9853 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9854}
9855
9856template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009857TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009858TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009859 bool TemplateKW,
9860 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009861 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009862 Template);
9863}
9864
9865template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009866TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009867TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9868 const IdentifierInfo &Name,
9869 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009870 QualType ObjectType,
9871 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009872 UnqualifiedId TemplateName;
9873 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009874 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009875 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009876 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009877 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009878 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009879 /*EnteringContext=*/false,
9880 Template);
John McCall31f82722010-11-12 08:19:04 +00009881 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009882}
Mike Stump11289f42009-09-09 15:08:12 +00009883
Douglas Gregora16548e2009-08-11 05:31:07 +00009884template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009885TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009886TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009887 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009888 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009889 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009890 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009891 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009892 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009893 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009894 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009895 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009896 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009897 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009898 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009899 /*EnteringContext=*/false,
9900 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009901 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009902}
Chad Rosier1dcde962012-08-08 18:46:20 +00009903
Douglas Gregor71395fa2009-11-04 00:56:37 +00009904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009905ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009906TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9907 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009908 Expr *OrigCallee,
9909 Expr *First,
9910 Expr *Second) {
9911 Expr *Callee = OrigCallee->IgnoreParenCasts();
9912 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009913
Douglas Gregora16548e2009-08-11 05:31:07 +00009914 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009915 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009916 if (!First->getType()->isOverloadableType() &&
9917 !Second->getType()->isOverloadableType())
9918 return getSema().CreateBuiltinArraySubscriptExpr(First,
9919 Callee->getLocStart(),
9920 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009921 } else if (Op == OO_Arrow) {
9922 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009923 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9924 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009925 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009926 // The argument is not of overloadable type, so try to create a
9927 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009928 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009929 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009930
John McCallb268a282010-08-23 23:25:46 +00009931 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009932 }
9933 } else {
John McCallb268a282010-08-23 23:25:46 +00009934 if (!First->getType()->isOverloadableType() &&
9935 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009936 // Neither of the arguments is an overloadable type, so try to
9937 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009938 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009939 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009940 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009941 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009942 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009943
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009944 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009945 }
9946 }
Mike Stump11289f42009-09-09 15:08:12 +00009947
9948 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009949 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009950 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009951
John McCallb268a282010-08-23 23:25:46 +00009952 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009953 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009954 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009955 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009956 // If we've resolved this to a particular non-member function, just call
9957 // that function. If we resolved it to a member function,
9958 // CreateOverloaded* will find that function for us.
9959 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9960 if (!isa<CXXMethodDecl>(ND))
9961 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009962 }
Mike Stump11289f42009-09-09 15:08:12 +00009963
Douglas Gregora16548e2009-08-11 05:31:07 +00009964 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009965 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009966 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009967
Douglas Gregora16548e2009-08-11 05:31:07 +00009968 // Create the overloaded operator invocation for unary operators.
9969 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009970 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009971 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009972 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009973 }
Mike Stump11289f42009-09-09 15:08:12 +00009974
Douglas Gregore9d62932011-07-15 16:25:15 +00009975 if (Op == OO_Subscript) {
9976 SourceLocation LBrace;
9977 SourceLocation RBrace;
9978
9979 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9980 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9981 LBrace = SourceLocation::getFromRawEncoding(
9982 NameLoc.CXXOperatorName.BeginOpNameLoc);
9983 RBrace = SourceLocation::getFromRawEncoding(
9984 NameLoc.CXXOperatorName.EndOpNameLoc);
9985 } else {
9986 LBrace = Callee->getLocStart();
9987 RBrace = OpLoc;
9988 }
9989
9990 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9991 First, Second);
9992 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009993
Douglas Gregora16548e2009-08-11 05:31:07 +00009994 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009995 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009996 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009997 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9998 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010000
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010001 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010002}
Mike Stump11289f42009-09-09 15:08:12 +000010003
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010004template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010005ExprResult
John McCallb268a282010-08-23 23:25:46 +000010006TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010007 SourceLocation OperatorLoc,
10008 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010009 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010010 TypeSourceInfo *ScopeType,
10011 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010012 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010013 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010014 QualType BaseType = Base->getType();
10015 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010016 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010017 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010018 !BaseType->getAs<PointerType>()->getPointeeType()
10019 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010020 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010021 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010022 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010023 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010024 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010025 /*FIXME?*/true);
10026 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010027
Douglas Gregor678f90d2010-02-25 01:56:36 +000010028 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010029 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10030 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10031 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10032 NameInfo.setNamedTypeInfo(DestroyedType);
10033
Richard Smith8e4a3862012-05-15 06:15:11 +000010034 // The scope type is now known to be a valid nested name specifier
10035 // component. Tack it on to the end of the nested name specifier.
10036 if (ScopeType)
10037 SS.Extend(SemaRef.Context, SourceLocation(),
10038 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010039
Abramo Bagnara7945c982012-01-27 09:46:47 +000010040 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010041 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010042 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010043 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010044 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010045 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010046 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010047}
10048
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010049template<typename Derived>
10050StmtResult
10051TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010052 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010053 CapturedDecl *CD = S->getCapturedDecl();
10054 unsigned NumParams = CD->getNumParams();
10055 unsigned ContextParamPos = CD->getContextParamPosition();
10056 SmallVector<Sema::CapturedParamNameType, 4> Params;
10057 for (unsigned I = 0; I < NumParams; ++I) {
10058 if (I != ContextParamPos) {
10059 Params.push_back(
10060 std::make_pair(
10061 CD->getParam(I)->getName(),
10062 getDerived().TransformType(CD->getParam(I)->getType())));
10063 } else {
10064 Params.push_back(std::make_pair(StringRef(), QualType()));
10065 }
10066 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010067 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010068 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010069 StmtResult Body;
10070 {
10071 Sema::CompoundScopeRAII CompoundScope(getSema());
10072 Body = getDerived().TransformStmt(S->getCapturedStmt());
10073 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010074
10075 if (Body.isInvalid()) {
10076 getSema().ActOnCapturedRegionError();
10077 return StmtError();
10078 }
10079
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010080 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010081}
10082
Douglas Gregord6ff3322009-08-04 16:50:30 +000010083} // end namespace clang
10084
10085#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H