blob: eba23a5def8b3dc3e00dab987fb64385a6334419 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000609 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
852 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Craig Topperc3ec1492014-05-26 06:22:03 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Craig Topperc3ec1492014-05-26 06:22:03 +0000916 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001083 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001190 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001304 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001316 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev62c87d22014-03-21 04:51:18 +00001326 /// \brief Build a new OpenMP 'safelen' clause.
1327 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001328 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1331 SourceLocation LParenLoc,
1332 SourceLocation EndLoc) {
1333 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1334 }
1335
Alexander Musman8bd31e62014-05-27 15:12:19 +00001336 /// \brief Build a new OpenMP 'collapse' clause.
1337 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001338 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1341 SourceLocation LParenLoc,
1342 SourceLocation EndLoc) {
1343 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1344 EndLoc);
1345 }
1346
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001347 /// \brief Build a new OpenMP 'default' clause.
1348 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001349 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001350 /// Subclasses may override this routine to provide different behavior.
1351 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1352 SourceLocation KindKwLoc,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1357 StartLoc, LParenLoc, EndLoc);
1358 }
1359
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001360 /// \brief Build a new OpenMP 'proc_bind' clause.
1361 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001362 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001363 /// Subclasses may override this routine to provide different behavior.
1364 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1365 SourceLocation KindKwLoc,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1370 StartLoc, LParenLoc, EndLoc);
1371 }
1372
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 /// \brief Build a new OpenMP 'private' clause.
1374 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001375 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001385 /// \brief Build a new OpenMP 'firstprivate' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexander Musman1bb328c2014-06-04 13:06:39 +00001397 /// \brief Build a new OpenMP 'lastprivate' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001409 /// \brief Build a new OpenMP 'shared' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001412 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001413 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1414 SourceLocation StartLoc,
1415 SourceLocation LParenLoc,
1416 SourceLocation EndLoc) {
1417 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1418 EndLoc);
1419 }
1420
Alexander Musman8dba6642014-04-22 13:09:42 +00001421 /// \brief Build a new OpenMP 'linear' clause.
1422 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001423 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001424 /// Subclasses may override this routine to provide different behavior.
1425 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1426 SourceLocation StartLoc,
1427 SourceLocation LParenLoc,
1428 SourceLocation ColonLoc,
1429 SourceLocation EndLoc) {
1430 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1431 ColonLoc, EndLoc);
1432 }
1433
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001434 /// \brief Build a new OpenMP 'aligned' clause.
1435 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001436 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001437 /// Subclasses may override this routine to provide different behavior.
1438 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1439 SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 SourceLocation ColonLoc,
1442 SourceLocation EndLoc) {
1443 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1444 LParenLoc, ColonLoc, EndLoc);
1445 }
1446
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001447 /// \brief Build a new OpenMP 'copyin' clause.
1448 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001449 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001450 /// Subclasses may override this routine to provide different behavior.
1451 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1452 SourceLocation StartLoc,
1453 SourceLocation LParenLoc,
1454 SourceLocation EndLoc) {
1455 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1456 EndLoc);
1457 }
1458
James Dennett2a4d13c2012-06-15 07:13:21 +00001459 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001460 ///
1461 /// By default, performs semantic analysis to build the new statement.
1462 /// Subclasses may override this routine to provide different behavior.
1463 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1464 Expr *object) {
1465 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1466 }
1467
James Dennett2a4d13c2012-06-15 07:13:21 +00001468 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001469 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001473 Expr *Object, Stmt *Body) {
1474 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001475 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001476
James Dennett2a4d13c2012-06-15 07:13:21 +00001477 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1481 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1482 Stmt *Body) {
1483 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1484 }
John McCall53848232011-07-27 01:07:15 +00001485
Douglas Gregorf68a5082010-04-22 23:10:45 +00001486 /// \brief Build a new Objective-C fast enumeration statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001490 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001491 Stmt *Element,
1492 Expr *Collection,
1493 SourceLocation RParenLoc,
1494 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001495 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001496 Element,
John McCallb268a282010-08-23 23:25:46 +00001497 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001498 RParenLoc);
1499 if (ForEachStmt.isInvalid())
1500 return StmtError();
1501
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001502 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001504
Douglas Gregorebe10102009-08-20 07:17:43 +00001505 /// \brief Build a new C++ exception declaration.
1506 ///
1507 /// By default, performs semantic analysis to build the new decaration.
1508 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001509 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001510 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001511 SourceLocation StartLoc,
1512 SourceLocation IdLoc,
1513 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001514 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001515 StartLoc, IdLoc, Id);
1516 if (Var)
1517 getSema().CurContext->addDecl(Var);
1518 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001519 }
1520
1521 /// \brief Build a new C++ catch statement.
1522 ///
1523 /// By default, performs semantic analysis to build the new statement.
1524 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001525 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001526 VarDecl *ExceptionDecl,
1527 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001528 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1529 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001530 }
Mike Stump11289f42009-09-09 15:08:12 +00001531
Douglas Gregorebe10102009-08-20 07:17:43 +00001532 /// \brief Build a new C++ try statement.
1533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001536 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1537 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001538 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001539 }
Mike Stump11289f42009-09-09 15:08:12 +00001540
Richard Smith02e85f32011-04-14 22:09:26 +00001541 /// \brief Build a new C++0x range-based for statement.
1542 ///
1543 /// By default, performs semantic analysis to build the new statement.
1544 /// Subclasses may override this routine to provide different behavior.
1545 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1546 SourceLocation ColonLoc,
1547 Stmt *Range, Stmt *BeginEnd,
1548 Expr *Cond, Expr *Inc,
1549 Stmt *LoopVar,
1550 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001551 // If we've just learned that the range is actually an Objective-C
1552 // collection, treat this as an Objective-C fast enumeration loop.
1553 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1554 if (RangeStmt->isSingleDecl()) {
1555 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001556 if (RangeVar->isInvalidDecl())
1557 return StmtError();
1558
Douglas Gregorf7106af2013-04-08 18:40:13 +00001559 Expr *RangeExpr = RangeVar->getInit();
1560 if (!RangeExpr->isTypeDependent() &&
1561 RangeExpr->getType()->isObjCObjectPointerType())
1562 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1563 RParenLoc);
1564 }
1565 }
1566 }
1567
Richard Smith02e85f32011-04-14 22:09:26 +00001568 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001569 Cond, Inc, LoopVar, RParenLoc,
1570 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001571 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001572
1573 /// \brief Build a new C++0x range-based for statement.
1574 ///
1575 /// By default, performs semantic analysis to build the new statement.
1576 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001577 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001578 bool IsIfExists,
1579 NestedNameSpecifierLoc QualifierLoc,
1580 DeclarationNameInfo NameInfo,
1581 Stmt *Nested) {
1582 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1583 QualifierLoc, NameInfo, Nested);
1584 }
1585
Richard Smith02e85f32011-04-14 22:09:26 +00001586 /// \brief Attach body to a C++0x range-based for statement.
1587 ///
1588 /// By default, performs semantic analysis to finish the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
1590 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1591 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001593
David Majnemerfad8f482013-10-15 09:33:02 +00001594 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1595 Stmt *TryBlock, Stmt *Handler) {
1596 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001597 }
1598
David Majnemerfad8f482013-10-15 09:33:02 +00001599 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001600 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001601 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001602 }
1603
David Majnemerfad8f482013-10-15 09:33:02 +00001604 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1605 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001606 }
1607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new expression that references a declaration.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001613 LookupResult &R,
1614 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001615 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1616 }
1617
1618
1619 /// \brief Build a new expression that references a declaration.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001623 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001624 ValueDecl *VD,
1625 const DeclarationNameInfo &NameInfo,
1626 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001627 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001628 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001629
1630 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001631
1632 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001636 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001641 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 }
1643
Douglas Gregorad8a3362009-09-04 17:36:40 +00001644 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001645 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001648 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001649 SourceLocation OperatorLoc,
1650 bool isArrow,
1651 CXXScopeSpec &SS,
1652 TypeSourceInfo *ScopeType,
1653 SourceLocation CCLoc,
1654 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001655 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001658 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001661 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001662 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001664 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
Mike Stump11289f42009-09-09 15:08:12 +00001666
Douglas Gregor882211c2010-04-28 22:16:22 +00001667 /// \brief Build a new builtin offsetof expression.
1668 ///
1669 /// 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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001672 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001673 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001674 unsigned NumComponents,
1675 SourceLocation RParenLoc) {
1676 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1677 NumComponents, RParenLoc);
1678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001679
1680 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001681 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001682 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001685 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1686 SourceLocation OpLoc,
1687 UnaryExprOrTypeTrait ExprKind,
1688 SourceRange R) {
1689 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 }
1691
Peter Collingbournee190dee2011-03-11 19:24:49 +00001692 /// \brief Build a new sizeof, alignof or vec step expression with an
1693 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001694 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001697 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1698 UnaryExprOrTypeTrait ExprKind,
1699 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001701 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001704
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001705 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001709 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001716 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001717 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 RBracketLoc);
1719 }
1720
1721 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001722 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001727 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001728 Expr *ExecConfig = nullptr) {
1729 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001730 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 }
1732
1733 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001734 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001737 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001738 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001739 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001740 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001741 const DeclarationNameInfo &MemberNameInfo,
1742 ValueDecl *Member,
1743 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001744 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001745 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001746 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1747 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001748 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001749 // We have a reference to an unnamed field. This is always the
1750 // base of an anonymous struct/union member access, i.e. the
1751 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001752 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001753 assert(Member->getType()->isRecordType() &&
1754 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001755
Richard Smithcab9a7d2011-10-26 19:06:56 +00001756 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001757 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001758 QualifierLoc.getNestedNameSpecifier(),
1759 FoundDecl, Member);
1760 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001761 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001762 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001763 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001764 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001765 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001766 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001767 cast<FieldDecl>(Member)->getType(),
1768 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001769 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001772 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001773 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001774
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001775 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001776 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001777
John McCall16df1e52010-03-30 21:47:33 +00001778 // FIXME: this involves duplicating earlier analysis in a lot of
1779 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001780 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001781 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001782 R.resolveKind();
1783
John McCallb268a282010-08-23 23:25:46 +00001784 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001785 SS, TemplateKWLoc,
1786 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001787 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001791 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001795 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001796 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001797 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001801 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001805 SourceLocation QuestionLoc,
1806 Expr *LHS,
1807 SourceLocation ColonLoc,
1808 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001809 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1810 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 }
1812
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001820 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001821 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001822 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001830 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001832 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001833 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001834 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 }
Mike Stump11289f42009-09-09 15:08:12 +00001836
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001838 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 SourceLocation OpLoc,
1843 SourceLocation AccessorLoc,
1844 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001845
John McCall10eae182009-11-30 22:42:35 +00001846 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001847 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001848 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001849 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001850 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001851 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001852 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001853 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001857 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001861 MultiExprArg Inits,
1862 SourceLocation RBraceLoc,
1863 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001865 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001866 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001867 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001868
Douglas Gregord3d93062009-11-09 17:16:50 +00001869 // Patch in the result type we were given, which may have been computed
1870 // when the initial InitListExpr was built.
1871 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1872 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001873 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001877 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 MultiExprArg ArrayExprs,
1882 SourceLocation EqualOrColonLoc,
1883 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001884 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001887 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001890
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001891 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
Mike Stump11289f42009-09-09 15:08:12 +00001893
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001895 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// By default, builds the implicit value initialization without performing
1897 /// any semantic analysis. Subclasses may override this routine to provide
1898 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001900 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 }
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001908 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001909 SourceLocation RParenLoc) {
1910 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001911 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001912 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
1915 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001920 MultiExprArg SubExprs,
1921 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001922 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001926 ///
1927 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// rather than attempting to map the label statement itself.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001931 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001932 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 }
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001936 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001940 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001942 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 }
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 /// \brief Build a new __builtin_choose_expr expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001950 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 SourceLocation RParenLoc) {
1952 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001953 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Peter Collingbourne91147592011-04-15 00:35:48 +00001957 /// \brief Build a new generic selection expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
1961 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1962 SourceLocation DefaultLoc,
1963 SourceLocation RParenLoc,
1964 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001965 ArrayRef<TypeSourceInfo *> Types,
1966 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001967 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001968 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001969 }
1970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new overloaded operator call expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// The semantic analysis provides the behavior of template instantiation,
1975 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001976 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// argument-dependent lookup, etc. Subclasses may override this routine to
1978 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001981 Expr *Callee,
1982 Expr *First,
1983 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001984
1985 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// reinterpret_cast.
1987 ///
1988 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001989 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 Stmt::StmtClass Class,
1993 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001994 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 SourceLocation RAngleLoc,
1996 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001997 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation RParenLoc) {
1999 switch (Class) {
2000 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002001 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002002 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002003 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004
2005 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002006 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002007 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002008 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002011 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002012 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002017 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002018 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002019 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002022 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 }
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 /// \brief Build a new C++ static_cast expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002032 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation RAngleLoc,
2034 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002035 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002037 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002038 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002039 SourceRange(LAngleLoc, RAngleLoc),
2040 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 }
2042
2043 /// \brief Build a new C++ dynamic_cast expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002047 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002049 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RAngleLoc,
2051 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002054 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002055 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002056 SourceRange(LAngleLoc, RAngleLoc),
2057 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new C++ reinterpret_cast expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002066 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RAngleLoc,
2068 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002071 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002072 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002073 SourceRange(LAngleLoc, RAngleLoc),
2074 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 }
2076
2077 /// \brief Build a new C++ const_cast expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002083 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 SourceLocation RAngleLoc,
2085 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002086 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002088 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002089 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002090 SourceRange(LAngleLoc, RAngleLoc),
2091 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 /// \brief Build a new C++ functional-style cast expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002098 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2099 SourceLocation LParenLoc,
2100 Expr *Sub,
2101 SourceLocation RParenLoc) {
2102 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002103 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 RParenLoc);
2105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 /// \brief Build a new C++ typeid(type) expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002112 SourceLocation TypeidLoc,
2113 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002115 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002116 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Francois Pichet9f4f2072010-09-08 12:20:18 +00002119
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 /// \brief Build a new C++ typeid(expr) expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002124 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002125 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002126 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002128 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002129 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002130 }
2131
Francois Pichet9f4f2072010-09-08 12:20:18 +00002132 /// \brief Build a new C++ __uuidof(type) expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
2136 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2137 SourceLocation TypeidLoc,
2138 TypeSourceInfo *Operand,
2139 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002140 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002141 RParenLoc);
2142 }
2143
2144 /// \brief Build a new C++ __uuidof(expr) expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
2148 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2149 SourceLocation TypeidLoc,
2150 Expr *Operand,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2153 RParenLoc);
2154 }
2155
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 /// \brief Build a new C++ "this" expression.
2157 ///
2158 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002159 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002162 QualType ThisType,
2163 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002164 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002165 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 }
2167
2168 /// \brief Build a new C++ throw expression.
2169 ///
2170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002172 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2173 bool IsThrownVariableInScope) {
2174 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 }
2176
2177 /// \brief Build a new C++ default-argument expression.
2178 ///
2179 /// By default, builds a new default-argument expression, which does not
2180 /// require any semantic analysis. Subclasses may override this routine to
2181 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002182 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002183 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002184 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
2186
Richard Smith852c9db2013-04-20 22:23:05 +00002187 /// \brief Build a new C++11 default-initialization expression.
2188 ///
2189 /// By default, builds a new default field initialization expression, which
2190 /// does not require any semantic analysis. Subclasses may override this
2191 /// routine to provide different behavior.
2192 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2193 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002194 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002195 }
2196
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 /// \brief Build a new C++ zero-initialization expression.
2198 ///
2199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002201 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2202 SourceLocation LParenLoc,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002205 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 }
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 /// \brief Build a new C++ "new" expression.
2209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002212 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002213 bool UseGlobal,
2214 SourceLocation PlacementLParen,
2215 MultiExprArg PlacementArgs,
2216 SourceLocation PlacementRParen,
2217 SourceRange TypeIdParens,
2218 QualType AllocatedType,
2219 TypeSourceInfo *AllocatedTypeInfo,
2220 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002221 SourceRange DirectInitRange,
2222 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002223 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002225 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002227 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002228 AllocatedType,
2229 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002230 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002231 DirectInitRange,
2232 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// \brief Build a new C++ "delete" expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 bool IsGlobalDelete,
2241 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002242 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002244 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregor29c42f22012-02-24 07:38:34 +00002247 /// \brief Build a new type trait expression.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildTypeTrait(TypeTrait Trait,
2252 SourceLocation StartLoc,
2253 ArrayRef<TypeSourceInfo *> Args,
2254 SourceLocation RParenLoc) {
2255 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002257
John Wiegley6242b6a2011-04-28 00:16:57 +00002258 /// \brief Build a new array type trait expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
2262 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2263 SourceLocation StartLoc,
2264 TypeSourceInfo *TSInfo,
2265 Expr *DimExpr,
2266 SourceLocation RParenLoc) {
2267 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2268 }
2269
John Wiegleyf9f65842011-04-25 06:54:41 +00002270 /// \brief Build a new expression 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 RebuildExpressionTrait(ExpressionTrait Trait,
2275 SourceLocation StartLoc,
2276 Expr *Queried,
2277 SourceLocation RParenLoc) {
2278 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2279 }
2280
Mike Stump11289f42009-09-09 15:08:12 +00002281 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// expression.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002286 ExprResult RebuildDependentScopeDeclRefExpr(
2287 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002288 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002289 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002290 const TemplateArgumentListInfo *TemplateArgs,
2291 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002293 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002294
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002295 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002296 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002297 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002298
Richard Smithdb2630f2012-10-21 03:28:35 +00002299 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2300 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
2302
2303 /// \brief Build a new template-id expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002308 SourceLocation TemplateKWLoc,
2309 LookupResult &R,
2310 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002311 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002312 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2313 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 }
2315
2316 /// \brief Build a new object-construction expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002320 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002321 SourceLocation Loc,
2322 CXXConstructorDecl *Constructor,
2323 bool IsElidable,
2324 MultiExprArg Args,
2325 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002326 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002327 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002328 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002329 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002330 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002331 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002332 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002333 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002334
Douglas Gregordb121ba2009-12-14 16:27:04 +00002335 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002336 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002337 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002338 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002339 RequiresZeroInit, ConstructKind,
2340 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
2342
2343 /// \brief Build a new object-construction expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002347 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2348 SourceLocation LParenLoc,
2349 MultiExprArg Args,
2350 SourceLocation RParenLoc) {
2351 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002353 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 RParenLoc);
2355 }
2356
2357 /// \brief Build a new object-construction expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002361 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2362 SourceLocation LParenLoc,
2363 MultiExprArg Args,
2364 SourceLocation RParenLoc) {
2365 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002367 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 RParenLoc);
2369 }
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 /// \brief Build a new member reference expression.
2372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002375 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002376 QualType BaseType,
2377 bool IsArrow,
2378 SourceLocation OperatorLoc,
2379 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002380 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002381 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002382 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002383 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002385 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002386
John McCallb268a282010-08-23 23:25:46 +00002387 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002388 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002389 SS, TemplateKWLoc,
2390 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 MemberNameInfo,
2392 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 }
2394
John McCall10eae182009-11-30 22:42:35 +00002395 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002399 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2400 SourceLocation OperatorLoc,
2401 bool IsArrow,
2402 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002403 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002404 NamedDecl *FirstQualifierInScope,
2405 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002406 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002407 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002408 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002409
John McCallb268a282010-08-23 23:25:46 +00002410 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002411 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002412 SS, TemplateKWLoc,
2413 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002414 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002417 /// \brief Build a new noexcept expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
2421 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2422 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2423 }
2424
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002425 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002426 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2427 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002428 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002429 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002430 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002431 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2432 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002433 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002434
2435 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2436 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002437 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002438 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002439
Patrick Beard0caa3942012-04-19 00:25:12 +00002440 /// \brief Build a new Objective-C boxed expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
2444 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2445 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002447
Ted Kremeneke65b0862012-03-06 20:05:56 +00002448 /// \brief Build a new Objective-C array literal.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
2452 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2453 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002454 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002455 MultiExprArg(Elements, NumElements));
2456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002457
2458 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002459 Expr *Base, Expr *Key,
2460 ObjCMethodDecl *getterMethod,
2461 ObjCMethodDecl *setterMethod) {
2462 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2463 getterMethod, setterMethod);
2464 }
2465
2466 /// \brief Build a new Objective-C dictionary literal.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
2470 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2471 ObjCDictionaryElement *Elements,
2472 unsigned NumElements) {
2473 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002475
James Dennett2a4d13c2012-06-15 07:13:21 +00002476 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002481 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002482 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002483 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002484 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002488 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002489 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002490 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002491 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002492 MultiExprArg Args,
2493 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002494 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2495 ReceiverTypeInfo->getType(),
2496 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002497 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002498 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002499 }
2500
2501 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002502 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002503 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002504 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002505 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002506 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002507 MultiExprArg Args,
2508 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002509 return SemaRef.BuildInstanceMessage(Receiver,
2510 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002511 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002512 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002513 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002514 }
2515
Douglas Gregord51d90d2010-04-26 20:11:03 +00002516 /// \brief Build a new Objective-C ivar reference expression.
2517 ///
2518 /// By default, performs semantic analysis to build the new expression.
2519 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002520 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002521 SourceLocation IvarLoc,
2522 bool IsArrow, bool IsFreeIvar) {
2523 // FIXME: We lose track of the IsFreeIvar bit.
2524 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002525 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2526 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002527 /*FIXME:*/IvarLoc, IsArrow,
2528 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002529 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002530 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002531 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002532 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002533
2534 /// \brief Build a new Objective-C property reference expression.
2535 ///
2536 /// By default, performs semantic analysis to build the new expression.
2537 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002538 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002539 ObjCPropertyDecl *Property,
2540 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002541 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002542 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2543 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2544 /*FIXME:*/PropertyLoc,
2545 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002546 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002547 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002548 NameInfo,
2549 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002551
John McCallb7bd14f2010-12-02 01:19:52 +00002552 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002553 ///
2554 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002555 /// Subclasses may override this routine to provide different behavior.
2556 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2557 ObjCMethodDecl *Getter,
2558 ObjCMethodDecl *Setter,
2559 SourceLocation PropertyLoc) {
2560 // Since these expressions can only be value-dependent, we do not
2561 // need to perform semantic analysis again.
2562 return Owned(
2563 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2564 VK_LValue, OK_ObjCProperty,
2565 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002566 }
2567
Douglas Gregord51d90d2010-04-26 20:11:03 +00002568 /// \brief Build a new Objective-C "isa" expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002572 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002573 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002574 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002575 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2576 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002577 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002578 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002579 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002580 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002581 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002583
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 /// \brief Build a new shuffle vector expression.
2585 ///
2586 /// By default, performs semantic analysis to build the new expression.
2587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002588 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002589 MultiExprArg SubExprs,
2590 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002592 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002593 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2594 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2595 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002596 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002599 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002600 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2601 SemaRef.Context.BuiltinFnTy,
2602 VK_RValue, BuiltinLoc);
2603 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2604 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002605 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002606
2607 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002608 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002609 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002610 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002611
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002613 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 }
John McCall31f82722010-11-12 08:19:04 +00002615
Hal Finkelc4d7c822013-09-18 03:29:45 +00002616 /// \brief Build a new convert vector expression.
2617 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2618 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2619 SourceLocation RParenLoc) {
2620 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2621 BuiltinLoc, RParenLoc);
2622 }
2623
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002624 /// \brief Build a new template argument pack expansion.
2625 ///
2626 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002627 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002628 /// different behavior.
2629 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002630 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002631 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002632 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002633 case TemplateArgument::Expression: {
2634 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002635 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2636 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002637 if (Result.isInvalid())
2638 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002639
Douglas Gregor98318c22011-01-03 21:37:45 +00002640 return TemplateArgumentLoc(Result.get(), Result.get());
2641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002642
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002643 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002644 return TemplateArgumentLoc(TemplateArgument(
2645 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002646 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002647 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002648 Pattern.getTemplateNameLoc(),
2649 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002650
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002651 case TemplateArgument::Null:
2652 case TemplateArgument::Integral:
2653 case TemplateArgument::Declaration:
2654 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002655 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002656 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002657 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002659 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002660 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002661 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002662 EllipsisLoc,
2663 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002664 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2665 Expansion);
2666 break;
2667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002668
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002669 return TemplateArgumentLoc();
2670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002671
Douglas Gregor968f23a2011-01-03 19:31:53 +00002672 /// \brief Build a new expression pack expansion.
2673 ///
2674 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002675 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002676 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002677 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002678 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002679 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002680 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002681
2682 /// \brief Build a new atomic operation expression.
2683 ///
2684 /// By default, performs semantic analysis to build the new expression.
2685 /// Subclasses may override this routine to provide different behavior.
2686 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2687 MultiExprArg SubExprs,
2688 QualType RetTy,
2689 AtomicExpr::AtomicOp Op,
2690 SourceLocation RParenLoc) {
2691 // Just create the expression; there is not any interesting semantic
2692 // analysis here because we can't actually build an AtomicExpr until
2693 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002694 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002695 RParenLoc);
2696 }
2697
John McCall31f82722010-11-12 08:19:04 +00002698private:
Douglas Gregor14454802011-02-25 02:25:35 +00002699 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2700 QualType ObjectType,
2701 NamedDecl *FirstQualifierInScope,
2702 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002703
2704 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2705 QualType ObjectType,
2706 NamedDecl *FirstQualifierInScope,
2707 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002708
2709 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2710 NamedDecl *FirstQualifierInScope,
2711 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002712};
Douglas Gregora16548e2009-08-11 05:31:07 +00002713
Douglas Gregorebe10102009-08-20 07:17:43 +00002714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002715StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002716 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002717 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002718
Douglas Gregorebe10102009-08-20 07:17:43 +00002719 switch (S->getStmtClass()) {
2720 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregorebe10102009-08-20 07:17:43 +00002722 // Transform individual statement nodes
2723#define STMT(Node, Parent) \
2724 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002725#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002726#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002727#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002728
Douglas Gregorebe10102009-08-20 07:17:43 +00002729 // Transform expressions by calling TransformExpr.
2730#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002731#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002732#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002733#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002734 {
John McCalldadc5752010-08-24 06:29:42 +00002735 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002736 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002737 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002738
Richard Smith945f8d32013-01-14 22:39:08 +00002739 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002740 }
Mike Stump11289f42009-09-09 15:08:12 +00002741 }
2742
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002743 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002744}
Mike Stump11289f42009-09-09 15:08:12 +00002745
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002746template<typename Derived>
2747OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2748 if (!S)
2749 return S;
2750
2751 switch (S->getClauseKind()) {
2752 default: break;
2753 // Transform individual clause nodes
2754#define OPENMP_CLAUSE(Name, Class) \
2755 case OMPC_ ## Name : \
2756 return getDerived().Transform ## Class(cast<Class>(S));
2757#include "clang/Basic/OpenMPKinds.def"
2758 }
2759
2760 return S;
2761}
2762
Mike Stump11289f42009-09-09 15:08:12 +00002763
Douglas Gregore922c772009-08-04 22:27:00 +00002764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002765ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002766 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002767 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002768
2769 switch (E->getStmtClass()) {
2770 case Stmt::NoStmtClass: break;
2771#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002772#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002773#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002774 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002775#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002776 }
2777
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002778 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002779}
2780
2781template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002782ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2783 bool CXXDirectInit) {
2784 // Initializers are instantiated like expressions, except that various outer
2785 // layers are stripped.
2786 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002787 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002788
2789 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2790 Init = ExprTemp->getSubExpr();
2791
Richard Smithe6ca4752013-05-30 22:40:16 +00002792 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2793 Init = MTE->GetTemporaryExpr();
2794
Richard Smithd59b8322012-12-19 01:39:02 +00002795 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2796 Init = Binder->getSubExpr();
2797
2798 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2799 Init = ICE->getSubExprAsWritten();
2800
Richard Smithcc1b96d2013-06-12 22:31:48 +00002801 if (CXXStdInitializerListExpr *ILE =
2802 dyn_cast<CXXStdInitializerListExpr>(Init))
2803 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2804
Richard Smith38a549b2012-12-21 08:13:35 +00002805 // If this is not a direct-initializer, we only need to reconstruct
2806 // InitListExprs. Other forms of copy-initialization will be a no-op if
2807 // the initializer is already the right type.
2808 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2809 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2810 return getDerived().TransformExpr(Init);
2811
2812 // Revert value-initialization back to empty parens.
2813 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2814 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002815 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002816 Parens.getEnd());
2817 }
2818
2819 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2820 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002821 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002822 SourceLocation());
2823
2824 // Revert initialization by constructor back to a parenthesized or braced list
2825 // of expressions. Any other form of initializer can just be reused directly.
2826 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002827 return getDerived().TransformExpr(Init);
2828
2829 SmallVector<Expr*, 8> NewArgs;
2830 bool ArgChanged = false;
2831 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2832 /*IsCall*/true, NewArgs, &ArgChanged))
2833 return ExprError();
2834
2835 // If this was list initialization, revert to list form.
2836 if (Construct->isListInitialization())
2837 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2838 Construct->getLocEnd(),
2839 Construct->getType());
2840
Richard Smithd59b8322012-12-19 01:39:02 +00002841 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002842 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002843 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2844 Parens.getEnd());
2845}
2846
2847template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002848bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2849 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002850 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002851 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002852 bool *ArgChanged) {
2853 for (unsigned I = 0; I != NumInputs; ++I) {
2854 // If requested, drop call arguments that need to be dropped.
2855 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2856 if (ArgChanged)
2857 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
Douglas Gregora3efea12011-01-03 19:04:46 +00002859 break;
2860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002861
Douglas Gregor968f23a2011-01-03 19:31:53 +00002862 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2863 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002864
Chris Lattner01cf8db2011-07-20 06:58:45 +00002865 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2867 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Douglas Gregor968f23a2011-01-03 19:31:53 +00002869 // Determine whether the set of unexpanded parameter packs can and should
2870 // be expanded.
2871 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002872 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002873 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2874 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2876 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002877 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002878 Expand, RetainExpansion,
2879 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002880 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
Douglas Gregor968f23a2011-01-03 19:31:53 +00002882 if (!Expand) {
2883 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002884 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002885 // expansion.
2886 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2887 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2888 if (OutPattern.isInvalid())
2889 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
2891 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002892 Expansion->getEllipsisLoc(),
2893 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002894 if (Out.isInvalid())
2895 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002896
Douglas Gregor968f23a2011-01-03 19:31:53 +00002897 if (ArgChanged)
2898 *ArgChanged = true;
2899 Outputs.push_back(Out.get());
2900 continue;
2901 }
John McCall542e7c62011-07-06 07:30:07 +00002902
2903 // Record right away that the argument was changed. This needs
2904 // to happen even if the array expands to nothing.
2905 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002906
Douglas Gregor968f23a2011-01-03 19:31:53 +00002907 // The transform has determined that we should perform an elementwise
2908 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002909 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2911 ExprResult Out = getDerived().TransformExpr(Pattern);
2912 if (Out.isInvalid())
2913 return true;
2914
Richard Smith9467be42014-06-06 17:33:35 +00002915 // FIXME: Can this happen? We should not try to expand the pack
2916 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002917 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002918 Out = getDerived().RebuildPackExpansion(
2919 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002920 if (Out.isInvalid())
2921 return true;
2922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002923
Douglas Gregor968f23a2011-01-03 19:31:53 +00002924 Outputs.push_back(Out.get());
2925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Richard Smith9467be42014-06-06 17:33:35 +00002927 // If we're supposed to retain a pack expansion, do so by temporarily
2928 // forgetting the partially-substituted parameter pack.
2929 if (RetainExpansion) {
2930 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2931
2932 ExprResult Out = getDerived().TransformExpr(Pattern);
2933 if (Out.isInvalid())
2934 return true;
2935
2936 Out = getDerived().RebuildPackExpansion(
2937 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
2938 if (Out.isInvalid())
2939 return true;
2940
2941 Outputs.push_back(Out.get());
2942 }
2943
Douglas Gregor968f23a2011-01-03 19:31:53 +00002944 continue;
2945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Richard Smithd59b8322012-12-19 01:39:02 +00002947 ExprResult Result =
2948 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2949 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002950 if (Result.isInvalid())
2951 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002952
Douglas Gregora3efea12011-01-03 19:04:46 +00002953 if (Result.get() != Inputs[I] && ArgChanged)
2954 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002955
2956 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregora3efea12011-01-03 19:04:46 +00002959 return false;
2960}
2961
2962template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002963NestedNameSpecifierLoc
2964TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2965 NestedNameSpecifierLoc NNS,
2966 QualType ObjectType,
2967 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002968 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002969 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002970 Qualifier = Qualifier.getPrefix())
2971 Qualifiers.push_back(Qualifier);
2972
2973 CXXScopeSpec SS;
2974 while (!Qualifiers.empty()) {
2975 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2976 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
Douglas Gregor14454802011-02-25 02:25:35 +00002978 switch (QNNS->getKind()) {
2979 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002980 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002981 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002982 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002983 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002984 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002985 FirstQualifierInScope, false))
2986 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002987
Douglas Gregor14454802011-02-25 02:25:35 +00002988 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregor14454802011-02-25 02:25:35 +00002990 case NestedNameSpecifier::Namespace: {
2991 NamespaceDecl *NS
2992 = cast_or_null<NamespaceDecl>(
2993 getDerived().TransformDecl(
2994 Q.getLocalBeginLoc(),
2995 QNNS->getAsNamespace()));
2996 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2997 break;
2998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor14454802011-02-25 02:25:35 +00003000 case NestedNameSpecifier::NamespaceAlias: {
3001 NamespaceAliasDecl *Alias
3002 = cast_or_null<NamespaceAliasDecl>(
3003 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3004 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003005 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003006 Q.getLocalEndLoc());
3007 break;
3008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003009
Douglas Gregor14454802011-02-25 02:25:35 +00003010 case NestedNameSpecifier::Global:
3011 // There is no meaningful transformation that one could perform on the
3012 // global scope.
3013 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3014 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003015
Douglas Gregor14454802011-02-25 02:25:35 +00003016 case NestedNameSpecifier::TypeSpecWithTemplate:
3017 case NestedNameSpecifier::TypeSpec: {
3018 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3019 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003020
Douglas Gregor14454802011-02-25 02:25:35 +00003021 if (!TL)
3022 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor14454802011-02-25 02:25:35 +00003024 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003025 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003026 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003027 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003028 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003029 if (TL.getType()->isEnumeralType())
3030 SemaRef.Diag(TL.getBeginLoc(),
3031 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003032 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3033 Q.getLocalEndLoc());
3034 break;
3035 }
Richard Trieude756fb2011-05-07 01:36:37 +00003036 // If the nested-name-specifier is an invalid type def, don't emit an
3037 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003038 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3039 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003040 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003041 << TL.getType() << SS.getRange();
3042 }
Douglas Gregor14454802011-02-25 02:25:35 +00003043 return NestedNameSpecifierLoc();
3044 }
Douglas Gregore16af532011-02-28 18:50:33 +00003045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003046
Douglas Gregore16af532011-02-28 18:50:33 +00003047 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003048 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003049 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
Douglas Gregor14454802011-02-25 02:25:35 +00003052 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003053 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003054 !getDerived().AlwaysRebuild())
3055 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003056
3057 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003058 // nested-name-specifier, do so.
3059 if (SS.location_size() == NNS.getDataLength() &&
3060 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3061 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3062
3063 // Allocate new nested-name-specifier location information.
3064 return SS.getWithLocInContext(SemaRef.Context);
3065}
3066
3067template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003068DeclarationNameInfo
3069TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003070::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003071 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003072 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003073 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003074
3075 switch (Name.getNameKind()) {
3076 case DeclarationName::Identifier:
3077 case DeclarationName::ObjCZeroArgSelector:
3078 case DeclarationName::ObjCOneArgSelector:
3079 case DeclarationName::ObjCMultiArgSelector:
3080 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003081 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003082 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003083 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003084
Douglas Gregorf816bd72009-09-03 22:13:48 +00003085 case DeclarationName::CXXConstructorName:
3086 case DeclarationName::CXXDestructorName:
3087 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003088 TypeSourceInfo *NewTInfo;
3089 CanQualType NewCanTy;
3090 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003091 NewTInfo = getDerived().TransformType(OldTInfo);
3092 if (!NewTInfo)
3093 return DeclarationNameInfo();
3094 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003095 }
3096 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003097 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003098 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003099 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003100 if (NewT.isNull())
3101 return DeclarationNameInfo();
3102 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3103 }
Mike Stump11289f42009-09-09 15:08:12 +00003104
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003105 DeclarationName NewName
3106 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3107 NewCanTy);
3108 DeclarationNameInfo NewNameInfo(NameInfo);
3109 NewNameInfo.setName(NewName);
3110 NewNameInfo.setNamedTypeInfo(NewTInfo);
3111 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003112 }
Mike Stump11289f42009-09-09 15:08:12 +00003113 }
3114
David Blaikie83d382b2011-09-23 05:06:16 +00003115 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003116}
3117
3118template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003119TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003120TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3121 TemplateName Name,
3122 SourceLocation NameLoc,
3123 QualType ObjectType,
3124 NamedDecl *FirstQualifierInScope) {
3125 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3126 TemplateDecl *Template = QTN->getTemplateDecl();
3127 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003128
Douglas Gregor9db53502011-03-02 18:07:45 +00003129 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003130 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003131 Template));
3132 if (!TransTemplate)
3133 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 if (!getDerived().AlwaysRebuild() &&
3136 SS.getScopeRep() == QTN->getQualifier() &&
3137 TransTemplate == Template)
3138 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003139
Douglas Gregor9db53502011-03-02 18:07:45 +00003140 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3141 TransTemplate);
3142 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Douglas Gregor9db53502011-03-02 18:07:45 +00003144 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3145 if (SS.getScopeRep()) {
3146 // These apply to the scope specifier, not the template.
3147 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003148 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003149 }
3150
Douglas Gregor9db53502011-03-02 18:07:45 +00003151 if (!getDerived().AlwaysRebuild() &&
3152 SS.getScopeRep() == DTN->getQualifier() &&
3153 ObjectType.isNull())
3154 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003155
Douglas Gregor9db53502011-03-02 18:07:45 +00003156 if (DTN->isIdentifier()) {
3157 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003158 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 NameLoc,
3160 ObjectType,
3161 FirstQualifierInScope);
3162 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor9db53502011-03-02 18:07:45 +00003164 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3165 ObjectType);
3166 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003167
Douglas Gregor9db53502011-03-02 18:07:45 +00003168 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3169 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003170 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003171 Template));
3172 if (!TransTemplate)
3173 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003174
Douglas Gregor9db53502011-03-02 18:07:45 +00003175 if (!getDerived().AlwaysRebuild() &&
3176 TransTemplate == Template)
3177 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Douglas Gregor9db53502011-03-02 18:07:45 +00003179 return TemplateName(TransTemplate);
3180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003181
Douglas Gregor9db53502011-03-02 18:07:45 +00003182 if (SubstTemplateTemplateParmPackStorage *SubstPack
3183 = Name.getAsSubstTemplateTemplateParmPack()) {
3184 TemplateTemplateParmDecl *TransParam
3185 = cast_or_null<TemplateTemplateParmDecl>(
3186 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3187 if (!TransParam)
3188 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003189
Douglas Gregor9db53502011-03-02 18:07:45 +00003190 if (!getDerived().AlwaysRebuild() &&
3191 TransParam == SubstPack->getParameterPack())
3192 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003193
3194 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003195 SubstPack->getArgumentPack());
3196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor9db53502011-03-02 18:07:45 +00003198 // These should be getting filtered out before they reach the AST.
3199 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003200}
3201
3202template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003203void TreeTransform<Derived>::InventTemplateArgumentLoc(
3204 const TemplateArgument &Arg,
3205 TemplateArgumentLoc &Output) {
3206 SourceLocation Loc = getDerived().getBaseLocation();
3207 switch (Arg.getKind()) {
3208 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003209 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003210 break;
3211
3212 case TemplateArgument::Type:
3213 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003214 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003215
John McCall0ad16662009-10-29 08:12:44 +00003216 break;
3217
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003218 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003219 case TemplateArgument::TemplateExpansion: {
3220 NestedNameSpecifierLocBuilder Builder;
3221 TemplateName Template = Arg.getAsTemplate();
3222 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3223 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3224 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3225 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor9d802122011-03-02 17:09:35 +00003227 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003228 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003229 Builder.getWithLocInContext(SemaRef.Context),
3230 Loc);
3231 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003232 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003233 Builder.getWithLocInContext(SemaRef.Context),
3234 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003235
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003236 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003237 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003238
John McCall0ad16662009-10-29 08:12:44 +00003239 case TemplateArgument::Expression:
3240 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3241 break;
3242
3243 case TemplateArgument::Declaration:
3244 case TemplateArgument::Integral:
3245 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003246 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003247 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003248 break;
3249 }
3250}
3251
3252template<typename Derived>
3253bool TreeTransform<Derived>::TransformTemplateArgument(
3254 const TemplateArgumentLoc &Input,
3255 TemplateArgumentLoc &Output) {
3256 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003257 switch (Arg.getKind()) {
3258 case TemplateArgument::Null:
3259 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003260 case TemplateArgument::Pack:
3261 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003262 case TemplateArgument::NullPtr:
3263 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003264
Douglas Gregore922c772009-08-04 22:27:00 +00003265 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003266 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003267 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003268 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003269
3270 DI = getDerived().TransformType(DI);
3271 if (!DI) return true;
3272
3273 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3274 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003275 }
Mike Stump11289f42009-09-09 15:08:12 +00003276
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003277 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003278 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3279 if (QualifierLoc) {
3280 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3281 if (!QualifierLoc)
3282 return true;
3283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregordf846d12011-03-02 18:46:51 +00003285 CXXScopeSpec SS;
3286 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003287 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003288 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3289 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003290 if (Template.isNull())
3291 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregor9d802122011-03-02 17:09:35 +00003293 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003294 Input.getTemplateNameLoc());
3295 return false;
3296 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003297
3298 case TemplateArgument::TemplateExpansion:
3299 llvm_unreachable("Caller should expand pack expansions");
3300
Douglas Gregore922c772009-08-04 22:27:00 +00003301 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003302 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003303 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003304 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003305
John McCall0ad16662009-10-29 08:12:44 +00003306 Expr *InputExpr = Input.getSourceExpression();
3307 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3308
Chris Lattnercdb591a2011-04-25 20:37:58 +00003309 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003310 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003311 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003312 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003314 }
Douglas Gregore922c772009-08-04 22:27:00 +00003315 }
Mike Stump11289f42009-09-09 15:08:12 +00003316
Douglas Gregore922c772009-08-04 22:27:00 +00003317 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003318 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003319}
3320
Douglas Gregorfe921a72010-12-20 23:36:19 +00003321/// \brief Iterator adaptor that invents template argument location information
3322/// for each of the template arguments in its underlying iterator.
3323template<typename Derived, typename InputIterator>
3324class TemplateArgumentLocInventIterator {
3325 TreeTransform<Derived> &Self;
3326 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregorfe921a72010-12-20 23:36:19 +00003328public:
3329 typedef TemplateArgumentLoc value_type;
3330 typedef TemplateArgumentLoc reference;
3331 typedef typename std::iterator_traits<InputIterator>::difference_type
3332 difference_type;
3333 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003334
Douglas Gregorfe921a72010-12-20 23:36:19 +00003335 class pointer {
3336 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003337
Douglas Gregorfe921a72010-12-20 23:36:19 +00003338 public:
3339 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregorfe921a72010-12-20 23:36:19 +00003341 const TemplateArgumentLoc *operator->() const { return &Arg; }
3342 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregorfe921a72010-12-20 23:36:19 +00003344 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregorfe921a72010-12-20 23:36:19 +00003346 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3347 InputIterator Iter)
3348 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregorfe921a72010-12-20 23:36:19 +00003350 TemplateArgumentLocInventIterator &operator++() {
3351 ++Iter;
3352 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003354
Douglas Gregorfe921a72010-12-20 23:36:19 +00003355 TemplateArgumentLocInventIterator operator++(int) {
3356 TemplateArgumentLocInventIterator Old(*this);
3357 ++(*this);
3358 return Old;
3359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregorfe921a72010-12-20 23:36:19 +00003361 reference operator*() const {
3362 TemplateArgumentLoc Result;
3363 Self.InventTemplateArgumentLoc(*Iter, Result);
3364 return Result;
3365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003366
Douglas Gregorfe921a72010-12-20 23:36:19 +00003367 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregorfe921a72010-12-20 23:36:19 +00003369 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3370 const TemplateArgumentLocInventIterator &Y) {
3371 return X.Iter == Y.Iter;
3372 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003373
Douglas Gregorfe921a72010-12-20 23:36:19 +00003374 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3375 const TemplateArgumentLocInventIterator &Y) {
3376 return X.Iter != Y.Iter;
3377 }
3378};
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor42cafa82010-12-20 17:42:22 +00003380template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003381template<typename InputIterator>
3382bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3383 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003384 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003385 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003386 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003387 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3390 // Unpack argument packs, which we translate them into separate
3391 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003392 // FIXME: We could do much better if we could guarantee that the
3393 // TemplateArgumentLocInfo for the pack expansion would be usable for
3394 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003395 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003396 TemplateArgument::pack_iterator>
3397 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003398 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003399 In.getArgument().pack_begin()),
3400 PackLocIterator(*this,
3401 In.getArgument().pack_end()),
3402 Outputs))
3403 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003405 continue;
3406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003408 if (In.getArgument().isPackExpansion()) {
3409 // We have a pack expansion, for which we will be substituting into
3410 // the pattern.
3411 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003412 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003413 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003414 = getSema().getTemplateArgumentPackExpansionPattern(
3415 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Chris Lattner01cf8db2011-07-20 06:58:45 +00003417 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003418 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3419 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 // Determine whether the set of unexpanded parameter packs can and should
3422 // be expanded.
3423 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003424 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003425 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003426 if (getDerived().TryExpandParameterPacks(Ellipsis,
3427 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003428 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003429 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003430 RetainExpansion,
3431 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003432 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003434 if (!Expand) {
3435 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003436 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003437 // expansion.
3438 TemplateArgumentLoc OutPattern;
3439 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3440 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3441 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003443 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3444 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003445 if (Out.getArgument().isNull())
3446 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003448 Outputs.addArgument(Out);
3449 continue;
3450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003452 // The transform has determined that we should perform an elementwise
3453 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003454 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003455 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3456
3457 if (getDerived().TransformTemplateArgument(Pattern, Out))
3458 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003460 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003461 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3462 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003463 if (Out.getArgument().isNull())
3464 return true;
3465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003467 Outputs.addArgument(Out);
3468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor48d24112011-01-10 20:53:55 +00003470 // If we're supposed to retain a pack expansion, do so by temporarily
3471 // forgetting the partially-substituted parameter pack.
3472 if (RetainExpansion) {
3473 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Douglas Gregor48d24112011-01-10 20:53:55 +00003475 if (getDerived().TransformTemplateArgument(Pattern, Out))
3476 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003478 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3479 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003480 if (Out.getArgument().isNull())
3481 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
Douglas Gregor48d24112011-01-10 20:53:55 +00003483 Outputs.addArgument(Out);
3484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003486 continue;
3487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003488
3489 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003490 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003491 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregor42cafa82010-12-20 17:42:22 +00003493 Outputs.addArgument(Out);
3494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregor42cafa82010-12-20 17:42:22 +00003496 return false;
3497
3498}
3499
Douglas Gregord6ff3322009-08-04 16:50:30 +00003500//===----------------------------------------------------------------------===//
3501// Type transformation
3502//===----------------------------------------------------------------------===//
3503
3504template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003505QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003506 if (getDerived().AlreadyTransformed(T))
3507 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003508
John McCall550e0c22009-10-21 00:40:46 +00003509 // Temporary workaround. All of these transformations should
3510 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003511 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3512 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
John McCall31f82722010-11-12 08:19:04 +00003514 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003515
John McCall550e0c22009-10-21 00:40:46 +00003516 if (!NewDI)
3517 return QualType();
3518
3519 return NewDI->getType();
3520}
3521
3522template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003523TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003524 // Refine the base location to the type's location.
3525 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3526 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003527 if (getDerived().AlreadyTransformed(DI->getType()))
3528 return DI;
3529
3530 TypeLocBuilder TLB;
3531
3532 TypeLoc TL = DI->getTypeLoc();
3533 TLB.reserve(TL.getFullDataSize());
3534
John McCall31f82722010-11-12 08:19:04 +00003535 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003536 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003537 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003538
John McCallbcd03502009-12-07 02:54:59 +00003539 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003540}
3541
3542template<typename Derived>
3543QualType
John McCall31f82722010-11-12 08:19:04 +00003544TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003545 switch (T.getTypeLocClass()) {
3546#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003547#define TYPELOC(CLASS, PARENT) \
3548 case TypeLoc::CLASS: \
3549 return getDerived().Transform##CLASS##Type(TLB, \
3550 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003551#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003552 }
Mike Stump11289f42009-09-09 15:08:12 +00003553
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003554 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003555}
3556
3557/// FIXME: By default, this routine adds type qualifiers only to types
3558/// that can have qualifiers, and silently suppresses those qualifiers
3559/// that are not permitted (e.g., qualifiers on reference or function
3560/// types). This is the right thing for template instantiation, but
3561/// probably not for other clients.
3562template<typename Derived>
3563QualType
3564TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003565 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003566 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003567
John McCall31f82722010-11-12 08:19:04 +00003568 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003569 if (Result.isNull())
3570 return QualType();
3571
3572 // Silently suppress qualifiers if the result type can't be qualified.
3573 // FIXME: this is the right thing for template instantiation, but
3574 // probably not for other clients.
3575 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003577
John McCall31168b02011-06-15 23:02:42 +00003578 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003579 // resulting type.
3580 if (Quals.hasObjCLifetime()) {
3581 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3582 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003583 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003584 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003585 // A lifetime qualifier applied to a substituted template parameter
3586 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003587 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003589 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3590 QualType Replacement = SubstTypeParam->getReplacementType();
3591 Qualifiers Qs = Replacement.getQualifiers();
3592 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003593 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003594 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3595 Qs);
3596 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003597 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003598 Replacement);
3599 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003600 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3601 // 'auto' types behave the same way as template parameters.
3602 QualType Deduced = AutoTy->getDeducedType();
3603 Qualifiers Qs = Deduced.getQualifiers();
3604 Qs.removeObjCLifetime();
3605 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3606 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003607 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3608 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003609 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003610 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003611 // Otherwise, complain about the addition of a qualifier to an
3612 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003613 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003614 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003615 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
Douglas Gregore46db902011-06-17 22:11:49 +00003617 Quals.removeObjCLifetime();
3618 }
3619 }
3620 }
John McCallcb0f89a2010-06-05 06:41:15 +00003621 if (!Quals.empty()) {
3622 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003623 // BuildQualifiedType might not add qualifiers if they are invalid.
3624 if (Result.hasLocalQualifiers())
3625 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003626 // No location information to preserve.
3627 }
John McCall550e0c22009-10-21 00:40:46 +00003628
3629 return Result;
3630}
3631
Douglas Gregor14454802011-02-25 02:25:35 +00003632template<typename Derived>
3633TypeLoc
3634TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3635 QualType ObjectType,
3636 NamedDecl *UnqualLookup,
3637 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003638 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003639 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003641 TypeSourceInfo *TSI =
3642 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3643 if (TSI)
3644 return TSI->getTypeLoc();
3645 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003646}
3647
Douglas Gregor579c15f2011-03-02 18:32:08 +00003648template<typename Derived>
3649TypeSourceInfo *
3650TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3651 QualType ObjectType,
3652 NamedDecl *UnqualLookup,
3653 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003654 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003655 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003656
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003657 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3658 UnqualLookup, SS);
3659}
3660
3661template <typename Derived>
3662TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3663 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3664 CXXScopeSpec &SS) {
3665 QualType T = TL.getType();
3666 assert(!getDerived().AlreadyTransformed(T));
3667
Douglas Gregor579c15f2011-03-02 18:32:08 +00003668 TypeLocBuilder TLB;
3669 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor579c15f2011-03-02 18:32:08 +00003671 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003672 TemplateSpecializationTypeLoc SpecTL =
3673 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
Douglas Gregor579c15f2011-03-02 18:32:08 +00003675 TemplateName Template
3676 = getDerived().TransformTemplateName(SS,
3677 SpecTL.getTypePtr()->getTemplateName(),
3678 SpecTL.getTemplateNameLoc(),
3679 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003680 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003681 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003682
3683 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003684 Template);
3685 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003686 DependentTemplateSpecializationTypeLoc SpecTL =
3687 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor579c15f2011-03-02 18:32:08 +00003689 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003690 = getDerived().RebuildTemplateName(SS,
3691 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003692 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003693 ObjectType, UnqualLookup);
3694 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003695 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
3697 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003698 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003699 Template,
3700 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003701 } else {
3702 // Nothing special needs to be done for these.
3703 Result = getDerived().TransformType(TLB, TL);
3704 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
3706 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003707 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003708
Douglas Gregor579c15f2011-03-02 18:32:08 +00003709 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3710}
3711
John McCall550e0c22009-10-21 00:40:46 +00003712template <class TyLoc> static inline
3713QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3714 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3715 NewT.setNameLoc(T.getNameLoc());
3716 return T.getType();
3717}
3718
John McCall550e0c22009-10-21 00:40:46 +00003719template<typename Derived>
3720QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003721 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003722 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3723 NewT.setBuiltinLoc(T.getBuiltinLoc());
3724 if (T.needsExtraLocalData())
3725 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3726 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727}
Mike Stump11289f42009-09-09 15:08:12 +00003728
Douglas Gregord6ff3322009-08-04 16:50:30 +00003729template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003730QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003731 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003732 // FIXME: recurse?
3733 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003734}
Mike Stump11289f42009-09-09 15:08:12 +00003735
Reid Kleckner0503a872013-12-05 01:23:43 +00003736template <typename Derived>
3737QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3738 AdjustedTypeLoc TL) {
3739 // Adjustments applied during transformation are handled elsewhere.
3740 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3741}
3742
Douglas Gregord6ff3322009-08-04 16:50:30 +00003743template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003744QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3745 DecayedTypeLoc TL) {
3746 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3747 if (OriginalType.isNull())
3748 return QualType();
3749
3750 QualType Result = TL.getType();
3751 if (getDerived().AlwaysRebuild() ||
3752 OriginalType != TL.getOriginalLoc().getType())
3753 Result = SemaRef.Context.getDecayedType(OriginalType);
3754 TLB.push<DecayedTypeLoc>(Result);
3755 // Nothing to set for DecayedTypeLoc.
3756 return Result;
3757}
3758
3759template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003760QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003761 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003762 QualType PointeeType
3763 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003764 if (PointeeType.isNull())
3765 return QualType();
3766
3767 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003768 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003769 // A dependent pointer type 'T *' has is being transformed such
3770 // that an Objective-C class type is being replaced for 'T'. The
3771 // resulting pointer type is an ObjCObjectPointerType, not a
3772 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003773 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
John McCall8b07ec22010-05-15 11:32:37 +00003775 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3776 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003777 return Result;
3778 }
John McCall31f82722010-11-12 08:19:04 +00003779
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003780 if (getDerived().AlwaysRebuild() ||
3781 PointeeType != TL.getPointeeLoc().getType()) {
3782 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3783 if (Result.isNull())
3784 return QualType();
3785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
John McCall31168b02011-06-15 23:02:42 +00003787 // Objective-C ARC can add lifetime qualifiers to the type that we're
3788 // pointing to.
3789 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003790
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003791 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3792 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003793 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003794}
Mike Stump11289f42009-09-09 15:08:12 +00003795
3796template<typename Derived>
3797QualType
John McCall550e0c22009-10-21 00:40:46 +00003798TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003799 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003800 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003801 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3802 if (PointeeType.isNull())
3803 return QualType();
3804
3805 QualType Result = TL.getType();
3806 if (getDerived().AlwaysRebuild() ||
3807 PointeeType != TL.getPointeeLoc().getType()) {
3808 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003809 TL.getSigilLoc());
3810 if (Result.isNull())
3811 return QualType();
3812 }
3813
Douglas Gregor049211a2010-04-22 16:50:51 +00003814 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003815 NewT.setSigilLoc(TL.getSigilLoc());
3816 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003817}
3818
John McCall70dd5f62009-10-30 00:06:24 +00003819/// Transforms a reference type. Note that somewhat paradoxically we
3820/// don't care whether the type itself is an l-value type or an r-value
3821/// type; we only care if the type was *written* as an l-value type
3822/// or an r-value type.
3823template<typename Derived>
3824QualType
3825TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003826 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003827 const ReferenceType *T = TL.getTypePtr();
3828
3829 // Note that this works with the pointee-as-written.
3830 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3831 if (PointeeType.isNull())
3832 return QualType();
3833
3834 QualType Result = TL.getType();
3835 if (getDerived().AlwaysRebuild() ||
3836 PointeeType != T->getPointeeTypeAsWritten()) {
3837 Result = getDerived().RebuildReferenceType(PointeeType,
3838 T->isSpelledAsLValue(),
3839 TL.getSigilLoc());
3840 if (Result.isNull())
3841 return QualType();
3842 }
3843
John McCall31168b02011-06-15 23:02:42 +00003844 // Objective-C ARC can add lifetime qualifiers to the type that we're
3845 // referring to.
3846 TLB.TypeWasModifiedSafely(
3847 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3848
John McCall70dd5f62009-10-30 00:06:24 +00003849 // r-value references can be rebuilt as l-value references.
3850 ReferenceTypeLoc NewTL;
3851 if (isa<LValueReferenceType>(Result))
3852 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3853 else
3854 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3855 NewTL.setSigilLoc(TL.getSigilLoc());
3856
3857 return Result;
3858}
3859
Mike Stump11289f42009-09-09 15:08:12 +00003860template<typename Derived>
3861QualType
John McCall550e0c22009-10-21 00:40:46 +00003862TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003863 LValueReferenceTypeLoc TL) {
3864 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003865}
3866
Mike Stump11289f42009-09-09 15:08:12 +00003867template<typename Derived>
3868QualType
John McCall550e0c22009-10-21 00:40:46 +00003869TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003870 RValueReferenceTypeLoc TL) {
3871 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003872}
Mike Stump11289f42009-09-09 15:08:12 +00003873
Douglas Gregord6ff3322009-08-04 16:50:30 +00003874template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003875QualType
John McCall550e0c22009-10-21 00:40:46 +00003876TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003877 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003878 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879 if (PointeeType.isNull())
3880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003881
Abramo Bagnara509357842011-03-05 14:42:21 +00003882 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003883 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003884 if (OldClsTInfo) {
3885 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3886 if (!NewClsTInfo)
3887 return QualType();
3888 }
3889
3890 const MemberPointerType *T = TL.getTypePtr();
3891 QualType OldClsType = QualType(T->getClass(), 0);
3892 QualType NewClsType;
3893 if (NewClsTInfo)
3894 NewClsType = NewClsTInfo->getType();
3895 else {
3896 NewClsType = getDerived().TransformType(OldClsType);
3897 if (NewClsType.isNull())
3898 return QualType();
3899 }
Mike Stump11289f42009-09-09 15:08:12 +00003900
John McCall550e0c22009-10-21 00:40:46 +00003901 QualType Result = TL.getType();
3902 if (getDerived().AlwaysRebuild() ||
3903 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003904 NewClsType != OldClsType) {
3905 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003906 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003907 if (Result.isNull())
3908 return QualType();
3909 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003910
Reid Kleckner0503a872013-12-05 01:23:43 +00003911 // If we had to adjust the pointee type when building a member pointer, make
3912 // sure to push TypeLoc info for it.
3913 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3914 if (MPT && PointeeType != MPT->getPointeeType()) {
3915 assert(isa<AdjustedType>(MPT->getPointeeType()));
3916 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3917 }
3918
John McCall550e0c22009-10-21 00:40:46 +00003919 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3920 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003921 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003922
3923 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003924}
3925
Mike Stump11289f42009-09-09 15:08:12 +00003926template<typename Derived>
3927QualType
John McCall550e0c22009-10-21 00:40:46 +00003928TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003929 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003930 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003931 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003932 if (ElementType.isNull())
3933 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003934
John McCall550e0c22009-10-21 00:40:46 +00003935 QualType Result = TL.getType();
3936 if (getDerived().AlwaysRebuild() ||
3937 ElementType != T->getElementType()) {
3938 Result = getDerived().RebuildConstantArrayType(ElementType,
3939 T->getSizeModifier(),
3940 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003941 T->getIndexTypeCVRQualifiers(),
3942 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003943 if (Result.isNull())
3944 return QualType();
3945 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003946
3947 // We might have either a ConstantArrayType or a VariableArrayType now:
3948 // a ConstantArrayType is allowed to have an element type which is a
3949 // VariableArrayType if the type is dependent. Fortunately, all array
3950 // types have the same location layout.
3951 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003952 NewTL.setLBracketLoc(TL.getLBracketLoc());
3953 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003954
John McCall550e0c22009-10-21 00:40:46 +00003955 Expr *Size = TL.getSizeExpr();
3956 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003957 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3958 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003959 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3960 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003961 }
3962 NewTL.setSizeExpr(Size);
3963
3964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregord6ff3322009-08-04 16:50:30 +00003967template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003969 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003970 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003971 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003972 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003973 if (ElementType.isNull())
3974 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003975
John McCall550e0c22009-10-21 00:40:46 +00003976 QualType Result = TL.getType();
3977 if (getDerived().AlwaysRebuild() ||
3978 ElementType != T->getElementType()) {
3979 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003980 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003981 T->getIndexTypeCVRQualifiers(),
3982 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003983 if (Result.isNull())
3984 return QualType();
3985 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003986
John McCall550e0c22009-10-21 00:40:46 +00003987 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3988 NewTL.setLBracketLoc(TL.getLBracketLoc());
3989 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003990 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003991
3992 return Result;
3993}
3994
3995template<typename Derived>
3996QualType
3997TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003998 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003999 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004000 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4001 if (ElementType.isNull())
4002 return QualType();
4003
John McCalldadc5752010-08-24 06:29:42 +00004004 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004005 = getDerived().TransformExpr(T->getSizeExpr());
4006 if (SizeResult.isInvalid())
4007 return QualType();
4008
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004009 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004010
4011 QualType Result = TL.getType();
4012 if (getDerived().AlwaysRebuild() ||
4013 ElementType != T->getElementType() ||
4014 Size != T->getSizeExpr()) {
4015 Result = getDerived().RebuildVariableArrayType(ElementType,
4016 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004017 Size,
John McCall550e0c22009-10-21 00:40:46 +00004018 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004019 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004020 if (Result.isNull())
4021 return QualType();
4022 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004023
Serge Pavlov774c6d02014-02-06 03:49:11 +00004024 // We might have constant size array now, but fortunately it has the same
4025 // location layout.
4026 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004027 NewTL.setLBracketLoc(TL.getLBracketLoc());
4028 NewTL.setRBracketLoc(TL.getRBracketLoc());
4029 NewTL.setSizeExpr(Size);
4030
4031 return Result;
4032}
4033
4034template<typename Derived>
4035QualType
4036TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004037 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004038 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4040 if (ElementType.isNull())
4041 return QualType();
4042
Richard Smith764d2fe2011-12-20 02:08:33 +00004043 // Array bounds are constant expressions.
4044 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4045 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004046
John McCall33ddac02011-01-19 10:06:00 +00004047 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4048 Expr *origSize = TL.getSizeExpr();
4049 if (!origSize) origSize = T->getSizeExpr();
4050
4051 ExprResult sizeResult
4052 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004053 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004054 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004055 return QualType();
4056
John McCall33ddac02011-01-19 10:06:00 +00004057 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004058
4059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004062 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004063 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4064 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004065 size,
John McCall550e0c22009-10-21 00:40:46 +00004066 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004067 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004068 if (Result.isNull())
4069 return QualType();
4070 }
John McCall550e0c22009-10-21 00:40:46 +00004071
4072 // We might have any sort of array type now, but fortunately they
4073 // all have the same location layout.
4074 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4075 NewTL.setLBracketLoc(TL.getLBracketLoc());
4076 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004077 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004078
4079 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080}
Mike Stump11289f42009-09-09 15:08:12 +00004081
4082template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004084 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004086 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004087
4088 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089 QualType ElementType = getDerived().TransformType(T->getElementType());
4090 if (ElementType.isNull())
4091 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004092
Richard Smith764d2fe2011-12-20 02:08:33 +00004093 // Vector sizes are constant expressions.
4094 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4095 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004096
John McCalldadc5752010-08-24 06:29:42 +00004097 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004098 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099 if (Size.isInvalid())
4100 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004101
John McCall550e0c22009-10-21 00:40:46 +00004102 QualType Result = TL.getType();
4103 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004104 ElementType != T->getElementType() ||
4105 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004106 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004107 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004109 if (Result.isNull())
4110 return QualType();
4111 }
John McCall550e0c22009-10-21 00:40:46 +00004112
4113 // Result might be dependent or not.
4114 if (isa<DependentSizedExtVectorType>(Result)) {
4115 DependentSizedExtVectorTypeLoc NewTL
4116 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4117 NewTL.setNameLoc(TL.getNameLoc());
4118 } else {
4119 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4120 NewTL.setNameLoc(TL.getNameLoc());
4121 }
4122
4123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004124}
Mike Stump11289f42009-09-09 15:08:12 +00004125
4126template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004127QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004129 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130 QualType ElementType = getDerived().TransformType(T->getElementType());
4131 if (ElementType.isNull())
4132 return QualType();
4133
John McCall550e0c22009-10-21 00:40:46 +00004134 QualType Result = TL.getType();
4135 if (getDerived().AlwaysRebuild() ||
4136 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004137 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004138 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004139 if (Result.isNull())
4140 return QualType();
4141 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
John McCall550e0c22009-10-21 00:40:46 +00004143 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4144 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004145
John McCall550e0c22009-10-21 00:40:46 +00004146 return Result;
4147}
4148
4149template<typename Derived>
4150QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004151 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004152 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004153 QualType ElementType = getDerived().TransformType(T->getElementType());
4154 if (ElementType.isNull())
4155 return QualType();
4156
4157 QualType Result = TL.getType();
4158 if (getDerived().AlwaysRebuild() ||
4159 ElementType != T->getElementType()) {
4160 Result = getDerived().RebuildExtVectorType(ElementType,
4161 T->getNumElements(),
4162 /*FIXME*/ SourceLocation());
4163 if (Result.isNull())
4164 return QualType();
4165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004166
John McCall550e0c22009-10-21 00:40:46 +00004167 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4168 NewTL.setNameLoc(TL.getNameLoc());
4169
4170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
David Blaikie05785d12013-02-20 22:23:23 +00004173template <typename Derived>
4174ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4175 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4176 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004177 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004178 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004179
Douglas Gregor715e4612011-01-14 22:40:04 +00004180 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004181 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004182 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004183 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004184 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004185
Douglas Gregor715e4612011-01-14 22:40:04 +00004186 TypeLocBuilder TLB;
4187 TypeLoc NewTL = OldDI->getTypeLoc();
4188 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004189
4190 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004191 OldExpansionTL.getPatternLoc());
4192 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004193 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004194
4195 Result = RebuildPackExpansionType(Result,
4196 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004197 OldExpansionTL.getEllipsisLoc(),
4198 NumExpansions);
4199 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004200 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004201
Douglas Gregor715e4612011-01-14 22:40:04 +00004202 PackExpansionTypeLoc NewExpansionTL
4203 = TLB.push<PackExpansionTypeLoc>(Result);
4204 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4205 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4206 } else
4207 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004208 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004209 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004210
John McCall8fb0d9d2011-05-01 22:35:37 +00004211 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004212 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004213
4214 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4215 OldParm->getDeclContext(),
4216 OldParm->getInnerLocStart(),
4217 OldParm->getLocation(),
4218 OldParm->getIdentifier(),
4219 NewDI->getType(),
4220 NewDI,
4221 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004222 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004223 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4224 OldParm->getFunctionScopeIndex() + indexAdjustment);
4225 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004226}
4227
4228template<typename Derived>
4229bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004230 TransformFunctionTypeParams(SourceLocation Loc,
4231 ParmVarDecl **Params, unsigned NumParams,
4232 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004233 SmallVectorImpl<QualType> &OutParamTypes,
4234 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004235 int indexAdjustment = 0;
4236
Douglas Gregordd472162011-01-07 00:20:55 +00004237 for (unsigned i = 0; i != NumParams; ++i) {
4238 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004239 assert(OldParm->getFunctionScopeIndex() == i);
4240
David Blaikie05785d12013-02-20 22:23:23 +00004241 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004242 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004243 if (OldParm->isParameterPack()) {
4244 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004245 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004246
Douglas Gregor5499af42011-01-05 23:12:31 +00004247 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004248 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004249 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004250 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4251 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004252 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4253
Douglas Gregor5499af42011-01-05 23:12:31 +00004254 // Determine whether we should expand the parameter packs.
4255 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004256 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004257 Optional<unsigned> OrigNumExpansions =
4258 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004259 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004260 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4261 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004262 Unexpanded,
4263 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004264 RetainExpansion,
4265 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004266 return true;
4267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004268
Douglas Gregor5499af42011-01-05 23:12:31 +00004269 if (ShouldExpand) {
4270 // Expand the function parameter pack into multiple, separate
4271 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004272 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004273 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004274 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004275 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004276 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004277 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004278 OrigNumExpansions,
4279 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 if (!NewParm)
4281 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004282
Douglas Gregordd472162011-01-07 00:20:55 +00004283 OutParamTypes.push_back(NewParm->getType());
4284 if (PVars)
4285 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004287
4288 // If we're supposed to retain a pack expansion, do so by temporarily
4289 // forgetting the partially-substituted parameter pack.
4290 if (RetainExpansion) {
4291 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004292 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004293 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004294 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004295 OrigNumExpansions,
4296 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004297 if (!NewParm)
4298 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004299
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004300 OutParamTypes.push_back(NewParm->getType());
4301 if (PVars)
4302 PVars->push_back(NewParm);
4303 }
4304
John McCall8fb0d9d2011-05-01 22:35:37 +00004305 // The next parameter should have the same adjustment as the
4306 // last thing we pushed, but we post-incremented indexAdjustment
4307 // on every push. Also, if we push nothing, the adjustment should
4308 // go down by one.
4309 indexAdjustment--;
4310
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 // We're done with the pack expansion.
4312 continue;
4313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
4315 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004316 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004317 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4318 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004319 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004320 NumExpansions,
4321 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004322 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004323 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004324 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004325 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004326
John McCall58f10c32010-03-11 09:03:00 +00004327 if (!NewParm)
4328 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Douglas Gregordd472162011-01-07 00:20:55 +00004330 OutParamTypes.push_back(NewParm->getType());
4331 if (PVars)
4332 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 continue;
4334 }
John McCall58f10c32010-03-11 09:03:00 +00004335
4336 // Deal with the possibility that we don't have a parameter
4337 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004338 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004340 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004341 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004342 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004343 = dyn_cast<PackExpansionType>(OldType)) {
4344 // We have a function parameter pack that may need to be expanded.
4345 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004346 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004347 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004348
Douglas Gregor5499af42011-01-05 23:12:31 +00004349 // Determine whether we should expand the parameter packs.
4350 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004351 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004352 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004353 Unexpanded,
4354 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004355 RetainExpansion,
4356 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004357 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004359
Douglas Gregor5499af42011-01-05 23:12:31 +00004360 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004361 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004362 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004363 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4365 QualType NewType = getDerived().TransformType(Pattern);
4366 if (NewType.isNull())
4367 return true;
John McCall58f10c32010-03-11 09:03:00 +00004368
Douglas Gregordd472162011-01-07 00:20:55 +00004369 OutParamTypes.push_back(NewType);
4370 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004371 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004373
Douglas Gregor5499af42011-01-05 23:12:31 +00004374 // We're done with the pack expansion.
4375 continue;
4376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Douglas Gregor48d24112011-01-10 20:53:55 +00004378 // If we're supposed to retain a pack expansion, do so by temporarily
4379 // forgetting the partially-substituted parameter pack.
4380 if (RetainExpansion) {
4381 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4382 QualType NewType = getDerived().TransformType(Pattern);
4383 if (NewType.isNull())
4384 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004385
Douglas Gregor48d24112011-01-10 20:53:55 +00004386 OutParamTypes.push_back(NewType);
4387 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004388 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004389 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004390
Chad Rosier1dcde962012-08-08 18:46:20 +00004391 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004392 // expansion.
4393 OldType = Expansion->getPattern();
4394 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004395 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4396 NewType = getDerived().TransformType(OldType);
4397 } else {
4398 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004400
Douglas Gregor5499af42011-01-05 23:12:31 +00004401 if (NewType.isNull())
4402 return true;
4403
4404 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004405 NewType = getSema().Context.getPackExpansionType(NewType,
4406 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 OutParamTypes.push_back(NewType);
4409 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004410 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004411 }
4412
John McCall8fb0d9d2011-05-01 22:35:37 +00004413#ifndef NDEBUG
4414 if (PVars) {
4415 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4416 if (ParmVarDecl *parm = (*PVars)[i])
4417 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004418 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004419#endif
4420
4421 return false;
4422}
John McCall58f10c32010-03-11 09:03:00 +00004423
4424template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004425QualType
John McCall550e0c22009-10-21 00:40:46 +00004426TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004427 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004428 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004429}
4430
4431template<typename Derived>
4432QualType
4433TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4434 FunctionProtoTypeLoc TL,
4435 CXXRecordDecl *ThisContext,
4436 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004437 // Transform the parameters and return type.
4438 //
Richard Smithf623c962012-04-17 00:58:00 +00004439 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004440 // When the function has a trailing return type, we instantiate the
4441 // parameters before the return type, since the return type can then refer
4442 // to the parameters themselves (via decltype, sizeof, etc.).
4443 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004444 SmallVector<QualType, 4> ParamTypes;
4445 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004446 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004447
Douglas Gregor7fb25412010-10-01 18:44:50 +00004448 QualType ResultType;
4449
Richard Smith1226c602012-08-14 22:51:13 +00004450 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004451 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004452 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004453 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004454 return QualType();
4455
Douglas Gregor3024f072012-04-16 07:05:22 +00004456 {
4457 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004458 // If a declaration declares a member function or member function
4459 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004460 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004461 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004462 // declarator.
4463 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004464
Alp Toker42a16a62014-01-25 23:51:36 +00004465 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004466 if (ResultType.isNull())
4467 return QualType();
4468 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004469 }
4470 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004471 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004472 if (ResultType.isNull())
4473 return QualType();
4474
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 }
4480
Richard Smithf623c962012-04-17 00:58:00 +00004481 // FIXME: Need to transform the exception-specification too.
4482
John McCall550e0c22009-10-21 00:40:46 +00004483 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004484 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004485 T->getNumParams() != ParamTypes.size() ||
4486 !std::equal(T->param_type_begin(), T->param_type_end(),
4487 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004488 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004489 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004490 if (Result.isNull())
4491 return QualType();
4492 }
Mike Stump11289f42009-09-09 15:08:12 +00004493
John McCall550e0c22009-10-21 00:40:46 +00004494 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004495 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004496 NewTL.setLParenLoc(TL.getLParenLoc());
4497 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004498 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004499 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4500 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004501
4502 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004503}
Mike Stump11289f42009-09-09 15:08:12 +00004504
Douglas Gregord6ff3322009-08-04 16:50:30 +00004505template<typename Derived>
4506QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004507 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004508 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004509 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004510 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004511 if (ResultType.isNull())
4512 return QualType();
4513
4514 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004515 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004516 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4517
4518 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(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());
John McCall550e0c22009-10-21 00:40:46 +00004523
4524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004525}
Mike Stump11289f42009-09-09 15:08:12 +00004526
John McCallb96ec562009-12-04 22:46:56 +00004527template<typename Derived> QualType
4528TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004529 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004530 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004531 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004532 if (!D)
4533 return QualType();
4534
4535 QualType Result = TL.getType();
4536 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4537 Result = getDerived().RebuildUnresolvedUsingType(D);
4538 if (Result.isNull())
4539 return QualType();
4540 }
4541
4542 // We might get an arbitrary type spec type back. We should at
4543 // least always get a type spec type, though.
4544 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4545 NewTL.setNameLoc(TL.getNameLoc());
4546
4547 return Result;
4548}
4549
Douglas Gregord6ff3322009-08-04 16:50:30 +00004550template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004551QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004552 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004553 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004554 TypedefNameDecl *Typedef
4555 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4556 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004557 if (!Typedef)
4558 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004559
John McCall550e0c22009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
4561 if (getDerived().AlwaysRebuild() ||
4562 Typedef != T->getDecl()) {
4563 Result = getDerived().RebuildTypedefType(Typedef);
4564 if (Result.isNull())
4565 return QualType();
4566 }
Mike Stump11289f42009-09-09 15:08:12 +00004567
John McCall550e0c22009-10-21 00:40:46 +00004568 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570
4571 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572}
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregord6ff3322009-08-04 16:50:30 +00004574template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004575QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004576 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004577 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004578 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4579 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004580
John McCalldadc5752010-08-24 06:29:42 +00004581 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004582 if (E.isInvalid())
4583 return QualType();
4584
Eli Friedmane4f22df2012-02-29 04:03:55 +00004585 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4586 if (E.isInvalid())
4587 return QualType();
4588
John McCall550e0c22009-10-21 00:40:46 +00004589 QualType Result = TL.getType();
4590 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004591 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004592 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004593 if (Result.isNull())
4594 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004595 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004596 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004597
John McCall550e0c22009-10-21 00:40:46 +00004598 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004599 NewTL.setTypeofLoc(TL.getTypeofLoc());
4600 NewTL.setLParenLoc(TL.getLParenLoc());
4601 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004602
4603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004604}
Mike Stump11289f42009-09-09 15:08:12 +00004605
4606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004607QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004608 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004609 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4610 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4611 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004613
John McCall550e0c22009-10-21 00:40:46 +00004614 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004615 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4616 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004617 if (Result.isNull())
4618 return QualType();
4619 }
Mike Stump11289f42009-09-09 15:08:12 +00004620
John McCall550e0c22009-10-21 00:40:46 +00004621 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004622 NewTL.setTypeofLoc(TL.getTypeofLoc());
4623 NewTL.setLParenLoc(TL.getLParenLoc());
4624 NewTL.setRParenLoc(TL.getRParenLoc());
4625 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004632 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004633 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004634
Douglas Gregore922c772009-08-04 22:27:00 +00004635 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004636 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4637 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004638
John McCalldadc5752010-08-24 06:29:42 +00004639 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640 if (E.isInvalid())
4641 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004642
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004643 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004644 if (E.isInvalid())
4645 return QualType();
4646
John McCall550e0c22009-10-21 00:40:46 +00004647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() ||
4649 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004650 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004651 if (Result.isNull())
4652 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004654 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCall550e0c22009-10-21 00:40:46 +00004656 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4657 NewTL.setNameLoc(TL.getNameLoc());
4658
4659 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004660}
4661
4662template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004663QualType TreeTransform<Derived>::TransformUnaryTransformType(
4664 TypeLocBuilder &TLB,
4665 UnaryTransformTypeLoc TL) {
4666 QualType Result = TL.getType();
4667 if (Result->isDependentType()) {
4668 const UnaryTransformType *T = TL.getTypePtr();
4669 QualType NewBase =
4670 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4671 Result = getDerived().RebuildUnaryTransformType(NewBase,
4672 T->getUTTKind(),
4673 TL.getKWLoc());
4674 if (Result.isNull())
4675 return QualType();
4676 }
4677
4678 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4679 NewTL.setKWLoc(TL.getKWLoc());
4680 NewTL.setParensRange(TL.getParensRange());
4681 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4682 return Result;
4683}
4684
4685template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004686QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4687 AutoTypeLoc TL) {
4688 const AutoType *T = TL.getTypePtr();
4689 QualType OldDeduced = T->getDeducedType();
4690 QualType NewDeduced;
4691 if (!OldDeduced.isNull()) {
4692 NewDeduced = getDerived().TransformType(OldDeduced);
4693 if (NewDeduced.isNull())
4694 return QualType();
4695 }
4696
4697 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004698 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4699 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004700 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004701 if (Result.isNull())
4702 return QualType();
4703 }
4704
4705 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4706 NewTL.setNameLoc(TL.getNameLoc());
4707
4708 return Result;
4709}
4710
4711template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004712QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004713 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004714 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004715 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004716 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4717 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718 if (!Record)
4719 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004720
John McCall550e0c22009-10-21 00:40:46 +00004721 QualType Result = TL.getType();
4722 if (getDerived().AlwaysRebuild() ||
4723 Record != T->getDecl()) {
4724 Result = getDerived().RebuildRecordType(Record);
4725 if (Result.isNull())
4726 return QualType();
4727 }
Mike Stump11289f42009-09-09 15:08:12 +00004728
John McCall550e0c22009-10-21 00:40:46 +00004729 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4730 NewTL.setNameLoc(TL.getNameLoc());
4731
4732 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
4735template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004736QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004737 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004738 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004740 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4741 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742 if (!Enum)
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 Enum != T->getDecl()) {
4748 Result = getDerived().RebuildEnumType(Enum);
4749 if (Result.isNull())
4750 return QualType();
4751 }
Mike Stump11289f42009-09-09 15:08:12 +00004752
John McCall550e0c22009-10-21 00:40:46 +00004753 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4754 NewTL.setNameLoc(TL.getNameLoc());
4755
4756 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757}
John McCallfcc33b02009-09-05 00:15:47 +00004758
John McCalle78aac42010-03-10 03:28:59 +00004759template<typename Derived>
4760QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4761 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004762 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004763 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4764 TL.getTypePtr()->getDecl());
4765 if (!D) return QualType();
4766
4767 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4768 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4769 return T;
4770}
4771
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772template<typename Derived>
4773QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004774 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004775 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004776 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004777}
4778
Mike Stump11289f42009-09-09 15:08:12 +00004779template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004780QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004781 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004782 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004783 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004784
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004785 // Substitute into the replacement type, which itself might involve something
4786 // that needs to be transformed. This only tends to occur with default
4787 // template arguments of template template parameters.
4788 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4789 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4790 if (Replacement.isNull())
4791 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004792
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004793 // Always canonicalize the replacement type.
4794 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4795 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004796 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004797 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004798
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004799 // Propagate type-source information.
4800 SubstTemplateTypeParmTypeLoc NewTL
4801 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4802 NewTL.setNameLoc(TL.getNameLoc());
4803 return Result;
4804
John McCallcebee162009-10-18 09:09:24 +00004805}
4806
4807template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004808QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4809 TypeLocBuilder &TLB,
4810 SubstTemplateTypeParmPackTypeLoc TL) {
4811 return TransformTypeSpecType(TLB, TL);
4812}
4813
4814template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004815QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004816 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004817 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004818 const TemplateSpecializationType *T = TL.getTypePtr();
4819
Douglas Gregordf846d12011-03-02 18:46:51 +00004820 // The nested-name-specifier never matters in a TemplateSpecializationType,
4821 // because we can't have a dependent nested-name-specifier anyway.
4822 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004823 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004824 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4825 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004826 if (Template.isNull())
4827 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004828
John McCall31f82722010-11-12 08:19:04 +00004829 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4830}
4831
Eli Friedman0dfb8892011-10-06 23:00:33 +00004832template<typename Derived>
4833QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4834 AtomicTypeLoc TL) {
4835 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4836 if (ValueType.isNull())
4837 return QualType();
4838
4839 QualType Result = TL.getType();
4840 if (getDerived().AlwaysRebuild() ||
4841 ValueType != TL.getValueLoc().getType()) {
4842 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4843 if (Result.isNull())
4844 return QualType();
4845 }
4846
4847 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4848 NewTL.setKWLoc(TL.getKWLoc());
4849 NewTL.setLParenLoc(TL.getLParenLoc());
4850 NewTL.setRParenLoc(TL.getRParenLoc());
4851
4852 return Result;
4853}
4854
Chad Rosier1dcde962012-08-08 18:46:20 +00004855 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004856 /// container that provides a \c getArgLoc() member function.
4857 ///
4858 /// This iterator is intended to be used with the iterator form of
4859 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4860 template<typename ArgLocContainer>
4861 class TemplateArgumentLocContainerIterator {
4862 ArgLocContainer *Container;
4863 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004864
Douglas Gregorfe921a72010-12-20 23:36:19 +00004865 public:
4866 typedef TemplateArgumentLoc value_type;
4867 typedef TemplateArgumentLoc reference;
4868 typedef int difference_type;
4869 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004870
Douglas Gregorfe921a72010-12-20 23:36:19 +00004871 class pointer {
4872 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004873
Douglas Gregorfe921a72010-12-20 23:36:19 +00004874 public:
4875 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004876
Douglas Gregorfe921a72010-12-20 23:36:19 +00004877 const TemplateArgumentLoc *operator->() const {
4878 return &Arg;
4879 }
4880 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004881
4882
Douglas Gregorfe921a72010-12-20 23:36:19 +00004883 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004884
Douglas Gregorfe921a72010-12-20 23:36:19 +00004885 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4886 unsigned Index)
4887 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregorfe921a72010-12-20 23:36:19 +00004889 TemplateArgumentLocContainerIterator &operator++() {
4890 ++Index;
4891 return *this;
4892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
Douglas Gregorfe921a72010-12-20 23:36:19 +00004894 TemplateArgumentLocContainerIterator operator++(int) {
4895 TemplateArgumentLocContainerIterator Old(*this);
4896 ++(*this);
4897 return Old;
4898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004899
Douglas Gregorfe921a72010-12-20 23:36:19 +00004900 TemplateArgumentLoc operator*() const {
4901 return Container->getArgLoc(Index);
4902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004903
Douglas Gregorfe921a72010-12-20 23:36:19 +00004904 pointer operator->() const {
4905 return pointer(Container->getArgLoc(Index));
4906 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004907
Douglas Gregorfe921a72010-12-20 23:36:19 +00004908 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004909 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004910 return X.Container == Y.Container && X.Index == Y.Index;
4911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
Douglas Gregorfe921a72010-12-20 23:36:19 +00004913 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004914 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004915 return !(X == Y);
4916 }
4917 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004918
4919
John McCall31f82722010-11-12 08:19:04 +00004920template <typename Derived>
4921QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4922 TypeLocBuilder &TLB,
4923 TemplateSpecializationTypeLoc TL,
4924 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004925 TemplateArgumentListInfo NewTemplateArgs;
4926 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4927 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004928 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4929 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004930 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004931 ArgIterator(TL, TL.getNumArgs()),
4932 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004933 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004934
John McCall0ad16662009-10-29 08:12:44 +00004935 // FIXME: maybe don't rebuild if all the template arguments are the same.
4936
4937 QualType Result =
4938 getDerived().RebuildTemplateSpecializationType(Template,
4939 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004940 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004941
4942 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004943 // Specializations of template template parameters are represented as
4944 // TemplateSpecializationTypes, and substitution of type alias templates
4945 // within a dependent context can transform them into
4946 // DependentTemplateSpecializationTypes.
4947 if (isa<DependentTemplateSpecializationType>(Result)) {
4948 DependentTemplateSpecializationTypeLoc NewTL
4949 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004950 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004951 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004952 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004953 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004954 NewTL.setLAngleLoc(TL.getLAngleLoc());
4955 NewTL.setRAngleLoc(TL.getRAngleLoc());
4956 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4957 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4958 return Result;
4959 }
4960
John McCall0ad16662009-10-29 08:12:44 +00004961 TemplateSpecializationTypeLoc NewTL
4962 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004963 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004964 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4965 NewTL.setLAngleLoc(TL.getLAngleLoc());
4966 NewTL.setRAngleLoc(TL.getRAngleLoc());
4967 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4968 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004969 }
Mike Stump11289f42009-09-09 15:08:12 +00004970
John McCall0ad16662009-10-29 08:12:44 +00004971 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregor5a064722011-02-28 17:23:35 +00004974template <typename Derived>
4975QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4976 TypeLocBuilder &TLB,
4977 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004978 TemplateName Template,
4979 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004980 TemplateArgumentListInfo NewTemplateArgs;
4981 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4982 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4983 typedef TemplateArgumentLocContainerIterator<
4984 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004985 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004986 ArgIterator(TL, TL.getNumArgs()),
4987 NewTemplateArgs))
4988 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregor5a064722011-02-28 17:23:35 +00004990 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004991
Douglas Gregor5a064722011-02-28 17:23:35 +00004992 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4993 QualType Result
4994 = getSema().Context.getDependentTemplateSpecializationType(
4995 TL.getTypePtr()->getKeyword(),
4996 DTN->getQualifier(),
4997 DTN->getIdentifier(),
4998 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004999
Douglas Gregor5a064722011-02-28 17:23:35 +00005000 DependentTemplateSpecializationTypeLoc NewTL
5001 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005002 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005003 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005004 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005005 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005006 NewTL.setLAngleLoc(TL.getLAngleLoc());
5007 NewTL.setRAngleLoc(TL.getRAngleLoc());
5008 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5009 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5010 return Result;
5011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005012
5013 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005014 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005015 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005016 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005017
Douglas Gregor5a064722011-02-28 17:23:35 +00005018 if (!Result.isNull()) {
5019 /// FIXME: Wrap this in an elaborated-type-specifier?
5020 TemplateSpecializationTypeLoc NewTL
5021 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005022 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005023 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005024 NewTL.setLAngleLoc(TL.getLAngleLoc());
5025 NewTL.setRAngleLoc(TL.getRAngleLoc());
5026 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5027 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005029
Douglas Gregor5a064722011-02-28 17:23:35 +00005030 return Result;
5031}
5032
Mike Stump11289f42009-09-09 15:08:12 +00005033template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005034QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005035TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005036 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005037 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005038
Douglas Gregor844cb502011-03-01 18:12:44 +00005039 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005040 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005041 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005042 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005043 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5044 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005045 return QualType();
5046 }
Mike Stump11289f42009-09-09 15:08:12 +00005047
John McCall31f82722010-11-12 08:19:04 +00005048 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5049 if (NamedT.isNull())
5050 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005051
Richard Smith3f1b5d02011-05-05 21:57:07 +00005052 // C++0x [dcl.type.elab]p2:
5053 // If the identifier resolves to a typedef-name or the simple-template-id
5054 // resolves to an alias template specialization, the
5055 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005056 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5057 if (const TemplateSpecializationType *TST =
5058 NamedT->getAs<TemplateSpecializationType>()) {
5059 TemplateName Template = TST->getTemplateName();
5060 if (TypeAliasTemplateDecl *TAT =
5061 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5062 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5063 diag::err_tag_reference_non_tag) << 4;
5064 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5065 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005066 }
5067 }
5068
John McCall550e0c22009-10-21 00:40:46 +00005069 QualType Result = TL.getType();
5070 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005071 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005072 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005073 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005074 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005075 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005076 if (Result.isNull())
5077 return QualType();
5078 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005079
Abramo Bagnara6150c882010-05-11 21:36:43 +00005080 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005081 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005082 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005083 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084}
Mike Stump11289f42009-09-09 15:08:12 +00005085
5086template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005087QualType TreeTransform<Derived>::TransformAttributedType(
5088 TypeLocBuilder &TLB,
5089 AttributedTypeLoc TL) {
5090 const AttributedType *oldType = TL.getTypePtr();
5091 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5092 if (modifiedType.isNull())
5093 return QualType();
5094
5095 QualType result = TL.getType();
5096
5097 // FIXME: dependent operand expressions?
5098 if (getDerived().AlwaysRebuild() ||
5099 modifiedType != oldType->getModifiedType()) {
5100 // TODO: this is really lame; we should really be rebuilding the
5101 // equivalent type from first principles.
5102 QualType equivalentType
5103 = getDerived().TransformType(oldType->getEquivalentType());
5104 if (equivalentType.isNull())
5105 return QualType();
5106 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5107 modifiedType,
5108 equivalentType);
5109 }
5110
5111 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5112 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5113 if (TL.hasAttrOperand())
5114 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5115 if (TL.hasAttrExprOperand())
5116 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5117 else if (TL.hasAttrEnumOperand())
5118 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5119
5120 return result;
5121}
5122
5123template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005124QualType
5125TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5126 ParenTypeLoc TL) {
5127 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5128 if (Inner.isNull())
5129 return QualType();
5130
5131 QualType Result = TL.getType();
5132 if (getDerived().AlwaysRebuild() ||
5133 Inner != TL.getInnerLoc().getType()) {
5134 Result = getDerived().RebuildParenType(Inner);
5135 if (Result.isNull())
5136 return QualType();
5137 }
5138
5139 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5140 NewTL.setLParenLoc(TL.getLParenLoc());
5141 NewTL.setRParenLoc(TL.getRParenLoc());
5142 return Result;
5143}
5144
5145template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005146QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005147 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005148 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005149
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005150 NestedNameSpecifierLoc QualifierLoc
5151 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5152 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005154
John McCallc392f372010-06-11 00:33:02 +00005155 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005156 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005157 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005158 QualifierLoc,
5159 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005160 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005161 if (Result.isNull())
5162 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163
Abramo Bagnarad7548482010-05-19 21:37:53 +00005164 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5165 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005166 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5167
Abramo Bagnarad7548482010-05-19 21:37:53 +00005168 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005169 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005170 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005171 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005172 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005173 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005174 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005175 NewTL.setNameLoc(TL.getNameLoc());
5176 }
John McCall550e0c22009-10-21 00:40:46 +00005177 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregord6ff3322009-08-04 16:50:30 +00005180template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005181QualType TreeTransform<Derived>::
5182 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005183 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005184 NestedNameSpecifierLoc QualifierLoc;
5185 if (TL.getQualifierLoc()) {
5186 QualifierLoc
5187 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5188 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005189 return QualType();
5190 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
John McCall31f82722010-11-12 08:19:04 +00005192 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005193 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005194}
5195
5196template<typename Derived>
5197QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5199 DependentTemplateSpecializationTypeLoc TL,
5200 NestedNameSpecifierLoc QualifierLoc) {
5201 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
Douglas Gregora7a795b2011-03-01 20:11:18 +00005203 TemplateArgumentListInfo NewTemplateArgs;
5204 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5205 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
Douglas Gregora7a795b2011-03-01 20:11:18 +00005207 typedef TemplateArgumentLocContainerIterator<
5208 DependentTemplateSpecializationTypeLoc> ArgIterator;
5209 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5210 ArgIterator(TL, TL.getNumArgs()),
5211 NewTemplateArgs))
5212 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005213
Douglas Gregora7a795b2011-03-01 20:11:18 +00005214 QualType Result
5215 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5216 QualifierLoc,
5217 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005218 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005219 NewTemplateArgs);
5220 if (Result.isNull())
5221 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005222
Douglas Gregora7a795b2011-03-01 20:11:18 +00005223 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5224 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
Douglas Gregora7a795b2011-03-01 20:11:18 +00005226 // Copy information relevant to the template specialization.
5227 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005228 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005229 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005230 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005231 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5232 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005233 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005234 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005235
Douglas Gregora7a795b2011-03-01 20:11:18 +00005236 // Copy information relevant to the elaborated type.
5237 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005238 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005239 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005240 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5241 DependentTemplateSpecializationTypeLoc SpecTL
5242 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005243 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005244 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005245 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005246 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005247 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5248 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005249 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005250 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005251 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005252 TemplateSpecializationTypeLoc SpecTL
5253 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005254 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005255 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005256 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5257 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005258 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005259 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005260 }
5261 return Result;
5262}
5263
5264template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005265QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5266 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005267 QualType Pattern
5268 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005269 if (Pattern.isNull())
5270 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005271
5272 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005273 if (getDerived().AlwaysRebuild() ||
5274 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005275 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005276 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005277 TL.getEllipsisLoc(),
5278 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005279 if (Result.isNull())
5280 return QualType();
5281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregor822d0302011-01-12 17:07:58 +00005283 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5284 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5285 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005286}
5287
5288template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005289QualType
5290TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005291 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005292 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005293 TLB.pushFullCopy(TL);
5294 return TL.getType();
5295}
5296
5297template<typename Derived>
5298QualType
5299TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005300 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005301 // ObjCObjectType is never dependent.
5302 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005303 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304}
Mike Stump11289f42009-09-09 15:08:12 +00005305
5306template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005307QualType
5308TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005309 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005310 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005311 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005312 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005313}
5314
Douglas Gregord6ff3322009-08-04 16:50:30 +00005315//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005316// Statement transformation
5317//===----------------------------------------------------------------------===//
5318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005319StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005320TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005321 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005322}
5323
5324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005325StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005326TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5327 return getDerived().TransformCompoundStmt(S, false);
5328}
5329
5330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005331StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005332TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005334 Sema::CompoundScopeRAII CompoundScope(getSema());
5335
John McCall1ababa62010-08-27 19:56:05 +00005336 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005338 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005339 for (auto *B : S->body()) {
5340 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005341 if (Result.isInvalid()) {
5342 // Immediately fail if this was a DeclStmt, since it's very
5343 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005344 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005345 return StmtError();
5346
5347 // Otherwise, just keep processing substatements and fail later.
5348 SubStmtInvalid = true;
5349 continue;
5350 }
Mike Stump11289f42009-09-09 15:08:12 +00005351
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005352 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005353 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005354 }
Mike Stump11289f42009-09-09 15:08:12 +00005355
John McCall1ababa62010-08-27 19:56:05 +00005356 if (SubStmtInvalid)
5357 return StmtError();
5358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 if (!getDerived().AlwaysRebuild() &&
5360 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005361 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005362
5363 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005364 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005365 S->getRBracLoc(),
5366 IsStmtExpr);
5367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregorebe10102009-08-20 07:17:43 +00005369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005370StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005371TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005372 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005373 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005374 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5375 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005376
Eli Friedman06577382009-11-19 03:14:00 +00005377 // Transform the left-hand case value.
5378 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005379 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005380 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005381 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005382
Eli Friedman06577382009-11-19 03:14:00 +00005383 // Transform the right-hand case value (for the GNU case-range extension).
5384 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005385 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005386 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005387 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005388 }
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregorebe10102009-08-20 07:17:43 +00005390 // Build the case statement.
5391 // Case statements are always rebuilt so that they will attached to their
5392 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005393 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005394 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005395 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005396 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005397 S->getColonLoc());
5398 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005399 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005400
Douglas Gregorebe10102009-08-20 07:17:43 +00005401 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005402 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005403 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005404 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005405
Douglas Gregorebe10102009-08-20 07:17:43 +00005406 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005407 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005408}
5409
5410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005411StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005414 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005415 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005416 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregorebe10102009-08-20 07:17:43 +00005418 // Default statements are always rebuilt
5419 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005420 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005421}
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregorebe10102009-08-20 07:17:43 +00005423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005424StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005425TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
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
Chris Lattnercab02a62011-02-17 20:34:02 +00005430 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5431 S->getDecl());
5432 if (!LD)
5433 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005434
5435
Douglas Gregorebe10102009-08-20 07:17:43 +00005436 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005437 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005438 cast<LabelDecl>(LD), SourceLocation(),
5439 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005440}
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregorebe10102009-08-20 07:17:43 +00005442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005443StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005444TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5445 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5446 if (SubStmt.isInvalid())
5447 return StmtError();
5448
5449 // TODO: transform attributes
5450 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5451 return S;
5452
5453 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5454 S->getAttrs(),
5455 SubStmt.get());
5456}
5457
5458template<typename Derived>
5459StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005460TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005462 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005463 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005464 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005465 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005466 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005467 getDerived().TransformDefinition(
5468 S->getConditionVariable()->getLocation(),
5469 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005470 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005472 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005473 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005475 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005477
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005478 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005479 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005480 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005481 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005482 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005483 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005484
John McCallb268a282010-08-23 23:25:46 +00005485 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005486 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005488
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005489 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005490 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005492
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005494 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005495 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregorebe10102009-08-20 07:17:43 +00005498 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005499 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005500 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005501 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005502
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005504 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005505 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005506 Then.get() == S->getThen() &&
5507 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005508 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005509
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005510 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005511 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005512 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005513}
5514
5515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005516StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005517TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005518 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005519 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005520 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005521 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005522 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005523 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005524 getDerived().TransformDefinition(
5525 S->getConditionVariable()->getLocation(),
5526 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005527 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005529 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005530 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005531
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005532 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005533 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005534 }
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005537 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005538 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005539 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005542
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005544 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005545 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005546 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorebe10102009-08-20 07:17:43 +00005548 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005549 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5550 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005551}
Mike Stump11289f42009-09-09 15:08:12 +00005552
Douglas Gregorebe10102009-08-20 07:17:43 +00005553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005554StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005555TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005556 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005557 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005558 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005559 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005560 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005561 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005562 getDerived().TransformDefinition(
5563 S->getConditionVariable()->getLocation(),
5564 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005565 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005567 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005568 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005569
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005570 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005571 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005572
5573 if (S->getCond()) {
5574 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005575 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5576 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005577 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005578 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005580 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005581 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005584 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005585 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005589 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005594 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005595 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005597 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005599 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005600 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregorebe10102009-08-20 07:17:43 +00005603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005604StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005605TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005607 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005608 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005611 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005612 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005613 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005615
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 if (!getDerived().AlwaysRebuild() &&
5617 Cond.get() == S->getCond() &&
5618 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005619 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCallb268a282010-08-23 23:25:46 +00005621 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5622 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 S->getRParenLoc());
5624}
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregorebe10102009-08-20 07:17:43 +00005626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005629 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005630 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregorebe10102009-08-20 07:17:43 +00005634 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005635 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005636 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005637 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005638 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005639 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005640 getDerived().TransformDefinition(
5641 S->getConditionVariable()->getLocation(),
5642 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005643 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005645 } else {
5646 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005647
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005648 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005650
5651 if (S->getCond()) {
5652 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005653 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5654 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005655 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005656 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005658
John McCallb268a282010-08-23 23:25:46 +00005659 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005660 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005663 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005664 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005666
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005668 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005669 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005670 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005671
Richard Smith945f8d32013-01-14 22:39:08 +00005672 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005673 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005677 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregorebe10102009-08-20 07:17:43 +00005681 if (!getDerived().AlwaysRebuild() &&
5682 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005683 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 Inc.get() == S->getInc() &&
5685 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005686 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005689 Init.get(), FullCond, ConditionVar,
5690 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691}
5692
5693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005696 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5697 S->getLabel());
5698 if (!LD)
5699 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005700
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005702 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005703 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
5705
5706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005708TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005709 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005712 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregorebe10102009-08-20 07:17:43 +00005714 if (!getDerived().AlwaysRebuild() &&
5715 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005716 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005717
5718 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005719 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005720}
5721
5722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005724TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005725 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005726}
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregorebe10102009-08-20 07:17:43 +00005728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005729StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005730TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005731 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregorebe10102009-08-20 07:17:43 +00005734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005736TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005737 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005738 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005740
Mike Stump11289f42009-09-09 15:08:12 +00005741 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005742 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005743 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005744}
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregorebe10102009-08-20 07:17:43 +00005746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005747StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005748TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005749 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005750 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005751 for (auto *D : S->decls()) {
5752 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005753 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005755
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005756 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregorebe10102009-08-20 07:17:43 +00005759 Decls.push_back(Transformed);
5760 }
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregorebe10102009-08-20 07:17:43 +00005762 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005763 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005764
Rafael Espindolaab417692013-07-09 12:05:01 +00005765 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005766}
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregorebe10102009-08-20 07:17:43 +00005768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005769StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005770TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005771
Benjamin Kramerf0623432012-08-23 22:51:59 +00005772 SmallVector<Expr*, 8> Constraints;
5773 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005774 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005775
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005777 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005778
5779 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005780
Anders Carlssonaaeef072010-01-24 05:50:09 +00005781 // Go through the outputs.
5782 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005783 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Anders Carlssonaaeef072010-01-24 05:50:09 +00005785 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005786 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005787
Anders Carlssonaaeef072010-01-24 05:50:09 +00005788 // Transform the output expr.
5789 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005790 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005791 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005793
Anders Carlssonaaeef072010-01-24 05:50:09 +00005794 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
John McCallb268a282010-08-23 23:25:46 +00005796 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005798
Anders Carlssonaaeef072010-01-24 05:50:09 +00005799 // Go through the inputs.
5800 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005801 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005802
Anders Carlssonaaeef072010-01-24 05:50:09 +00005803 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005804 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005805
Anders Carlssonaaeef072010-01-24 05:50:09 +00005806 // Transform the input expr.
5807 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005808 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005809 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005810 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Anders Carlssonaaeef072010-01-24 05:50:09 +00005812 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
John McCallb268a282010-08-23 23:25:46 +00005814 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005816
Anders Carlssonaaeef072010-01-24 05:50:09 +00005817 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005818 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005819
5820 // Go through the clobbers.
5821 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005822 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005823
5824 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005825 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005826 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5827 S->isVolatile(), S->getNumOutputs(),
5828 S->getNumInputs(), Names.data(),
5829 Constraints, Exprs, AsmString.get(),
5830 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005831}
5832
Chad Rosier32503022012-06-11 20:47:18 +00005833template<typename Derived>
5834StmtResult
5835TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005836 ArrayRef<Token> AsmToks =
5837 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005838
John McCallf413f5e2013-05-03 00:10:13 +00005839 bool HadError = false, HadChange = false;
5840
5841 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5842 SmallVector<Expr*, 8> TransformedExprs;
5843 TransformedExprs.reserve(SrcExprs.size());
5844 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5845 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5846 if (!Result.isUsable()) {
5847 HadError = true;
5848 } else {
5849 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005850 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005851 }
5852 }
5853
5854 if (HadError) return StmtError();
5855 if (!HadChange && !getDerived().AlwaysRebuild())
5856 return Owned(S);
5857
Chad Rosierb6f46c12012-08-15 16:53:30 +00005858 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005859 AsmToks, S->getAsmString(),
5860 S->getNumOutputs(), S->getNumInputs(),
5861 S->getAllConstraints(), S->getClobbers(),
5862 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005863}
Douglas Gregorebe10102009-08-20 07:17:43 +00005864
5865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005867TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005868 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005869 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005870 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005872
Douglas Gregor96c79492010-04-23 22:50:49 +00005873 // Transform the @catch statements (if present).
5874 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005875 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005876 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005877 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005878 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005879 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005880 if (Catch.get() != S->getCatchStmt(I))
5881 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005882 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005884
Douglas Gregor306de2f2010-04-22 23:59:56 +00005885 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005886 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005887 if (S->getFinallyStmt()) {
5888 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5889 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005890 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005891 }
5892
5893 // If nothing changed, just retain this statement.
5894 if (!getDerived().AlwaysRebuild() &&
5895 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005896 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005897 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005898 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Douglas Gregor306de2f2010-04-22 23:59:56 +00005900 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005901 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005902 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005903}
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregorebe10102009-08-20 07:17:43 +00005905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005906StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005907TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005908 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005909 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005910 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005911 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005912 if (FromVar->getTypeSourceInfo()) {
5913 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5914 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005916 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005918 QualType T;
5919 if (TSInfo)
5920 T = TSInfo->getType();
5921 else {
5922 T = getDerived().TransformType(FromVar->getType());
5923 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005924 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005926
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005927 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5928 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005931
John McCalldadc5752010-08-24 06:29:42 +00005932 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005933 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005934 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005935
5936 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005937 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005938 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005939}
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorebe10102009-08-20 07:17:43 +00005941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005943TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005944 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005945 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005946 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
Douglas Gregor306de2f2010-04-22 23:59:56 +00005949 // If nothing changed, just retain this statement.
5950 if (!getDerived().AlwaysRebuild() &&
5951 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005952 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005953
5954 // Build a new statement.
5955 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005956 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005957}
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregorebe10102009-08-20 07:17:43 +00005959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005960StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005961TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005962 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005963 if (S->getThrowExpr()) {
5964 Operand = getDerived().TransformExpr(S->getThrowExpr());
5965 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005968
Douglas Gregor2900c162010-04-22 21:44:01 +00005969 if (!getDerived().AlwaysRebuild() &&
5970 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005971 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
John McCallb268a282010-08-23 23:25:46 +00005973 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005974}
Mike Stump11289f42009-09-09 15:08:12 +00005975
Douglas Gregorebe10102009-08-20 07:17:43 +00005976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005977StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005978TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005979 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005980 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005981 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005982 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005983 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005984 Object =
5985 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5986 Object.get());
5987 if (Object.isInvalid())
5988 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregor6148de72010-04-22 22:01:21 +00005990 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005991 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005992 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005993 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005994
Douglas Gregor6148de72010-04-22 22:01:21 +00005995 // If nothing change, just retain the current statement.
5996 if (!getDerived().AlwaysRebuild() &&
5997 Object.get() == S->getSynchExpr() &&
5998 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005999 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006000
6001 // Build a new statement.
6002 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006003 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006004}
6005
6006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007StmtResult
John McCall31168b02011-06-15 23:02:42 +00006008TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6009 ObjCAutoreleasePoolStmt *S) {
6010 // Transform the body.
6011 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6012 if (Body.isInvalid())
6013 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006014
John McCall31168b02011-06-15 23:02:42 +00006015 // If nothing changed, just retain this statement.
6016 if (!getDerived().AlwaysRebuild() &&
6017 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006018 return S;
John McCall31168b02011-06-15 23:02:42 +00006019
6020 // Build a new statement.
6021 return getDerived().RebuildObjCAutoreleasePoolStmt(
6022 S->getAtLoc(), Body.get());
6023}
6024
6025template<typename Derived>
6026StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006027TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006028 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006029 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006030 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006031 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006033
Douglas Gregorf68a5082010-04-22 23:10:45 +00006034 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006035 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006036 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006038
Douglas Gregorf68a5082010-04-22 23:10:45 +00006039 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006040 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006041 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006043
Douglas Gregorf68a5082010-04-22 23:10:45 +00006044 // If nothing changed, just retain this statement.
6045 if (!getDerived().AlwaysRebuild() &&
6046 Element.get() == S->getElement() &&
6047 Collection.get() == S->getCollection() &&
6048 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006049 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006050
Douglas Gregorf68a5082010-04-22 23:10:45 +00006051 // Build a new statement.
6052 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006053 Element.get(),
6054 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006055 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006056 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006057}
6058
David Majnemer5f7efef2013-10-15 09:50:08 +00006059template <typename Derived>
6060StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006062 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006063 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6064 TypeSourceInfo *T =
6065 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006066 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006068
David Majnemer5f7efef2013-10-15 09:50:08 +00006069 Var = getDerived().RebuildExceptionDecl(
6070 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6071 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006072 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 }
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006077 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006078 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006080
David Majnemer5f7efef2013-10-15 09:50:08 +00006081 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006083 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006084
David Majnemer5f7efef2013-10-15 09:50:08 +00006085 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006086}
Mike Stump11289f42009-09-09 15:08:12 +00006087
David Majnemer5f7efef2013-10-15 09:50:08 +00006088template <typename Derived>
6089StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006091 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006092 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006093 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 // Transform the handlers.
6096 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006097 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006099 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006102
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006104 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006105 }
Mike Stump11289f42009-09-09 15:08:12 +00006106
David Majnemer5f7efef2013-10-15 09:50:08 +00006107 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006108 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006109 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006110
John McCallb268a282010-08-23 23:25:46 +00006111 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006112 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006113}
Mike Stump11289f42009-09-09 15:08:12 +00006114
Richard Smith02e85f32011-04-14 22:09:26 +00006115template<typename Derived>
6116StmtResult
6117TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6118 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6119 if (Range.isInvalid())
6120 return StmtError();
6121
6122 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6123 if (BeginEnd.isInvalid())
6124 return StmtError();
6125
6126 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6127 if (Cond.isInvalid())
6128 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006129 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006130 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006131 if (Cond.isInvalid())
6132 return StmtError();
6133 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006134 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006135
6136 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6137 if (Inc.isInvalid())
6138 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006139 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006140 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006141
6142 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6143 if (LoopVar.isInvalid())
6144 return StmtError();
6145
6146 StmtResult NewStmt = S;
6147 if (getDerived().AlwaysRebuild() ||
6148 Range.get() != S->getRangeStmt() ||
6149 BeginEnd.get() != S->getBeginEndStmt() ||
6150 Cond.get() != S->getCond() ||
6151 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006152 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006153 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6154 S->getColonLoc(), Range.get(),
6155 BeginEnd.get(), Cond.get(),
6156 Inc.get(), LoopVar.get(),
6157 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006158 if (NewStmt.isInvalid())
6159 return StmtError();
6160 }
Richard Smith02e85f32011-04-14 22:09:26 +00006161
6162 StmtResult Body = getDerived().TransformStmt(S->getBody());
6163 if (Body.isInvalid())
6164 return StmtError();
6165
6166 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6167 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006168 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006169 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6170 S->getColonLoc(), Range.get(),
6171 BeginEnd.get(), Cond.get(),
6172 Inc.get(), LoopVar.get(),
6173 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006174 if (NewStmt.isInvalid())
6175 return StmtError();
6176 }
Richard Smith02e85f32011-04-14 22:09:26 +00006177
6178 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006179 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006180
6181 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6182}
6183
John Wiegley1c0675e2011-04-28 01:08:34 +00006184template<typename Derived>
6185StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006186TreeTransform<Derived>::TransformMSDependentExistsStmt(
6187 MSDependentExistsStmt *S) {
6188 // Transform the nested-name-specifier, if any.
6189 NestedNameSpecifierLoc QualifierLoc;
6190 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006191 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006192 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6193 if (!QualifierLoc)
6194 return StmtError();
6195 }
6196
6197 // Transform the declaration name.
6198 DeclarationNameInfo NameInfo = S->getNameInfo();
6199 if (NameInfo.getName()) {
6200 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6201 if (!NameInfo.getName())
6202 return StmtError();
6203 }
6204
6205 // Check whether anything changed.
6206 if (!getDerived().AlwaysRebuild() &&
6207 QualifierLoc == S->getQualifierLoc() &&
6208 NameInfo.getName() == S->getNameInfo().getName())
6209 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006210
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006211 // Determine whether this name exists, if we can.
6212 CXXScopeSpec SS;
6213 SS.Adopt(QualifierLoc);
6214 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006215 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006216 case Sema::IER_Exists:
6217 if (S->isIfExists())
6218 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006219
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006220 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6221
6222 case Sema::IER_DoesNotExist:
6223 if (S->isIfNotExists())
6224 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006226 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006227
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006228 case Sema::IER_Dependent:
6229 Dependent = true;
6230 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006231
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006232 case Sema::IER_Error:
6233 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006234 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006235
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006236 // We need to continue with the instantiation, so do so now.
6237 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6238 if (SubStmt.isInvalid())
6239 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006240
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006241 // If we have resolved the name, just transform to the substatement.
6242 if (!Dependent)
6243 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006244
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006245 // The name is still dependent, so build a dependent expression again.
6246 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6247 S->isIfExists(),
6248 QualifierLoc,
6249 NameInfo,
6250 SubStmt.get());
6251}
6252
6253template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006254ExprResult
6255TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6256 NestedNameSpecifierLoc QualifierLoc;
6257 if (E->getQualifierLoc()) {
6258 QualifierLoc
6259 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6260 if (!QualifierLoc)
6261 return ExprError();
6262 }
6263
6264 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6265 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6266 if (!PD)
6267 return ExprError();
6268
6269 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6270 if (Base.isInvalid())
6271 return ExprError();
6272
6273 return new (SemaRef.getASTContext())
6274 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6275 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6276 QualifierLoc, E->getMemberLoc());
6277}
6278
David Majnemerfad8f482013-10-15 09:33:02 +00006279template <typename Derived>
6280StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006281 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006282 if (TryBlock.isInvalid())
6283 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006284
6285 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006286 if (Handler.isInvalid())
6287 return StmtError();
6288
David Majnemerfad8f482013-10-15 09:33:02 +00006289 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6290 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006291 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006292
David Majnemerfad8f482013-10-15 09:33:02 +00006293 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006294 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006295}
6296
David Majnemerfad8f482013-10-15 09:33:02 +00006297template <typename Derived>
6298StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006299 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006300 if (Block.isInvalid())
6301 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006302
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006303 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006304}
6305
David Majnemerfad8f482013-10-15 09:33:02 +00006306template <typename Derived>
6307StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006308 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006309 if (FilterExpr.isInvalid())
6310 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006311
David Majnemer7e755502013-10-15 09:30:14 +00006312 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006313 if (Block.isInvalid())
6314 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006315
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006316 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6317 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006318}
6319
David Majnemerfad8f482013-10-15 09:33:02 +00006320template <typename Derived>
6321StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6322 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006323 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6324 else
6325 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6326}
6327
Alexander Musman64d33f12014-06-04 07:53:32 +00006328//===----------------------------------------------------------------------===//
6329// OpenMP directive transformation
6330//===----------------------------------------------------------------------===//
6331template <typename Derived>
6332StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6333 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006334
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006335 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006336 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006337 ArrayRef<OMPClause *> Clauses = D->clauses();
6338 TClauses.reserve(Clauses.size());
6339 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6340 I != E; ++I) {
6341 if (*I) {
6342 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006343 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006344 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006345 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006346 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006347 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006348 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006349 }
6350 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006351 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006352 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006353 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006354 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006355 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006356 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006357 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006358 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006359
Alexander Musman64d33f12014-06-04 07:53:32 +00006360 return getDerived().RebuildOMPExecutableDirective(
6361 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6362 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006363}
6364
Alexander Musman64d33f12014-06-04 07:53:32 +00006365template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006366StmtResult
6367TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6368 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006369 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006370 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6371 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6372 return Res;
6373}
6374
Alexander Musman64d33f12014-06-04 07:53:32 +00006375template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006376StmtResult
6377TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6378 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006379 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6381 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006382 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006383}
6384
Alexander Musman64d33f12014-06-04 07:53:32 +00006385//===----------------------------------------------------------------------===//
6386// OpenMP clause transformation
6387//===----------------------------------------------------------------------===//
6388template <typename Derived>
6389OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006390 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6391 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006392 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006393 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006394 C->getLParenLoc(), C->getLocEnd());
6395}
6396
Alexander Musman64d33f12014-06-04 07:53:32 +00006397template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006398OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006399TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6400 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6401 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006402 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006403 return getDerived().RebuildOMPNumThreadsClause(
6404 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006405}
6406
Alexey Bataev62c87d22014-03-21 04:51:18 +00006407template <typename Derived>
6408OMPClause *
6409TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6410 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6411 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006412 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006413 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006414 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006415}
6416
Alexander Musman8bd31e62014-05-27 15:12:19 +00006417template <typename Derived>
6418OMPClause *
6419TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6420 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6421 if (E.isInvalid())
6422 return 0;
6423 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006424 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006425}
6426
Alexander Musman64d33f12014-06-04 07:53:32 +00006427template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006428OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006429TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006430 return getDerived().RebuildOMPDefaultClause(
6431 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6432 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006433}
6434
Alexander Musman64d33f12014-06-04 07:53:32 +00006435template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006436OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006437TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006438 return getDerived().RebuildOMPProcBindClause(
6439 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6440 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006441}
6442
Alexander Musman64d33f12014-06-04 07:53:32 +00006443template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006444OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006445TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006446 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006447 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006448 for (auto *VE : C->varlists()) {
6449 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006450 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006451 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006452 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006453 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006454 return getDerived().RebuildOMPPrivateClause(
6455 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006456}
6457
Alexander Musman64d33f12014-06-04 07:53:32 +00006458template <typename Derived>
6459OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6460 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006461 llvm::SmallVector<Expr *, 16> Vars;
6462 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006463 for (auto *VE : C->varlists()) {
6464 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006465 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006466 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006467 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006468 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006469 return getDerived().RebuildOMPFirstprivateClause(
6470 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006471}
6472
Alexander Musman64d33f12014-06-04 07:53:32 +00006473template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006474OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006475TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6476 llvm::SmallVector<Expr *, 16> Vars;
6477 Vars.reserve(C->varlist_size());
6478 for (auto *VE : C->varlists()) {
6479 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6480 if (EVar.isInvalid())
6481 return nullptr;
6482 Vars.push_back(EVar.get());
6483 }
6484 return getDerived().RebuildOMPLastprivateClause(
6485 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6486}
6487
6488template <typename Derived>
6489OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006490TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6491 llvm::SmallVector<Expr *, 16> Vars;
6492 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006493 for (auto *VE : C->varlists()) {
6494 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006495 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006496 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006497 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006498 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006499 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6500 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006501}
6502
Alexander Musman64d33f12014-06-04 07:53:32 +00006503template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006504OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006505TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6506 llvm::SmallVector<Expr *, 16> Vars;
6507 Vars.reserve(C->varlist_size());
6508 for (auto *VE : C->varlists()) {
6509 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6510 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006511 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006512 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006513 }
6514 ExprResult Step = getDerived().TransformExpr(C->getStep());
6515 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006516 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006517 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6518 C->getLParenLoc(),
6519 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006520}
6521
Alexander Musman64d33f12014-06-04 07:53:32 +00006522template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006523OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006524TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6525 llvm::SmallVector<Expr *, 16> Vars;
6526 Vars.reserve(C->varlist_size());
6527 for (auto *VE : C->varlists()) {
6528 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6529 if (EVar.isInvalid())
6530 return nullptr;
6531 Vars.push_back(EVar.get());
6532 }
6533 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6534 if (Alignment.isInvalid())
6535 return nullptr;
6536 return getDerived().RebuildOMPAlignedClause(
6537 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6538 C->getColonLoc(), C->getLocEnd());
6539}
6540
Alexander Musman64d33f12014-06-04 07:53:32 +00006541template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006542OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006543TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6544 llvm::SmallVector<Expr *, 16> Vars;
6545 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006546 for (auto *VE : C->varlists()) {
6547 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006548 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006549 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006550 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006551 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006552 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6553 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006554}
6555
Douglas Gregorebe10102009-08-20 07:17:43 +00006556//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006557// Expression transformation
6558//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006562 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006563}
Mike Stump11289f42009-09-09 15:08:12 +00006564
6565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006568 NestedNameSpecifierLoc QualifierLoc;
6569 if (E->getQualifierLoc()) {
6570 QualifierLoc
6571 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6572 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006573 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006574 }
John McCallce546572009-12-08 09:08:17 +00006575
6576 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006577 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6578 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006581
John McCall815039a2010-08-17 21:27:17 +00006582 DeclarationNameInfo NameInfo = E->getNameInfo();
6583 if (NameInfo.getName()) {
6584 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6585 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006587 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006588
6589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006590 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006591 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006592 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006593 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006594
6595 // Mark it referenced in the new context regardless.
6596 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006597 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006598
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006599 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006600 }
John McCallce546572009-12-08 09:08:17 +00006601
Craig Topperc3ec1492014-05-26 06:22:03 +00006602 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006603 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006604 TemplateArgs = &TransArgs;
6605 TransArgs.setLAngleLoc(E->getLAngleLoc());
6606 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006607 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6608 E->getNumTemplateArgs(),
6609 TransArgs))
6610 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006611 }
6612
Chad Rosier1dcde962012-08-08 18:46:20 +00006613 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006614 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006615}
Mike Stump11289f42009-09-09 15:08:12 +00006616
Douglas Gregora16548e2009-08-11 05:31:07 +00006617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006619TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006620 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006621}
Mike Stump11289f42009-09-09 15:08:12 +00006622
Douglas Gregora16548e2009-08-11 05:31:07 +00006623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006624ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006625TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006626 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006627}
Mike Stump11289f42009-09-09 15:08:12 +00006628
Douglas Gregora16548e2009-08-11 05:31:07 +00006629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006630ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006631TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006632 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006633}
Mike Stump11289f42009-09-09 15:08:12 +00006634
Douglas Gregora16548e2009-08-11 05:31:07 +00006635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006637TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006638 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006639}
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregora16548e2009-08-11 05:31:07 +00006641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006643TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006644 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006645}
6646
6647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006648ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006649TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006650 if (FunctionDecl *FD = E->getDirectCallee())
6651 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006652 return SemaRef.MaybeBindToTemporary(E);
6653}
6654
6655template<typename Derived>
6656ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006657TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6658 ExprResult ControllingExpr =
6659 getDerived().TransformExpr(E->getControllingExpr());
6660 if (ControllingExpr.isInvalid())
6661 return ExprError();
6662
Chris Lattner01cf8db2011-07-20 06:58:45 +00006663 SmallVector<Expr *, 4> AssocExprs;
6664 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006665 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6666 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6667 if (TS) {
6668 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6669 if (!AssocType)
6670 return ExprError();
6671 AssocTypes.push_back(AssocType);
6672 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006673 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006674 }
6675
6676 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6677 if (AssocExpr.isInvalid())
6678 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006679 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006680 }
6681
6682 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6683 E->getDefaultLoc(),
6684 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006685 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006686 AssocTypes,
6687 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006688}
6689
6690template<typename Derived>
6691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006692TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006698 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006699
John McCallb268a282010-08-23 23:25:46 +00006700 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 E->getRParen());
6702}
6703
Richard Smithdb2630f2012-10-21 03:28:35 +00006704/// \brief The operand of a unary address-of operator has special rules: it's
6705/// allowed to refer to a non-static member of a class even if there's no 'this'
6706/// object available.
6707template<typename Derived>
6708ExprResult
6709TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6710 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6711 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6712 else
6713 return getDerived().TransformExpr(E);
6714}
6715
Mike Stump11289f42009-09-09 15:08:12 +00006716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006718TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006719 ExprResult SubExpr;
6720 if (E->getOpcode() == UO_AddrOf)
6721 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6722 else
6723 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006728 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6731 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006732 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006733}
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregora16548e2009-08-11 05:31:07 +00006735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006736ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006737TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6738 // Transform the type.
6739 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6740 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
Douglas Gregor882211c2010-04-28 22:16:22 +00006743 // Transform all of the components into components similar to what the
6744 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006745 // FIXME: It would be slightly more efficient in the non-dependent case to
6746 // just map FieldDecls, rather than requiring the rebuilder to look for
6747 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006748 // template code that we don't care.
6749 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006750 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006751 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006752 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006753 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6754 const Node &ON = E->getComponent(I);
6755 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006756 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006757 Comp.LocStart = ON.getSourceRange().getBegin();
6758 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006759 switch (ON.getKind()) {
6760 case Node::Array: {
6761 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006762 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006763 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006765
Douglas Gregor882211c2010-04-28 22:16:22 +00006766 ExprChanged = ExprChanged || Index.get() != FromIndex;
6767 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006768 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006769 break;
6770 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006771
Douglas Gregor882211c2010-04-28 22:16:22 +00006772 case Node::Field:
6773 case Node::Identifier:
6774 Comp.isBrackets = false;
6775 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006776 if (!Comp.U.IdentInfo)
6777 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006778
Douglas Gregor882211c2010-04-28 22:16:22 +00006779 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
Douglas Gregord1702062010-04-29 00:18:15 +00006781 case Node::Base:
6782 // Will be recomputed during the rebuild.
6783 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006785
Douglas Gregor882211c2010-04-28 22:16:22 +00006786 Components.push_back(Comp);
6787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregor882211c2010-04-28 22:16:22 +00006789 // If nothing changed, retain the existing expression.
6790 if (!getDerived().AlwaysRebuild() &&
6791 Type == E->getTypeSourceInfo() &&
6792 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006793 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006794
Douglas Gregor882211c2010-04-28 22:16:22 +00006795 // Build a new offsetof expression.
6796 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6797 Components.data(), Components.size(),
6798 E->getRParenLoc());
6799}
6800
6801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006802ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006803TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6804 assert(getDerived().AlreadyTransformed(E->getType()) &&
6805 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006806 return E;
John McCall8d69a212010-11-15 23:31:06 +00006807}
6808
6809template<typename Derived>
6810ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006811TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006812 // Rebuild the syntactic form. The original syntactic form has
6813 // opaque-value expressions in it, so strip those away and rebuild
6814 // the result. This is a really awful way of doing this, but the
6815 // better solution (rebuilding the semantic expressions and
6816 // rebinding OVEs as necessary) doesn't work; we'd need
6817 // TreeTransform to not strip away implicit conversions.
6818 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6819 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006820 if (result.isInvalid()) return ExprError();
6821
6822 // If that gives us a pseudo-object result back, the pseudo-object
6823 // expression must have been an lvalue-to-rvalue conversion which we
6824 // should reapply.
6825 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006826 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006827
6828 return result;
6829}
6830
6831template<typename Derived>
6832ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006833TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6834 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006836 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006837
John McCallbcd03502009-12-07 02:54:59 +00006838 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006839 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006841
John McCall4c98fd82009-11-04 07:28:41 +00006842 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006843 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006844
Peter Collingbournee190dee2011-03-11 19:24:49 +00006845 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6846 E->getKind(),
6847 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006848 }
Mike Stump11289f42009-09-09 15:08:12 +00006849
Eli Friedmane4f22df2012-02-29 04:03:55 +00006850 // C++0x [expr.sizeof]p1:
6851 // The operand is either an expression, which is an unevaluated operand
6852 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006853 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6854 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006855
Eli Friedmane4f22df2012-02-29 04:03:55 +00006856 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6857 if (SubExpr.isInvalid())
6858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
Eli Friedmane4f22df2012-02-29 04:03:55 +00006860 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006861 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006862
Peter Collingbournee190dee2011-03-11 19:24:49 +00006863 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6864 E->getOperatorLoc(),
6865 E->getKind(),
6866 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006867}
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregora16548e2009-08-11 05:31:07 +00006869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006871TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006872 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006873 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006875
John McCalldadc5752010-08-24 06:29:42 +00006876 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006879
6880
Douglas Gregora16548e2009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
6882 LHS.get() == E->getLHS() &&
6883 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006884 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006885
John McCallb268a282010-08-23 23:25:46 +00006886 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006888 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006889 E->getRBracketLoc());
6890}
Mike Stump11289f42009-09-09 15:08:12 +00006891
6892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006893ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006894TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006895 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006896 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006897 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006899
6900 // Transform arguments.
6901 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006902 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006903 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006904 &ArgChanged))
6905 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006906
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
6908 Callee.get() == E->getCallee() &&
6909 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006910 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006911
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006913 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006914 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006915 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006916 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 E->getRParenLoc());
6918}
Mike Stump11289f42009-09-09 15:08:12 +00006919
6920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006923 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006924 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006926
Douglas Gregorea972d32011-02-28 21:54:11 +00006927 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006928 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006929 QualifierLoc
6930 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006931
Douglas Gregorea972d32011-02-28 21:54:11 +00006932 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006934 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006935 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006936
Eli Friedman2cfcef62009-12-04 06:40:45 +00006937 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006938 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6939 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006941 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006942
John McCall16df1e52010-03-30 21:47:33 +00006943 NamedDecl *FoundDecl = E->getFoundDecl();
6944 if (FoundDecl == E->getMemberDecl()) {
6945 FoundDecl = Member;
6946 } else {
6947 FoundDecl = cast_or_null<NamedDecl>(
6948 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6949 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006950 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006951 }
6952
Douglas Gregora16548e2009-08-11 05:31:07 +00006953 if (!getDerived().AlwaysRebuild() &&
6954 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006955 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006956 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006957 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006958 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006959
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006960 // Mark it referenced in the new context regardless.
6961 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006962 SemaRef.MarkMemberReferenced(E);
6963
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006964 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006965 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006966
John McCall6b51f282009-11-23 01:53:49 +00006967 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006968 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006969 TransArgs.setLAngleLoc(E->getLAngleLoc());
6970 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006971 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6972 E->getNumTemplateArgs(),
6973 TransArgs))
6974 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006976
Douglas Gregora16548e2009-08-11 05:31:07 +00006977 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006978 SourceLocation FakeOperatorLoc =
6979 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006980
John McCall38836f02010-01-15 08:34:02 +00006981 // FIXME: to do this check properly, we will need to preserve the
6982 // first-qualifier-in-scope here, just in case we had a dependent
6983 // base (and therefore couldn't do the check) and a
6984 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00006985 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00006986
John McCallb268a282010-08-23 23:25:46 +00006987 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006989 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006990 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006991 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006992 Member,
John McCall16df1e52010-03-30 21:47:33 +00006993 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006994 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00006995 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00006996 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006997}
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007001TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007002 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007003 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007005
John McCalldadc5752010-08-24 06:29:42 +00007006 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007007 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 if (!getDerived().AlwaysRebuild() &&
7011 LHS.get() == E->getLHS() &&
7012 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007013 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007014
Lang Hames5de91cc2012-10-02 04:45:10 +00007015 Sema::FPContractStateRAII FPContractState(getSema());
7016 getSema().FPFeatures.fp_contract = E->isFPContractable();
7017
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007019 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007020}
7021
Mike Stump11289f42009-09-09 15:08:12 +00007022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007023ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007024TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007025 CompoundAssignOperator *E) {
7026 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007027}
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007030ExprResult TreeTransform<Derived>::
7031TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7032 // Just rebuild the common and RHS expressions and see whether we
7033 // get any changes.
7034
7035 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7036 if (commonExpr.isInvalid())
7037 return ExprError();
7038
7039 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7040 if (rhs.isInvalid())
7041 return ExprError();
7042
7043 if (!getDerived().AlwaysRebuild() &&
7044 commonExpr.get() == e->getCommon() &&
7045 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007046 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007047
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007048 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007049 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007050 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007051 e->getColonLoc(),
7052 rhs.get());
7053}
7054
7055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007057TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007058 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007061
John McCalldadc5752010-08-24 06:29:42 +00007062 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007063 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007065
John McCalldadc5752010-08-24 06:29:42 +00007066 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007067 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007069
Douglas Gregora16548e2009-08-11 05:31:07 +00007070 if (!getDerived().AlwaysRebuild() &&
7071 Cond.get() == E->getCond() &&
7072 LHS.get() == E->getLHS() &&
7073 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007074 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007075
John McCallb268a282010-08-23 23:25:46 +00007076 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007077 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007078 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007079 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007080 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007081}
Mike Stump11289f42009-09-09 15:08:12 +00007082
7083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007085TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007086 // Implicit casts are eliminated during transformation, since they
7087 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007088 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007089}
Mike Stump11289f42009-09-09 15:08:12 +00007090
Douglas Gregora16548e2009-08-11 05:31:07 +00007091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007094 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7095 if (!Type)
7096 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007097
John McCalldadc5752010-08-24 06:29:42 +00007098 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007099 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007100 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007104 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007106 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007107
John McCall97513962010-01-15 18:39:57 +00007108 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007109 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007110 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007111 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007112}
Mike Stump11289f42009-09-09 15:08:12 +00007113
Douglas Gregora16548e2009-08-11 05:31:07 +00007114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007116TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007117 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7118 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7119 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007121
John McCalldadc5752010-08-24 06:29:42 +00007122 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007125
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007127 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007129 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007130
John McCall5d7aa7f2010-01-19 22:33:45 +00007131 // Note: the expression type doesn't necessarily match the
7132 // type-as-written, but that's okay, because it should always be
7133 // derivable from the initializer.
7134
John McCalle15bbff2010-01-18 19:35:47 +00007135 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007137 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregora16548e2009-08-11 05:31:07 +00007140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007143 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007146
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 if (!getDerived().AlwaysRebuild() &&
7148 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007149 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007150
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007152 SourceLocation FakeOperatorLoc =
7153 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007154 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 E->getAccessorLoc(),
7156 E->getAccessor());
7157}
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007161TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007162 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007163
Benjamin Kramerf0623432012-08-23 22:51:59 +00007164 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007165 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007166 Inits, &InitChanged))
7167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007170 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007171
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007172 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007173 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007174}
Mike Stump11289f42009-09-09 15:08:12 +00007175
Douglas Gregora16548e2009-08-11 05:31:07 +00007176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007177ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007178TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007179 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregorebe10102009-08-20 07:17:43 +00007181 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007182 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007183 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregorebe10102009-08-20 07:17:43 +00007186 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007187 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 bool ExprChanged = false;
7189 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7190 DEnd = E->designators_end();
7191 D != DEnd; ++D) {
7192 if (D->isFieldDesignator()) {
7193 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7194 D->getDotLoc(),
7195 D->getFieldLoc()));
7196 continue;
7197 }
Mike Stump11289f42009-09-09 15:08:12 +00007198
Douglas Gregora16548e2009-08-11 05:31:07 +00007199 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007200 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007203
7204 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007205 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007206
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007208 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007209 continue;
7210 }
Mike Stump11289f42009-09-09 15:08:12 +00007211
Douglas Gregora16548e2009-08-11 05:31:07 +00007212 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007213 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7215 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007217
John McCalldadc5752010-08-24 06:29:42 +00007218 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007219 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007221
7222 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 End.get(),
7224 D->getLBracketLoc(),
7225 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007226
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7228 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007229
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007230 ArrayExprs.push_back(Start.get());
7231 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007232 }
Mike Stump11289f42009-09-09 15:08:12 +00007233
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 if (!getDerived().AlwaysRebuild() &&
7235 Init.get() == E->getInit() &&
7236 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007237 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007238
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007239 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007241 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007242}
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007245ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007246TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007247 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007248 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007249
Douglas Gregor3da3c062009-10-28 00:29:27 +00007250 // FIXME: Will we ever have proper type location here? Will we actually
7251 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007252 QualType T = getDerived().TransformType(E->getType());
7253 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007255
Douglas Gregora16548e2009-08-11 05:31:07 +00007256 if (!getDerived().AlwaysRebuild() &&
7257 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007258 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007259
Douglas Gregora16548e2009-08-11 05:31:07 +00007260 return getDerived().RebuildImplicitValueInitExpr(T);
7261}
Mike Stump11289f42009-09-09 15:08:12 +00007262
Douglas Gregora16548e2009-08-11 05:31:07 +00007263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007265TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007266 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7267 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007269
John McCalldadc5752010-08-24 06:29:42 +00007270 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007271 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007273
Douglas Gregora16548e2009-08-11 05:31:07 +00007274 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007275 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007277 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007278
John McCallb268a282010-08-23 23:25:46 +00007279 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007280 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007281}
7282
7283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007284ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007285TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007287 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007288 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7289 &ArgumentChanged))
7290 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007291
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007293 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 E->getRParenLoc());
7295}
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregora16548e2009-08-11 05:31:07 +00007297/// \brief Transform an address-of-label expression.
7298///
7299/// By default, the transformation of an address-of-label expression always
7300/// rebuilds the expression, so that the label identifier can be resolved to
7301/// the corresponding label statement by semantic analysis.
7302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007304TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007305 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7306 E->getLabel());
7307 if (!LD)
7308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007311 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007312}
Mike Stump11289f42009-09-09 15:08:12 +00007313
7314template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007317 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007318 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007319 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007320 if (SubStmt.isInvalid()) {
7321 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007322 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007323 }
Mike Stump11289f42009-09-09 15:08:12 +00007324
Douglas Gregora16548e2009-08-11 05:31:07 +00007325 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007326 SubStmt.get() == E->getSubStmt()) {
7327 // Calling this an 'error' is unintuitive, but it does the right thing.
7328 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007329 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007330 }
Mike Stump11289f42009-09-09 15:08:12 +00007331
7332 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007333 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007334 E->getRParenLoc());
7335}
Mike Stump11289f42009-09-09 15:08:12 +00007336
Douglas Gregora16548e2009-08-11 05:31:07 +00007337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007339TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007340 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007341 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007343
John McCalldadc5752010-08-24 06:29:42 +00007344 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007345 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007347
John McCalldadc5752010-08-24 06:29:42 +00007348 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007349 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007351
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 if (!getDerived().AlwaysRebuild() &&
7353 Cond.get() == E->getCond() &&
7354 LHS.get() == E->getLHS() &&
7355 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007356 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007359 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007360 E->getRParenLoc());
7361}
Mike Stump11289f42009-09-09 15:08:12 +00007362
Douglas Gregora16548e2009-08-11 05:31:07 +00007363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007366 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007367}
7368
7369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007371TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007372 switch (E->getOperator()) {
7373 case OO_New:
7374 case OO_Delete:
7375 case OO_Array_New:
7376 case OO_Array_Delete:
7377 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007378
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007379 case OO_Call: {
7380 // This is a call to an object's operator().
7381 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7382
7383 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007384 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007385 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007386 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007387
7388 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007389 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7390 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007391
7392 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007393 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007394 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007395 Args))
7396 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007397
John McCallb268a282010-08-23 23:25:46 +00007398 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007399 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007400 E->getLocEnd());
7401 }
7402
7403#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7404 case OO_##Name:
7405#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7406#include "clang/Basic/OperatorKinds.def"
7407 case OO_Subscript:
7408 // Handled below.
7409 break;
7410
7411 case OO_Conditional:
7412 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007413
7414 case OO_None:
7415 case NUM_OVERLOADED_OPERATORS:
7416 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007417 }
7418
John McCalldadc5752010-08-24 06:29:42 +00007419 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007422
Richard Smithdb2630f2012-10-21 03:28:35 +00007423 ExprResult First;
7424 if (E->getOperator() == OO_Amp)
7425 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7426 else
7427 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007429 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007430
John McCalldadc5752010-08-24 06:29:42 +00007431 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 if (E->getNumArgs() == 2) {
7433 Second = getDerived().TransformExpr(E->getArg(1));
7434 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007435 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 }
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 if (!getDerived().AlwaysRebuild() &&
7439 Callee.get() == E->getCallee() &&
7440 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007441 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007442 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007443
Lang Hames5de91cc2012-10-02 04:45:10 +00007444 Sema::FPContractStateRAII FPContractState(getSema());
7445 getSema().FPFeatures.fp_contract = E->isFPContractable();
7446
Douglas Gregora16548e2009-08-11 05:31:07 +00007447 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7448 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007449 Callee.get(),
7450 First.get(),
7451 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007452}
Mike Stump11289f42009-09-09 15:08:12 +00007453
Douglas Gregora16548e2009-08-11 05:31:07 +00007454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007455ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007456TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7457 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007458}
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregora16548e2009-08-11 05:31:07 +00007460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007461ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007462TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7463 // Transform the callee.
7464 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7465 if (Callee.isInvalid())
7466 return ExprError();
7467
7468 // Transform exec config.
7469 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7470 if (EC.isInvalid())
7471 return ExprError();
7472
7473 // Transform arguments.
7474 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007475 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007476 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007477 &ArgChanged))
7478 return ExprError();
7479
7480 if (!getDerived().AlwaysRebuild() &&
7481 Callee.get() == E->getCallee() &&
7482 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007483 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007484
7485 // FIXME: Wrong source location information for the '('.
7486 SourceLocation FakeLParenLoc
7487 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7488 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007489 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007490 E->getRParenLoc(), EC.get());
7491}
7492
7493template<typename Derived>
7494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007495TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007496 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7497 if (!Type)
7498 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007499
John McCalldadc5752010-08-24 06:29:42 +00007500 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007501 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007502 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007504
Douglas Gregora16548e2009-08-11 05:31:07 +00007505 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007506 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007508 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007510 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007511 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007512 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007513 E->getAngleBrackets().getEnd(),
7514 // FIXME. this should be '(' location
7515 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007516 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007517 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007518}
Mike Stump11289f42009-09-09 15:08:12 +00007519
Douglas Gregora16548e2009-08-11 05:31:07 +00007520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007522TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7523 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007524}
Mike Stump11289f42009-09-09 15:08:12 +00007525
7526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007528TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7529 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007530}
7531
Douglas Gregora16548e2009-08-11 05:31:07 +00007532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007533ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007534TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007535 CXXReinterpretCastExpr *E) {
7536 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007537}
Mike Stump11289f42009-09-09 15:08:12 +00007538
Douglas Gregora16548e2009-08-11 05:31:07 +00007539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007541TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7542 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007543}
Mike Stump11289f42009-09-09 15:08:12 +00007544
Douglas Gregora16548e2009-08-11 05:31:07 +00007545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007546ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007547TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007548 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007549 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7550 if (!Type)
7551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007552
John McCalldadc5752010-08-24 06:29:42 +00007553 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007554 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007557
Douglas Gregora16548e2009-08-11 05:31:07 +00007558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007559 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007561 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007562
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007563 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007564 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007565 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 E->getRParenLoc());
7567}
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregora16548e2009-08-11 05:31:07 +00007569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007571TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007573 TypeSourceInfo *TInfo
7574 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7575 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007579 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007580 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007581
Douglas Gregor9da64192010-04-26 22:37:10 +00007582 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7583 E->getLocStart(),
7584 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 E->getLocEnd());
7586 }
Mike Stump11289f42009-09-09 15:08:12 +00007587
Eli Friedman456f0182012-01-20 01:26:23 +00007588 // We don't know whether the subexpression is potentially evaluated until
7589 // after we perform semantic analysis. We speculatively assume it is
7590 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007591 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007592 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7593 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007594
John McCalldadc5752010-08-24 06:29:42 +00007595 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007598
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 if (!getDerived().AlwaysRebuild() &&
7600 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007601 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007602
Douglas Gregor9da64192010-04-26 22:37:10 +00007603 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7604 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007605 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007606 E->getLocEnd());
7607}
7608
7609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007610ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007611TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7612 if (E->isTypeOperand()) {
7613 TypeSourceInfo *TInfo
7614 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7615 if (!TInfo)
7616 return ExprError();
7617
7618 if (!getDerived().AlwaysRebuild() &&
7619 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007620 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007621
Douglas Gregor69735112011-03-06 17:40:41 +00007622 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007623 E->getLocStart(),
7624 TInfo,
7625 E->getLocEnd());
7626 }
7627
Francois Pichet9f4f2072010-09-08 12:20:18 +00007628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7629
7630 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7631 if (SubExpr.isInvalid())
7632 return ExprError();
7633
7634 if (!getDerived().AlwaysRebuild() &&
7635 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007636 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007637
7638 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7639 E->getLocStart(),
7640 SubExpr.get(),
7641 E->getLocEnd());
7642}
7643
7644template<typename Derived>
7645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007646TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007647 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007648}
Mike Stump11289f42009-09-09 15:08:12 +00007649
Douglas Gregora16548e2009-08-11 05:31:07 +00007650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007651ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007652TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007653 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007654 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007655}
Mike Stump11289f42009-09-09 15:08:12 +00007656
Douglas Gregora16548e2009-08-11 05:31:07 +00007657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007658ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007659TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007660 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007662 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7663 // Make sure that we capture 'this'.
7664 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007665 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007667
Douglas Gregorb15af892010-01-07 23:12:05 +00007668 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007669}
Mike Stump11289f42009-09-09 15:08:12 +00007670
Douglas Gregora16548e2009-08-11 05:31:07 +00007671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007673TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007674 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 if (!getDerived().AlwaysRebuild() &&
7679 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007680 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007681
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007682 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7683 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007684}
Mike Stump11289f42009-09-09 15:08:12 +00007685
Douglas Gregora16548e2009-08-11 05:31:07 +00007686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007688TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007689 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007690 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7691 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007692 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007694
Chandler Carruth794da4c2010-02-08 06:42:49 +00007695 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007697 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007698
Douglas Gregor033f6752009-12-23 23:03:06 +00007699 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007700}
Mike Stump11289f42009-09-09 15:08:12 +00007701
Douglas Gregora16548e2009-08-11 05:31:07 +00007702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007703ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007704TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7705 FieldDecl *Field
7706 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7707 E->getField()));
7708 if (!Field)
7709 return ExprError();
7710
7711 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007712 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007713
7714 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7715}
7716
7717template<typename Derived>
7718ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007719TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7720 CXXScalarValueInitExpr *E) {
7721 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7722 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007723 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007726 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007727 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007728
Chad Rosier1dcde962012-08-08 18:46:20 +00007729 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007730 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007731 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007732}
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregora16548e2009-08-11 05:31:07 +00007734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007736TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007738 TypeSourceInfo *AllocTypeInfo
7739 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7740 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007742
Douglas Gregora16548e2009-08-11 05:31:07 +00007743 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007744 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007745 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007747
Douglas Gregora16548e2009-08-11 05:31:07 +00007748 // Transform the placement arguments (if any).
7749 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007750 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007751 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007752 E->getNumPlacementArgs(), true,
7753 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007755
Sebastian Redl6047f072012-02-16 12:22:20 +00007756 // Transform the initializer (if any).
7757 Expr *OldInit = E->getInitializer();
7758 ExprResult NewInit;
7759 if (OldInit)
7760 NewInit = getDerived().TransformExpr(OldInit);
7761 if (NewInit.isInvalid())
7762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007763
Sebastian Redl6047f072012-02-16 12:22:20 +00007764 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007765 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007766 if (E->getOperatorNew()) {
7767 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007768 getDerived().TransformDecl(E->getLocStart(),
7769 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007770 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007772 }
7773
Craig Topperc3ec1492014-05-26 06:22:03 +00007774 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007775 if (E->getOperatorDelete()) {
7776 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007777 getDerived().TransformDecl(E->getLocStart(),
7778 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007779 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007780 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007781 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007782
Douglas Gregora16548e2009-08-11 05:31:07 +00007783 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007784 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007786 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007787 OperatorNew == E->getOperatorNew() &&
7788 OperatorDelete == E->getOperatorDelete() &&
7789 !ArgumentChanged) {
7790 // Mark any declarations we need as referenced.
7791 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007792 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007793 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007794 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007795 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007796
Sebastian Redl6047f072012-02-16 12:22:20 +00007797 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007798 QualType ElementType
7799 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7800 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7801 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7802 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007803 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007804 }
7805 }
7806 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007807
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007808 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007809 }
Mike Stump11289f42009-09-09 15:08:12 +00007810
Douglas Gregor0744ef62010-09-07 21:49:58 +00007811 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007812 if (!ArraySize.get()) {
7813 // If no array size was specified, but the new expression was
7814 // instantiated with an array type (e.g., "new T" where T is
7815 // instantiated with "int[4]"), extract the outer bound from the
7816 // array type as our array size. We do this with constant and
7817 // dependently-sized array types.
7818 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7819 if (!ArrayT) {
7820 // Do nothing
7821 } else if (const ConstantArrayType *ConsArrayT
7822 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007823 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7824 SemaRef.Context.getSizeType(),
7825 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007826 AllocType = ConsArrayT->getElementType();
7827 } else if (const DependentSizedArrayType *DepArrayT
7828 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7829 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007830 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007831 AllocType = DepArrayT->getElementType();
7832 }
7833 }
7834 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007835
Douglas Gregora16548e2009-08-11 05:31:07 +00007836 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7837 E->isGlobalNew(),
7838 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007839 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007840 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007841 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007842 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007843 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007844 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007845 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007846 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007847}
Mike Stump11289f42009-09-09 15:08:12 +00007848
Douglas Gregora16548e2009-08-11 05:31:07 +00007849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007851TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007852 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007853 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007855
Douglas Gregord2d9da02010-02-26 00:38:10 +00007856 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007857 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007858 if (E->getOperatorDelete()) {
7859 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007860 getDerived().TransformDecl(E->getLocStart(),
7861 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007862 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007863 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007867 Operand.get() == E->getArgument() &&
7868 OperatorDelete == E->getOperatorDelete()) {
7869 // Mark any declarations we need as referenced.
7870 // FIXME: instantiation-specific.
7871 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007872 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007873
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007874 if (!E->getArgument()->isTypeDependent()) {
7875 QualType Destroyed = SemaRef.Context.getBaseElementType(
7876 E->getDestroyedType());
7877 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7878 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007879 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007880 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007881 }
7882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007883
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007884 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007885 }
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregora16548e2009-08-11 05:31:07 +00007887 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7888 E->isGlobalDelete(),
7889 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007890 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007891}
Mike Stump11289f42009-09-09 15:08:12 +00007892
Douglas Gregora16548e2009-08-11 05:31:07 +00007893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007894ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007895TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007896 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007897 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007898 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007899 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007900
John McCallba7bf592010-08-24 05:47:05 +00007901 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007902 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007903 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007904 E->getOperatorLoc(),
7905 E->isArrow()? tok::arrow : tok::period,
7906 ObjectTypePtr,
7907 MayBePseudoDestructor);
7908 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007909 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007910
John McCallba7bf592010-08-24 05:47:05 +00007911 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007912 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7913 if (QualifierLoc) {
7914 QualifierLoc
7915 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7916 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007917 return ExprError();
7918 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007919 CXXScopeSpec SS;
7920 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007921
Douglas Gregor678f90d2010-02-25 01:56:36 +00007922 PseudoDestructorTypeStorage Destroyed;
7923 if (E->getDestroyedTypeInfo()) {
7924 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007925 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007926 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007927 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007928 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007929 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007930 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007931 // We aren't likely to be able to resolve the identifier down to a type
7932 // now anyway, so just retain the identifier.
7933 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7934 E->getDestroyedTypeLoc());
7935 } else {
7936 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007937 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007938 *E->getDestroyedTypeIdentifier(),
7939 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007940 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007941 SS, ObjectTypePtr,
7942 false);
7943 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007944 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007945
Douglas Gregor678f90d2010-02-25 01:56:36 +00007946 Destroyed
7947 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7948 E->getDestroyedTypeLoc());
7949 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007950
Craig Topperc3ec1492014-05-26 06:22:03 +00007951 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007952 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007953 CXXScopeSpec EmptySS;
7954 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007955 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007956 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007957 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007959
John McCallb268a282010-08-23 23:25:46 +00007960 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007961 E->getOperatorLoc(),
7962 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007963 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007964 ScopeTypeInfo,
7965 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007966 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007967 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007968}
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregorad8a3362009-09-04 17:36:40 +00007970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007971ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007972TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007973 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007974 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7975 Sema::LookupOrdinaryName);
7976
7977 // Transform all the decls.
7978 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7979 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007980 NamedDecl *InstD = static_cast<NamedDecl*>(
7981 getDerived().TransformDecl(Old->getNameLoc(),
7982 *I));
John McCall84d87672009-12-10 09:41:52 +00007983 if (!InstD) {
7984 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7985 // This can happen because of dependent hiding.
7986 if (isa<UsingShadowDecl>(*I))
7987 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007988 else {
7989 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007990 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007991 }
John McCall84d87672009-12-10 09:41:52 +00007992 }
John McCalle66edc12009-11-24 19:00:30 +00007993
7994 // Expand using declarations.
7995 if (isa<UsingDecl>(InstD)) {
7996 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007997 for (auto *I : UD->shadows())
7998 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007999 continue;
8000 }
8001
8002 R.addDecl(InstD);
8003 }
8004
8005 // Resolve a kind, but don't do any further analysis. If it's
8006 // ambiguous, the callee needs to deal with it.
8007 R.resolveKind();
8008
8009 // Rebuild the nested-name qualifier, if present.
8010 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008011 if (Old->getQualifierLoc()) {
8012 NestedNameSpecifierLoc QualifierLoc
8013 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8014 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008015 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008016
Douglas Gregor0da1d432011-02-28 20:01:57 +00008017 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008018 }
8019
Douglas Gregor9262f472010-04-27 18:19:34 +00008020 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008021 CXXRecordDecl *NamingClass
8022 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8023 Old->getNameLoc(),
8024 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008025 if (!NamingClass) {
8026 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008027 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008029
Douglas Gregorda7be082010-04-27 16:10:10 +00008030 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008031 }
8032
Abramo Bagnara7945c982012-01-27 09:46:47 +00008033 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8034
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008035 // If we have neither explicit template arguments, nor the template keyword,
8036 // it's a normal declaration name.
8037 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008038 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8039
8040 // If we have template arguments, rebuild them, then rebuild the
8041 // templateid expression.
8042 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008043 if (Old->hasExplicitTemplateArgs() &&
8044 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008045 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008046 TransArgs)) {
8047 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008048 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008049 }
John McCalle66edc12009-11-24 19:00:30 +00008050
Abramo Bagnara7945c982012-01-27 09:46:47 +00008051 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008052 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008053}
Mike Stump11289f42009-09-09 15:08:12 +00008054
Douglas Gregora16548e2009-08-11 05:31:07 +00008055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008056ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008057TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8058 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008059 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008060 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8061 TypeSourceInfo *From = E->getArg(I);
8062 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008063 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008064 TypeLocBuilder TLB;
8065 TLB.reserve(FromTL.getFullDataSize());
8066 QualType To = getDerived().TransformType(TLB, FromTL);
8067 if (To.isNull())
8068 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008069
Douglas Gregor29c42f22012-02-24 07:38:34 +00008070 if (To == From->getType())
8071 Args.push_back(From);
8072 else {
8073 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8074 ArgChanged = true;
8075 }
8076 continue;
8077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008078
Douglas Gregor29c42f22012-02-24 07:38:34 +00008079 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008080
Douglas Gregor29c42f22012-02-24 07:38:34 +00008081 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008082 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008083 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8084 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8085 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008086
Douglas Gregor29c42f22012-02-24 07:38:34 +00008087 // Determine whether the set of unexpanded parameter packs can and should
8088 // be expanded.
8089 bool Expand = true;
8090 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008091 Optional<unsigned> OrigNumExpansions =
8092 ExpansionTL.getTypePtr()->getNumExpansions();
8093 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008094 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8095 PatternTL.getSourceRange(),
8096 Unexpanded,
8097 Expand, RetainExpansion,
8098 NumExpansions))
8099 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
Douglas Gregor29c42f22012-02-24 07:38:34 +00008101 if (!Expand) {
8102 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008103 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008104 // expansion.
8105 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008106
Douglas Gregor29c42f22012-02-24 07:38:34 +00008107 TypeLocBuilder TLB;
8108 TLB.reserve(From->getTypeLoc().getFullDataSize());
8109
8110 QualType To = getDerived().TransformType(TLB, PatternTL);
8111 if (To.isNull())
8112 return ExprError();
8113
Chad Rosier1dcde962012-08-08 18:46:20 +00008114 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008115 PatternTL.getSourceRange(),
8116 ExpansionTL.getEllipsisLoc(),
8117 NumExpansions);
8118 if (To.isNull())
8119 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008120
Douglas Gregor29c42f22012-02-24 07:38:34 +00008121 PackExpansionTypeLoc ToExpansionTL
8122 = TLB.push<PackExpansionTypeLoc>(To);
8123 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8124 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8125 continue;
8126 }
8127
8128 // Expand the pack expansion by substituting for each argument in the
8129 // pack(s).
8130 for (unsigned I = 0; I != *NumExpansions; ++I) {
8131 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8132 TypeLocBuilder TLB;
8133 TLB.reserve(PatternTL.getFullDataSize());
8134 QualType To = getDerived().TransformType(TLB, PatternTL);
8135 if (To.isNull())
8136 return ExprError();
8137
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008138 if (To->containsUnexpandedParameterPack()) {
8139 To = getDerived().RebuildPackExpansionType(To,
8140 PatternTL.getSourceRange(),
8141 ExpansionTL.getEllipsisLoc(),
8142 NumExpansions);
8143 if (To.isNull())
8144 return ExprError();
8145
8146 PackExpansionTypeLoc ToExpansionTL
8147 = TLB.push<PackExpansionTypeLoc>(To);
8148 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8149 }
8150
Douglas Gregor29c42f22012-02-24 07:38:34 +00008151 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008153
Douglas Gregor29c42f22012-02-24 07:38:34 +00008154 if (!RetainExpansion)
8155 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008156
Douglas Gregor29c42f22012-02-24 07:38:34 +00008157 // If we're supposed to retain a pack expansion, do so by temporarily
8158 // forgetting the partially-substituted parameter pack.
8159 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8160
8161 TypeLocBuilder TLB;
8162 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008163
Douglas Gregor29c42f22012-02-24 07:38:34 +00008164 QualType To = getDerived().TransformType(TLB, PatternTL);
8165 if (To.isNull())
8166 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008167
8168 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008169 PatternTL.getSourceRange(),
8170 ExpansionTL.getEllipsisLoc(),
8171 NumExpansions);
8172 if (To.isNull())
8173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008174
Douglas Gregor29c42f22012-02-24 07:38:34 +00008175 PackExpansionTypeLoc ToExpansionTL
8176 = TLB.push<PackExpansionTypeLoc>(To);
8177 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8178 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008180
Douglas Gregor29c42f22012-02-24 07:38:34 +00008181 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008182 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008183
8184 return getDerived().RebuildTypeTrait(E->getTrait(),
8185 E->getLocStart(),
8186 Args,
8187 E->getLocEnd());
8188}
8189
8190template<typename Derived>
8191ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008192TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8193 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8194 if (!T)
8195 return ExprError();
8196
8197 if (!getDerived().AlwaysRebuild() &&
8198 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008199 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008200
8201 ExprResult SubExpr;
8202 {
8203 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8204 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8205 if (SubExpr.isInvalid())
8206 return ExprError();
8207
8208 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008209 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008210 }
8211
8212 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8213 E->getLocStart(),
8214 T,
8215 SubExpr.get(),
8216 E->getLocEnd());
8217}
8218
8219template<typename Derived>
8220ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008221TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8222 ExprResult SubExpr;
8223 {
8224 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8225 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8226 if (SubExpr.isInvalid())
8227 return ExprError();
8228
8229 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008230 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008231 }
8232
8233 return getDerived().RebuildExpressionTrait(
8234 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8235}
8236
8237template<typename Derived>
8238ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008239TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008240 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008241 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8242}
8243
8244template<typename Derived>
8245ExprResult
8246TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8247 DependentScopeDeclRefExpr *E,
8248 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008249 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008250 NestedNameSpecifierLoc QualifierLoc
8251 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8252 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008253 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008254 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008255
John McCall31f82722010-11-12 08:19:04 +00008256 // TODO: If this is a conversion-function-id, verify that the
8257 // destination type name (if present) resolves the same way after
8258 // instantiation as it did in the local scope.
8259
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008260 DeclarationNameInfo NameInfo
8261 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8262 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008264
John McCalle66edc12009-11-24 19:00:30 +00008265 if (!E->hasExplicitTemplateArgs()) {
8266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008267 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008268 // Note: it is sufficient to compare the Name component of NameInfo:
8269 // if name has not changed, DNLoc has not changed either.
8270 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008271 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008272
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008273 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00008274 TemplateKWLoc,
8275 NameInfo,
8276 /*TemplateArgs*/nullptr,
8277 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008278 }
John McCall6b51f282009-11-23 01:53:49 +00008279
8280 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008281 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8282 E->getNumTemplateArgs(),
8283 TransArgs))
8284 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008285
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008286 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008287 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008288 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008289 &TransArgs,
8290 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008291}
8292
8293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008295TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008296 // CXXConstructExprs other than for list-initialization and
8297 // CXXTemporaryObjectExpr are always implicit, so when we have
8298 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008299 if ((E->getNumArgs() == 1 ||
8300 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008301 (!getDerived().DropCallArgument(E->getArg(0))) &&
8302 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008303 return getDerived().TransformExpr(E->getArg(0));
8304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8306
8307 QualType T = getDerived().TransformType(E->getType());
8308 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008309 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008310
8311 CXXConstructorDecl *Constructor
8312 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008313 getDerived().TransformDecl(E->getLocStart(),
8314 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008317
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008319 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008320 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008321 &ArgumentChanged))
8322 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008323
Douglas Gregora16548e2009-08-11 05:31:07 +00008324 if (!getDerived().AlwaysRebuild() &&
8325 T == E->getType() &&
8326 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008327 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008328 // Mark the constructor as referenced.
8329 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008330 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008331 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008332 }
Mike Stump11289f42009-09-09 15:08:12 +00008333
Douglas Gregordb121ba2009-12-14 16:27:04 +00008334 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8335 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008336 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008337 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008338 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008339 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008340 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008341 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008342}
Mike Stump11289f42009-09-09 15:08:12 +00008343
Douglas Gregora16548e2009-08-11 05:31:07 +00008344/// \brief Transform a C++ temporary-binding expression.
8345///
Douglas Gregor363b1512009-12-24 18:51:59 +00008346/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8347/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008350TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008351 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008352}
Mike Stump11289f42009-09-09 15:08:12 +00008353
John McCall5d413782010-12-06 08:20:24 +00008354/// \brief Transform a C++ expression that contains cleanups that should
8355/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008356///
John McCall5d413782010-12-06 08:20:24 +00008357/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008358/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008360ExprResult
John McCall5d413782010-12-06 08:20:24 +00008361TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008362 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008363}
Mike Stump11289f42009-09-09 15:08:12 +00008364
Douglas Gregora16548e2009-08-11 05:31:07 +00008365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008366ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008367TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008368 CXXTemporaryObjectExpr *E) {
8369 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8370 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373 CXXConstructorDecl *Constructor
8374 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008375 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008376 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008377 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008379
Douglas Gregora16548e2009-08-11 05:31:07 +00008380 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008381 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008383 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008384 &ArgumentChanged))
8385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008386
Douglas Gregora16548e2009-08-11 05:31:07 +00008387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008388 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008389 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008390 !ArgumentChanged) {
8391 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008392 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008393 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008395
Richard Smithd59b8322012-12-19 01:39:02 +00008396 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008397 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8398 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008399 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008400 E->getLocEnd());
8401}
Mike Stump11289f42009-09-09 15:08:12 +00008402
Douglas Gregora16548e2009-08-11 05:31:07 +00008403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008404ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008405TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008406
8407 // Transform any init-capture expressions before entering the scope of the
8408 // lambda body, because they are not semantically within that scope.
8409 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8410 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8411 E->explicit_capture_begin());
8412
8413 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8414 CEnd = E->capture_end();
8415 C != CEnd; ++C) {
8416 if (!C->isInitCapture())
8417 continue;
8418 EnterExpressionEvaluationContext EEEC(getSema(),
8419 Sema::PotentiallyEvaluated);
8420 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8421 C->getCapturedVar()->getInit(),
8422 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8423
8424 if (NewExprInitResult.isInvalid())
8425 return ExprError();
8426 Expr *NewExprInit = NewExprInitResult.get();
8427
8428 VarDecl *OldVD = C->getCapturedVar();
8429 QualType NewInitCaptureType =
8430 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8431 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8432 NewExprInit);
8433 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008434 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8435 std::make_pair(NewExprInitResult, NewInitCaptureType);
8436
8437 }
8438
Faisal Vali524ca282013-11-12 01:40:44 +00008439 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008440 // Transform the template parameters, and add them to the current
8441 // instantiation scope. The null case is handled correctly.
8442 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8443 E->getTemplateParameterList());
8444
8445 // Check to see if the TypeSourceInfo of the call operator needs to
8446 // be transformed, and if so do the transformation in the
8447 // CurrentInstantiationScope.
8448
8449 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8450 FunctionProtoTypeLoc OldCallOpFPTL =
8451 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008452 TypeSourceInfo *NewCallOpTSI = nullptr;
8453
Faisal Vali2cba1332013-10-23 06:44:28 +00008454 const bool CallOpWasAlreadyTransformed =
8455 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8456
8457 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8458 if (CallOpWasAlreadyTransformed)
8459 NewCallOpTSI = OldCallOpTSI;
8460 else {
8461 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8462 // The transformation MUST be done in the CurrentInstantiationScope since
8463 // it introduces a mapping of the original to the newly created
8464 // transformed parameters.
8465
8466 TypeLocBuilder NewCallOpTLBuilder;
8467 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8468 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008469 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008470 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8471 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008472 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008473 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8474 // the vector below - this will be used to synthesize the
8475 // NewCallOperator. Additionally, add the parameters of the untransformed
8476 // lambda call operator to the CurrentInstantiationScope.
8477 SmallVector<ParmVarDecl *, 4> Params;
8478 {
8479 FunctionProtoTypeLoc NewCallOpFPTL =
8480 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8481 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008482 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008483
8484 for (unsigned I = 0; I < NewNumArgs; ++I) {
8485 // If this call operator's type does not require transformation,
8486 // the parameters do not get added to the current instantiation scope,
8487 // - so ADD them! This allows the following to compile when the enclosing
8488 // template is specialized and the entire lambda expression has to be
8489 // transformed.
8490 // template<class T> void foo(T t) {
8491 // auto L = [](auto a) {
8492 // auto M = [](char b) { <-- note: non-generic lambda
8493 // auto N = [](auto c) {
8494 // int x = sizeof(a);
8495 // x = sizeof(b); <-- specifically this line
8496 // x = sizeof(c);
8497 // };
8498 // };
8499 // };
8500 // }
8501 // foo('a')
8502 if (CallOpWasAlreadyTransformed)
8503 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8504 NewParamDeclArray[I]);
8505 // Add to Params array, so these parameters can be used to create
8506 // the newly transformed call operator.
8507 Params.push_back(NewParamDeclArray[I]);
8508 }
8509 }
8510
8511 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008512 return ExprError();
8513
Eli Friedmand564afb2012-09-19 01:18:11 +00008514 // Create the local class that will describe the lambda.
8515 CXXRecordDecl *Class
8516 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008517 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008518 /*KnownDependent=*/false,
8519 E->getCaptureDefault());
8520
Eli Friedmand564afb2012-09-19 01:18:11 +00008521 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8522
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008523 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008524 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008525 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008526 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008527 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008528 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008529 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008530
Faisal Vali2cba1332013-10-23 06:44:28 +00008531 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8532
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008533 return getDerived().TransformLambdaScope(E, NewCallOperator,
8534 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008535}
8536
8537template<typename Derived>
8538ExprResult
8539TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008540 CXXMethodDecl *CallOperator,
8541 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008542 bool Invalid = false;
8543
Douglas Gregorb4328232012-02-14 00:00:48 +00008544 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008545 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8546 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008547
Faisal Vali2b391ab2013-09-26 19:54:12 +00008548 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008549 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008550 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008551 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008552 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008553 E->hasExplicitParameters(),
8554 E->hasExplicitResultType(),
8555 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008556
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008557 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008558 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008559 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008560 CEnd = E->capture_end();
8561 C != CEnd; ++C) {
8562 // When we hit the first implicit capture, tell Sema that we've finished
8563 // the list of explicit captures.
8564 if (!FinishedExplicitCaptures && C->isImplicit()) {
8565 getSema().finishLambdaExplicitCaptures(LSI);
8566 FinishedExplicitCaptures = true;
8567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008568
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008569 // Capturing 'this' is trivial.
8570 if (C->capturesThis()) {
8571 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8572 continue;
8573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008574
Richard Smithba71c082013-05-16 06:20:58 +00008575 // Rebuild init-captures, including the implied field declaration.
8576 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008577
8578 InitCaptureInfoTy InitExprTypePair =
8579 InitCaptureExprsAndTypes[C - E->capture_begin()];
8580 ExprResult Init = InitExprTypePair.first;
8581 QualType InitQualType = InitExprTypePair.second;
8582 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008583 Invalid = true;
8584 continue;
8585 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008586 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008587 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8588 OldVD->getLocation(), InitExprTypePair.second,
8589 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008590 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008591 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008592 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008593 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008594 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008595 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008596 continue;
8597 }
8598
8599 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8600
Douglas Gregor3e308b12012-02-14 19:27:52 +00008601 // Determine the capture kind for Sema.
8602 Sema::TryCaptureKind Kind
8603 = C->isImplicit()? Sema::TryCapture_Implicit
8604 : C->getCaptureKind() == LCK_ByCopy
8605 ? Sema::TryCapture_ExplicitByVal
8606 : Sema::TryCapture_ExplicitByRef;
8607 SourceLocation EllipsisLoc;
8608 if (C->isPackExpansion()) {
8609 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8610 bool ShouldExpand = false;
8611 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008612 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008613 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8614 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008615 Unexpanded,
8616 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008617 NumExpansions)) {
8618 Invalid = true;
8619 continue;
8620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008621
Douglas Gregor3e308b12012-02-14 19:27:52 +00008622 if (ShouldExpand) {
8623 // The transform has determined that we should perform an expansion;
8624 // transform and capture each of the arguments.
8625 // expansion of the pattern. Do so.
8626 VarDecl *Pack = C->getCapturedVar();
8627 for (unsigned I = 0; I != *NumExpansions; ++I) {
8628 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8629 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008630 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008631 Pack));
8632 if (!CapturedVar) {
8633 Invalid = true;
8634 continue;
8635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008636
Douglas Gregor3e308b12012-02-14 19:27:52 +00008637 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008638 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8639 }
Richard Smith9467be42014-06-06 17:33:35 +00008640
8641 // FIXME: Retain a pack expansion if RetainExpansion is true.
8642
Douglas Gregor3e308b12012-02-14 19:27:52 +00008643 continue;
8644 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008645
Douglas Gregor3e308b12012-02-14 19:27:52 +00008646 EllipsisLoc = C->getEllipsisLoc();
8647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008648
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008649 // Transform the captured variable.
8650 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008651 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008652 C->getCapturedVar()));
8653 if (!CapturedVar) {
8654 Invalid = true;
8655 continue;
8656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008657
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008658 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008659 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008660 }
8661 if (!FinishedExplicitCaptures)
8662 getSema().finishLambdaExplicitCaptures(LSI);
8663
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008664
8665 // Enter a new evaluation context to insulate the lambda from any
8666 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008667 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008668
8669 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008670 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008671 /*IsInstantiation=*/true);
8672 return ExprError();
8673 }
8674
8675 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008676 StmtResult Body = getDerived().TransformStmt(E->getBody());
8677 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008678 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008679 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008680 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008681 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008682
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008683 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008684 /*CurScope=*/nullptr,
8685 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008686}
8687
8688template<typename Derived>
8689ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008690TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008691 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008692 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8693 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008695
Douglas Gregora16548e2009-08-11 05:31:07 +00008696 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008697 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008698 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008699 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008700 &ArgumentChanged))
8701 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008702
Douglas Gregora16548e2009-08-11 05:31:07 +00008703 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008704 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008705 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008706 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008707
Douglas Gregora16548e2009-08-11 05:31:07 +00008708 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008709 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008711 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008712 E->getRParenLoc());
8713}
Mike Stump11289f42009-09-09 15:08:12 +00008714
Douglas Gregora16548e2009-08-11 05:31:07 +00008715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008716ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008717TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008718 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008719 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008720 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008721 Expr *OldBase;
8722 QualType BaseType;
8723 QualType ObjectType;
8724 if (!E->isImplicitAccess()) {
8725 OldBase = E->getBase();
8726 Base = getDerived().TransformExpr(OldBase);
8727 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008729
John McCall2d74de92009-12-01 22:10:20 +00008730 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008731 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008732 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008733 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008734 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008735 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008736 ObjectTy,
8737 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008738 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008739 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008740
John McCallba7bf592010-08-24 05:47:05 +00008741 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008742 BaseType = ((Expr*) Base.get())->getType();
8743 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008744 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008745 BaseType = getDerived().TransformType(E->getBaseType());
8746 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8747 }
Mike Stump11289f42009-09-09 15:08:12 +00008748
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008749 // Transform the first part of the nested-name-specifier that qualifies
8750 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008751 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008752 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008753 E->getFirstQualifierFoundInScope(),
8754 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008755
Douglas Gregore16af532011-02-28 18:50:33 +00008756 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008757 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008758 QualifierLoc
8759 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8760 ObjectType,
8761 FirstQualifierInScope);
8762 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008763 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008764 }
Mike Stump11289f42009-09-09 15:08:12 +00008765
Abramo Bagnara7945c982012-01-27 09:46:47 +00008766 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8767
John McCall31f82722010-11-12 08:19:04 +00008768 // TODO: If this is a conversion-function-id, verify that the
8769 // destination type name (if present) resolves the same way after
8770 // instantiation as it did in the local scope.
8771
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008772 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008773 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008774 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008776
John McCall2d74de92009-12-01 22:10:20 +00008777 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008778 // This is a reference to a member without an explicitly-specified
8779 // template argument list. Optimize for this common case.
8780 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008781 Base.get() == OldBase &&
8782 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008783 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008784 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008785 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008786 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008787
John McCallb268a282010-08-23 23:25:46 +00008788 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008789 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008790 E->isArrow(),
8791 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008792 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008793 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008794 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008795 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008796 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008797 }
8798
John McCall6b51f282009-11-23 01:53:49 +00008799 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008800 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8801 E->getNumTemplateArgs(),
8802 TransArgs))
8803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008804
John McCallb268a282010-08-23 23:25:46 +00008805 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008806 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 E->isArrow(),
8808 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008809 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008810 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008811 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008812 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008813 &TransArgs);
8814}
8815
8816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008818TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008819 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008820 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008821 QualType BaseType;
8822 if (!Old->isImplicitAccess()) {
8823 Base = getDerived().TransformExpr(Old->getBase());
8824 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008825 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008826 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008827 Old->isArrow());
8828 if (Base.isInvalid())
8829 return ExprError();
8830 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008831 } else {
8832 BaseType = getDerived().TransformType(Old->getBaseType());
8833 }
John McCall10eae182009-11-30 22:42:35 +00008834
Douglas Gregor0da1d432011-02-28 20:01:57 +00008835 NestedNameSpecifierLoc QualifierLoc;
8836 if (Old->getQualifierLoc()) {
8837 QualifierLoc
8838 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8839 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008840 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008841 }
8842
Abramo Bagnara7945c982012-01-27 09:46:47 +00008843 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8844
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008845 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008846 Sema::LookupOrdinaryName);
8847
8848 // Transform all the decls.
8849 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8850 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008851 NamedDecl *InstD = static_cast<NamedDecl*>(
8852 getDerived().TransformDecl(Old->getMemberLoc(),
8853 *I));
John McCall84d87672009-12-10 09:41:52 +00008854 if (!InstD) {
8855 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8856 // This can happen because of dependent hiding.
8857 if (isa<UsingShadowDecl>(*I))
8858 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008859 else {
8860 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008861 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008862 }
John McCall84d87672009-12-10 09:41:52 +00008863 }
John McCall10eae182009-11-30 22:42:35 +00008864
8865 // Expand using declarations.
8866 if (isa<UsingDecl>(InstD)) {
8867 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008868 for (auto *I : UD->shadows())
8869 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008870 continue;
8871 }
8872
8873 R.addDecl(InstD);
8874 }
8875
8876 R.resolveKind();
8877
Douglas Gregor9262f472010-04-27 18:19:34 +00008878 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008879 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008880 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008881 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008882 Old->getMemberLoc(),
8883 Old->getNamingClass()));
8884 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008885 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008886
Douglas Gregorda7be082010-04-27 16:10:10 +00008887 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008889
John McCall10eae182009-11-30 22:42:35 +00008890 TemplateArgumentListInfo TransArgs;
8891 if (Old->hasExplicitTemplateArgs()) {
8892 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8893 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008894 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8895 Old->getNumTemplateArgs(),
8896 TransArgs))
8897 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008898 }
John McCall38836f02010-01-15 08:34:02 +00008899
8900 // FIXME: to do this check properly, we will need to preserve the
8901 // first-qualifier-in-scope here, just in case we had a dependent
8902 // base (and therefore couldn't do the check) and a
8903 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008904 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
John McCallb268a282010-08-23 23:25:46 +00008906 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008907 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008908 Old->getOperatorLoc(),
8909 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008910 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008911 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008912 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008913 R,
8914 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008915 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008916}
8917
8918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008919ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008920TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008921 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008922 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8923 if (SubExpr.isInvalid())
8924 return ExprError();
8925
8926 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008927 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008928
8929 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8930}
8931
8932template<typename Derived>
8933ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008934TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008935 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8936 if (Pattern.isInvalid())
8937 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008938
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008939 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008940 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008941
Douglas Gregorb8840002011-01-14 21:20:45 +00008942 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8943 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008944}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008945
8946template<typename Derived>
8947ExprResult
8948TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8949 // If E is not value-dependent, then nothing will change when we transform it.
8950 // Note: This is an instantiation-centric view.
8951 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008952 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008953
8954 // Note: None of the implementations of TryExpandParameterPacks can ever
8955 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008956 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008957 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8958 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008959 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008960 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008961 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008962 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008963 ShouldExpand, RetainExpansion,
8964 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008965 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008966
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008967 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008968 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008969
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008970 NamedDecl *Pack = E->getPack();
8971 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008972 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008973 Pack));
8974 if (!Pack)
8975 return ExprError();
8976 }
8977
Chad Rosier1dcde962012-08-08 18:46:20 +00008978
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008979 // We now know the length of the parameter pack, so build a new expression
8980 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008981 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8982 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008983 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008984}
8985
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008986template<typename Derived>
8987ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008988TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8989 SubstNonTypeTemplateParmPackExpr *E) {
8990 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008991 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008992}
8993
8994template<typename Derived>
8995ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008996TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8997 SubstNonTypeTemplateParmExpr *E) {
8998 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008999 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009000}
9001
9002template<typename Derived>
9003ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009004TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9005 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009006 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009007}
9008
9009template<typename Derived>
9010ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009011TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9012 MaterializeTemporaryExpr *E) {
9013 return getDerived().TransformExpr(E->GetTemporaryExpr());
9014}
Chad Rosier1dcde962012-08-08 18:46:20 +00009015
Douglas Gregorfe314812011-06-21 17:03:29 +00009016template<typename Derived>
9017ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009018TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9019 CXXStdInitializerListExpr *E) {
9020 return getDerived().TransformExpr(E->getSubExpr());
9021}
9022
9023template<typename Derived>
9024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009025TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009026 return SemaRef.MaybeBindToTemporary(E);
9027}
9028
9029template<typename Derived>
9030ExprResult
9031TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009032 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009033}
9034
9035template<typename Derived>
9036ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009037TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9038 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9039 if (SubExpr.isInvalid())
9040 return ExprError();
9041
9042 if (!getDerived().AlwaysRebuild() &&
9043 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009044 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009045
9046 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009047}
9048
9049template<typename Derived>
9050ExprResult
9051TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9052 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009053 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009054 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009055 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009056 /*IsCall=*/false, Elements, &ArgChanged))
9057 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009058
Ted Kremeneke65b0862012-03-06 20:05:56 +00009059 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9060 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009061
Ted Kremeneke65b0862012-03-06 20:05:56 +00009062 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9063 Elements.data(),
9064 Elements.size());
9065}
9066
9067template<typename Derived>
9068ExprResult
9069TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009071 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009072 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009073 bool ArgChanged = false;
9074 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9075 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009076
Ted Kremeneke65b0862012-03-06 20:05:56 +00009077 if (OrigElement.isPackExpansion()) {
9078 // This key/value element is a pack expansion.
9079 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9080 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9081 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9082 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9083
9084 // Determine whether the set of unexpanded parameter packs can
9085 // and should be expanded.
9086 bool Expand = true;
9087 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009088 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9089 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009090 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9091 OrigElement.Value->getLocEnd());
9092 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9093 PatternRange,
9094 Unexpanded,
9095 Expand, RetainExpansion,
9096 NumExpansions))
9097 return ExprError();
9098
9099 if (!Expand) {
9100 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009101 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009102 // expansion.
9103 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9104 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9105 if (Key.isInvalid())
9106 return ExprError();
9107
9108 if (Key.get() != OrigElement.Key)
9109 ArgChanged = true;
9110
9111 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9112 if (Value.isInvalid())
9113 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009114
Ted Kremeneke65b0862012-03-06 20:05:56 +00009115 if (Value.get() != OrigElement.Value)
9116 ArgChanged = true;
9117
Chad Rosier1dcde962012-08-08 18:46:20 +00009118 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009119 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9120 };
9121 Elements.push_back(Expansion);
9122 continue;
9123 }
9124
9125 // Record right away that the argument was changed. This needs
9126 // to happen even if the array expands to nothing.
9127 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009128
Ted Kremeneke65b0862012-03-06 20:05:56 +00009129 // The transform has determined that we should perform an elementwise
9130 // expansion of the pattern. Do so.
9131 for (unsigned I = 0; I != *NumExpansions; ++I) {
9132 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9133 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9134 if (Key.isInvalid())
9135 return ExprError();
9136
9137 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9138 if (Value.isInvalid())
9139 return ExprError();
9140
Chad Rosier1dcde962012-08-08 18:46:20 +00009141 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009142 Key.get(), Value.get(), SourceLocation(), NumExpansions
9143 };
9144
9145 // If any unexpanded parameter packs remain, we still have a
9146 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009147 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009148 if (Key.get()->containsUnexpandedParameterPack() ||
9149 Value.get()->containsUnexpandedParameterPack())
9150 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009151
Ted Kremeneke65b0862012-03-06 20:05:56 +00009152 Elements.push_back(Element);
9153 }
9154
Richard Smith9467be42014-06-06 17:33:35 +00009155 // FIXME: Retain a pack expansion if RetainExpansion is true.
9156
Ted Kremeneke65b0862012-03-06 20:05:56 +00009157 // We've finished with this pack expansion.
9158 continue;
9159 }
9160
9161 // Transform and check key.
9162 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9163 if (Key.isInvalid())
9164 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009165
Ted Kremeneke65b0862012-03-06 20:05:56 +00009166 if (Key.get() != OrigElement.Key)
9167 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009168
Ted Kremeneke65b0862012-03-06 20:05:56 +00009169 // Transform and check value.
9170 ExprResult Value
9171 = getDerived().TransformExpr(OrigElement.Value);
9172 if (Value.isInvalid())
9173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009174
Ted Kremeneke65b0862012-03-06 20:05:56 +00009175 if (Value.get() != OrigElement.Value)
9176 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009177
9178 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009179 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009180 };
9181 Elements.push_back(Element);
9182 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
Ted Kremeneke65b0862012-03-06 20:05:56 +00009184 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9185 return SemaRef.MaybeBindToTemporary(E);
9186
9187 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9188 Elements.data(),
9189 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009190}
9191
Mike Stump11289f42009-09-09 15:08:12 +00009192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009194TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009195 TypeSourceInfo *EncodedTypeInfo
9196 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9197 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009199
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009201 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009202 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009203
9204 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009205 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009206 E->getRParenLoc());
9207}
Mike Stump11289f42009-09-09 15:08:12 +00009208
Douglas Gregora16548e2009-08-11 05:31:07 +00009209template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009210ExprResult TreeTransform<Derived>::
9211TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009212 // This is a kind of implicit conversion, and it needs to get dropped
9213 // and recomputed for the same general reasons that ImplicitCastExprs
9214 // do, as well a more specific one: this expression is only valid when
9215 // it appears *immediately* as an argument expression.
9216 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009217}
9218
9219template<typename Derived>
9220ExprResult TreeTransform<Derived>::
9221TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009222 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009223 = getDerived().TransformType(E->getTypeInfoAsWritten());
9224 if (!TSInfo)
9225 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009226
John McCall31168b02011-06-15 23:02:42 +00009227 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009228 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009229 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009230
John McCall31168b02011-06-15 23:02:42 +00009231 if (!getDerived().AlwaysRebuild() &&
9232 TSInfo == E->getTypeInfoAsWritten() &&
9233 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009235
John McCall31168b02011-06-15 23:02:42 +00009236 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009237 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009238 Result.get());
9239}
9240
9241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009243TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009244 // Transform arguments.
9245 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009246 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009247 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009248 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009249 &ArgChanged))
9250 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009252 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9253 // Class message: transform the receiver type.
9254 TypeSourceInfo *ReceiverTypeInfo
9255 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9256 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009257 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009258
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009259 // If nothing changed, just retain the existing message send.
9260 if (!getDerived().AlwaysRebuild() &&
9261 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009262 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009263
9264 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009265 SmallVector<SourceLocation, 16> SelLocs;
9266 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009267 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9268 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009269 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009270 E->getMethodDecl(),
9271 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009272 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009273 E->getRightLoc());
9274 }
9275
9276 // Instance message: transform the receiver
9277 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9278 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009279 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009280 = getDerived().TransformExpr(E->getInstanceReceiver());
9281 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009282 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009283
9284 // If nothing changed, just retain the existing message send.
9285 if (!getDerived().AlwaysRebuild() &&
9286 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009287 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009288
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009289 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009290 SmallVector<SourceLocation, 16> SelLocs;
9291 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009292 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009293 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009294 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009295 E->getMethodDecl(),
9296 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009297 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009298 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009299}
9300
Mike Stump11289f42009-09-09 15:08:12 +00009301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009303TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009304 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009305}
9306
Mike Stump11289f42009-09-09 15:08:12 +00009307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009309TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009310 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009311}
9312
Mike Stump11289f42009-09-09 15:08:12 +00009313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009314ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009315TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009316 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009317 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009318 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009319 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009320
9321 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009322
Douglas Gregord51d90d2010-04-26 20:11:03 +00009323 // If nothing changed, just retain the existing expression.
9324 if (!getDerived().AlwaysRebuild() &&
9325 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009326 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009327
John McCallb268a282010-08-23 23:25:46 +00009328 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009329 E->getLocation(),
9330 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009331}
9332
Mike Stump11289f42009-09-09 15:08:12 +00009333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009335TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009336 // 'super' and types never change. Property never changes. Just
9337 // retain the existing expression.
9338 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009339 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009340
Douglas Gregor9faee212010-04-26 20:47:02 +00009341 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009342 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009343 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009345
Douglas Gregor9faee212010-04-26 20:47:02 +00009346 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009347
Douglas Gregor9faee212010-04-26 20:47:02 +00009348 // If nothing changed, just retain the existing expression.
9349 if (!getDerived().AlwaysRebuild() &&
9350 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009351 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009352
John McCallb7bd14f2010-12-02 01:19:52 +00009353 if (E->isExplicitProperty())
9354 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9355 E->getExplicitProperty(),
9356 E->getLocation());
9357
9358 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009359 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009360 E->getImplicitPropertyGetter(),
9361 E->getImplicitPropertySetter(),
9362 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009363}
9364
Mike Stump11289f42009-09-09 15:08:12 +00009365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009366ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009367TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9368 // Transform the base expression.
9369 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9370 if (Base.isInvalid())
9371 return ExprError();
9372
9373 // Transform the key expression.
9374 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9375 if (Key.isInvalid())
9376 return ExprError();
9377
9378 // If nothing changed, just retain the existing expression.
9379 if (!getDerived().AlwaysRebuild() &&
9380 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009381 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009382
Chad Rosier1dcde962012-08-08 18:46:20 +00009383 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009384 Base.get(), Key.get(),
9385 E->getAtIndexMethodDecl(),
9386 E->setAtIndexMethodDecl());
9387}
9388
9389template<typename Derived>
9390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009391TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009392 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009393 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009394 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009395 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009396
Douglas Gregord51d90d2010-04-26 20:11:03 +00009397 // If nothing changed, just retain the existing expression.
9398 if (!getDerived().AlwaysRebuild() &&
9399 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009400 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009401
John McCallb268a282010-08-23 23:25:46 +00009402 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009403 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009404 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009405}
9406
Mike Stump11289f42009-09-09 15:08:12 +00009407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009408ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009409TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009411 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009412 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009413 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009414 SubExprs, &ArgumentChanged))
9415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009416
Douglas Gregora16548e2009-08-11 05:31:07 +00009417 if (!getDerived().AlwaysRebuild() &&
9418 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009419 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009420
Douglas Gregora16548e2009-08-11 05:31:07 +00009421 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009422 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009423 E->getRParenLoc());
9424}
9425
Mike Stump11289f42009-09-09 15:08:12 +00009426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009427ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009428TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9429 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9430 if (SrcExpr.isInvalid())
9431 return ExprError();
9432
9433 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9434 if (!Type)
9435 return ExprError();
9436
9437 if (!getDerived().AlwaysRebuild() &&
9438 Type == E->getTypeSourceInfo() &&
9439 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009440 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009441
9442 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9443 SrcExpr.get(), Type,
9444 E->getRParenLoc());
9445}
9446
9447template<typename Derived>
9448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009449TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009450 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009451
Craig Topperc3ec1492014-05-26 06:22:03 +00009452 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009453 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9454
9455 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009456 blockScope->TheDecl->setBlockMissingReturnType(
9457 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009458
Chris Lattner01cf8db2011-07-20 06:58:45 +00009459 SmallVector<ParmVarDecl*, 4> params;
9460 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009461
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009462 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009463 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9464 oldBlock->param_begin(),
9465 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009466 nullptr, paramTypes, &params)) {
9467 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009468 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009469 }
John McCall490112f2011-02-04 18:33:18 +00009470
Jordan Rosea0a86be2013-03-08 22:25:36 +00009471 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009472 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009473 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009474
Jordan Rose5c382722013-03-08 21:51:21 +00009475 QualType functionType =
9476 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009477 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009478 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009479
9480 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009481 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009482 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009483
9484 if (!oldBlock->blockMissingReturnType()) {
9485 blockScope->HasImplicitReturnType = false;
9486 blockScope->ReturnType = exprResultType;
9487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009488
John McCall3882ace2011-01-05 12:14:39 +00009489 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009490 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009491 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009492 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009493 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009494 }
John McCall3882ace2011-01-05 12:14:39 +00009495
John McCall490112f2011-02-04 18:33:18 +00009496#ifndef NDEBUG
9497 // In builds with assertions, make sure that we captured everything we
9498 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009499 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009500 for (const auto &I : oldBlock->captures()) {
9501 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009502
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009503 // Ignore parameter packs.
9504 if (isa<ParmVarDecl>(oldCapture) &&
9505 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9506 continue;
John McCall490112f2011-02-04 18:33:18 +00009507
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009508 VarDecl *newCapture =
9509 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9510 oldCapture));
9511 assert(blockScope->CaptureMap.count(newCapture));
9512 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009513 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009514 }
9515#endif
9516
9517 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009518 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009519}
9520
Mike Stump11289f42009-09-09 15:08:12 +00009521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009522ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009523TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009524 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009525}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009526
9527template<typename Derived>
9528ExprResult
9529TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009530 QualType RetTy = getDerived().TransformType(E->getType());
9531 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009532 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009533 SubExprs.reserve(E->getNumSubExprs());
9534 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9535 SubExprs, &ArgumentChanged))
9536 return ExprError();
9537
9538 if (!getDerived().AlwaysRebuild() &&
9539 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009540 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009541
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009542 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009543 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009544}
Chad Rosier1dcde962012-08-08 18:46:20 +00009545
Douglas Gregora16548e2009-08-11 05:31:07 +00009546//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547// Type reconstruction
9548//===----------------------------------------------------------------------===//
9549
Mike Stump11289f42009-09-09 15:08:12 +00009550template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009551QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9552 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009553 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009554 getDerived().getBaseEntity());
9555}
9556
Mike Stump11289f42009-09-09 15:08:12 +00009557template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009558QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9559 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009560 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009561 getDerived().getBaseEntity());
9562}
9563
Mike Stump11289f42009-09-09 15:08:12 +00009564template<typename Derived>
9565QualType
John McCall70dd5f62009-10-30 00:06:24 +00009566TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9567 bool WrittenAsLValue,
9568 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009569 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009570 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009571}
9572
9573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009574QualType
John McCall70dd5f62009-10-30 00:06:24 +00009575TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9576 QualType ClassType,
9577 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009578 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9579 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009580}
9581
9582template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009583QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009584TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9585 ArrayType::ArraySizeModifier SizeMod,
9586 const llvm::APInt *Size,
9587 Expr *SizeExpr,
9588 unsigned IndexTypeQuals,
9589 SourceRange BracketsRange) {
9590 if (SizeExpr || !Size)
9591 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9592 IndexTypeQuals, BracketsRange,
9593 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009594
9595 QualType Types[] = {
9596 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9597 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9598 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009599 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009600 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009601 QualType SizeType;
9602 for (unsigned I = 0; I != NumTypes; ++I)
9603 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9604 SizeType = Types[I];
9605 break;
9606 }
Mike Stump11289f42009-09-09 15:08:12 +00009607
Eli Friedman9562f392012-01-25 23:20:27 +00009608 // Note that we can return a VariableArrayType here in the case where
9609 // the element type was a dependent VariableArrayType.
9610 IntegerLiteral *ArraySize
9611 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9612 /*FIXME*/BracketsRange.getBegin());
9613 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009614 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009615 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009616}
Mike Stump11289f42009-09-09 15:08:12 +00009617
Douglas Gregord6ff3322009-08-04 16:50:30 +00009618template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009619QualType
9620TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009621 ArrayType::ArraySizeModifier SizeMod,
9622 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009623 unsigned IndexTypeQuals,
9624 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009625 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009626 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009627}
9628
9629template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009630QualType
Mike Stump11289f42009-09-09 15:08:12 +00009631TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009632 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009633 unsigned IndexTypeQuals,
9634 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009635 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009636 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009637}
Mike Stump11289f42009-09-09 15:08:12 +00009638
Douglas Gregord6ff3322009-08-04 16:50:30 +00009639template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009640QualType
9641TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009642 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009643 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009644 unsigned IndexTypeQuals,
9645 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009646 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009647 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009648 IndexTypeQuals, BracketsRange);
9649}
9650
9651template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009652QualType
9653TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009654 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009655 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009656 unsigned IndexTypeQuals,
9657 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009658 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009659 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009660 IndexTypeQuals, BracketsRange);
9661}
9662
9663template<typename Derived>
9664QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009665 unsigned NumElements,
9666 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009667 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009668 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009669}
Mike Stump11289f42009-09-09 15:08:12 +00009670
Douglas Gregord6ff3322009-08-04 16:50:30 +00009671template<typename Derived>
9672QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9673 unsigned NumElements,
9674 SourceLocation AttributeLoc) {
9675 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9676 NumElements, true);
9677 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009678 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9679 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009680 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009681}
Mike Stump11289f42009-09-09 15:08:12 +00009682
Douglas Gregord6ff3322009-08-04 16:50:30 +00009683template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009684QualType
9685TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009686 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009687 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009688 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009689}
Mike Stump11289f42009-09-09 15:08:12 +00009690
Douglas Gregord6ff3322009-08-04 16:50:30 +00009691template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009692QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9693 QualType T,
9694 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009695 const FunctionProtoType::ExtProtoInfo &EPI) {
9696 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009697 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009698 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009699 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009700}
Mike Stump11289f42009-09-09 15:08:12 +00009701
Douglas Gregord6ff3322009-08-04 16:50:30 +00009702template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009703QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9704 return SemaRef.Context.getFunctionNoProtoType(T);
9705}
9706
9707template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009708QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9709 assert(D && "no decl found");
9710 if (D->isInvalidDecl()) return QualType();
9711
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009712 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009713 TypeDecl *Ty;
9714 if (isa<UsingDecl>(D)) {
9715 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009716 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009717 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9718
9719 // A valid resolved using typename decl points to exactly one type decl.
9720 assert(++Using->shadow_begin() == Using->shadow_end());
9721 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009722
John McCallb96ec562009-12-04 22:46:56 +00009723 } else {
9724 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9725 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9726 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9727 }
9728
9729 return SemaRef.Context.getTypeDeclType(Ty);
9730}
9731
9732template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009733QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9734 SourceLocation Loc) {
9735 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009736}
9737
9738template<typename Derived>
9739QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9740 return SemaRef.Context.getTypeOfType(Underlying);
9741}
9742
9743template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009744QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9745 SourceLocation Loc) {
9746 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009747}
9748
9749template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009750QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9751 UnaryTransformType::UTTKind UKind,
9752 SourceLocation Loc) {
9753 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9754}
9755
9756template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009757QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009758 TemplateName Template,
9759 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009760 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009761 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009762}
Mike Stump11289f42009-09-09 15:08:12 +00009763
Douglas Gregor1135c352009-08-06 05:28:30 +00009764template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009765QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9766 SourceLocation KWLoc) {
9767 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9768}
9769
9770template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009771TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009772TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009773 bool TemplateKW,
9774 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009775 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009776 Template);
9777}
9778
9779template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009780TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009781TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9782 const IdentifierInfo &Name,
9783 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009784 QualType ObjectType,
9785 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009786 UnqualifiedId TemplateName;
9787 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009788 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009789 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009790 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009791 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009792 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009793 /*EnteringContext=*/false,
9794 Template);
John McCall31f82722010-11-12 08:19:04 +00009795 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009796}
Mike Stump11289f42009-09-09 15:08:12 +00009797
Douglas Gregora16548e2009-08-11 05:31:07 +00009798template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009799TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009800TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009801 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009802 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009803 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009804 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009805 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009806 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009807 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009808 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009809 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009810 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009811 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009812 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009813 /*EnteringContext=*/false,
9814 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009815 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009816}
Chad Rosier1dcde962012-08-08 18:46:20 +00009817
Douglas Gregor71395fa2009-11-04 00:56:37 +00009818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009819ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009820TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9821 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009822 Expr *OrigCallee,
9823 Expr *First,
9824 Expr *Second) {
9825 Expr *Callee = OrigCallee->IgnoreParenCasts();
9826 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009827
Douglas Gregora16548e2009-08-11 05:31:07 +00009828 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009829 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009830 if (!First->getType()->isOverloadableType() &&
9831 !Second->getType()->isOverloadableType())
9832 return getSema().CreateBuiltinArraySubscriptExpr(First,
9833 Callee->getLocStart(),
9834 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009835 } else if (Op == OO_Arrow) {
9836 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009837 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9838 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009839 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009840 // The argument is not of overloadable type, so try to create a
9841 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009842 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009843 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009844
John McCallb268a282010-08-23 23:25:46 +00009845 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009846 }
9847 } else {
John McCallb268a282010-08-23 23:25:46 +00009848 if (!First->getType()->isOverloadableType() &&
9849 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009850 // Neither of the arguments is an overloadable type, so try to
9851 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009852 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009853 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009854 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009855 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009857
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009858 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 }
9860 }
Mike Stump11289f42009-09-09 15:08:12 +00009861
9862 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009864 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009865
John McCallb268a282010-08-23 23:25:46 +00009866 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009867 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009868 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009869 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009870 // If we've resolved this to a particular non-member function, just call
9871 // that function. If we resolved it to a member function,
9872 // CreateOverloaded* will find that function for us.
9873 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9874 if (!isa<CXXMethodDecl>(ND))
9875 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009876 }
Mike Stump11289f42009-09-09 15:08:12 +00009877
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009879 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009880 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009881
Douglas Gregora16548e2009-08-11 05:31:07 +00009882 // Create the overloaded operator invocation for unary operators.
9883 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009884 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009885 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009886 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009887 }
Mike Stump11289f42009-09-09 15:08:12 +00009888
Douglas Gregore9d62932011-07-15 16:25:15 +00009889 if (Op == OO_Subscript) {
9890 SourceLocation LBrace;
9891 SourceLocation RBrace;
9892
9893 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9894 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9895 LBrace = SourceLocation::getFromRawEncoding(
9896 NameLoc.CXXOperatorName.BeginOpNameLoc);
9897 RBrace = SourceLocation::getFromRawEncoding(
9898 NameLoc.CXXOperatorName.EndOpNameLoc);
9899 } else {
9900 LBrace = Callee->getLocStart();
9901 RBrace = OpLoc;
9902 }
9903
9904 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9905 First, Second);
9906 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009907
Douglas Gregora16548e2009-08-11 05:31:07 +00009908 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009909 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009910 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009911 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9912 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009914
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009915 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009916}
Mike Stump11289f42009-09-09 15:08:12 +00009917
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009918template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009919ExprResult
John McCallb268a282010-08-23 23:25:46 +00009920TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009921 SourceLocation OperatorLoc,
9922 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009923 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009924 TypeSourceInfo *ScopeType,
9925 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009926 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009927 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009928 QualType BaseType = Base->getType();
9929 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009930 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009931 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009932 !BaseType->getAs<PointerType>()->getPointeeType()
9933 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009934 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009935 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009936 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009937 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009938 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009939 /*FIXME?*/true);
9940 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009941
Douglas Gregor678f90d2010-02-25 01:56:36 +00009942 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009943 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9944 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9945 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9946 NameInfo.setNamedTypeInfo(DestroyedType);
9947
Richard Smith8e4a3862012-05-15 06:15:11 +00009948 // The scope type is now known to be a valid nested name specifier
9949 // component. Tack it on to the end of the nested name specifier.
9950 if (ScopeType)
9951 SS.Extend(SemaRef.Context, SourceLocation(),
9952 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009953
Abramo Bagnara7945c982012-01-27 09:46:47 +00009954 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009955 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009956 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009957 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009958 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009959 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009960 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009961}
9962
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009963template<typename Derived>
9964StmtResult
9965TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009966 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +00009967 CapturedDecl *CD = S->getCapturedDecl();
9968 unsigned NumParams = CD->getNumParams();
9969 unsigned ContextParamPos = CD->getContextParamPosition();
9970 SmallVector<Sema::CapturedParamNameType, 4> Params;
9971 for (unsigned I = 0; I < NumParams; ++I) {
9972 if (I != ContextParamPos) {
9973 Params.push_back(
9974 std::make_pair(
9975 CD->getParam(I)->getName(),
9976 getDerived().TransformType(CD->getParam(I)->getType())));
9977 } else {
9978 Params.push_back(std::make_pair(StringRef(), QualType()));
9979 }
9980 }
Craig Topperc3ec1492014-05-26 06:22:03 +00009981 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +00009982 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +00009983 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9984
9985 if (Body.isInvalid()) {
9986 getSema().ActOnCapturedRegionError();
9987 return StmtError();
9988 }
9989
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009990 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009991}
9992
Douglas Gregord6ff3322009-08-04 16:50:30 +00009993} // end namespace clang
9994
9995#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H