blob: ac31da2a1e647e7a2890b6b827e3202a527eee1d [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 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// 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 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// 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 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// 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 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// 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 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// 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 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// 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 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// 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 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001397 /// \brief Build a new OpenMP 'shared' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001401 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexander Musman8dba6642014-04-22 13:09:42 +00001409 /// \brief Build a new OpenMP 'linear' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new statement.
1412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1414 SourceLocation StartLoc,
1415 SourceLocation LParenLoc,
1416 SourceLocation ColonLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1419 ColonLoc, EndLoc);
1420 }
1421
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001422 /// \brief Build a new OpenMP 'copyin' clause.
1423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
1426 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1427 SourceLocation StartLoc,
1428 SourceLocation LParenLoc,
1429 SourceLocation EndLoc) {
1430 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1431 EndLoc);
1432 }
1433
James Dennett2a4d13c2012-06-15 07:13:21 +00001434 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001435 ///
1436 /// By default, performs semantic analysis to build the new statement.
1437 /// Subclasses may override this routine to provide different behavior.
1438 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1439 Expr *object) {
1440 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1441 }
1442
James Dennett2a4d13c2012-06-15 07:13:21 +00001443 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001444 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001445 /// By default, performs semantic analysis to build the new statement.
1446 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001447 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001448 Expr *Object, Stmt *Body) {
1449 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001450 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001451
James Dennett2a4d13c2012-06-15 07:13:21 +00001452 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001453 ///
1454 /// By default, performs semantic analysis to build the new statement.
1455 /// Subclasses may override this routine to provide different behavior.
1456 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1457 Stmt *Body) {
1458 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1459 }
John McCall53848232011-07-27 01:07:15 +00001460
Douglas Gregorf68a5082010-04-22 23:10:45 +00001461 /// \brief Build a new Objective-C fast enumeration statement.
1462 ///
1463 /// By default, performs semantic analysis to build the new statement.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001466 Stmt *Element,
1467 Expr *Collection,
1468 SourceLocation RParenLoc,
1469 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001470 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001471 Element,
John McCallb268a282010-08-23 23:25:46 +00001472 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001473 RParenLoc);
1474 if (ForEachStmt.isInvalid())
1475 return StmtError();
1476
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001477 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001479
Douglas Gregorebe10102009-08-20 07:17:43 +00001480 /// \brief Build a new C++ exception declaration.
1481 ///
1482 /// By default, performs semantic analysis to build the new decaration.
1483 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001484 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001485 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001486 SourceLocation StartLoc,
1487 SourceLocation IdLoc,
1488 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001489 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001490 StartLoc, IdLoc, Id);
1491 if (Var)
1492 getSema().CurContext->addDecl(Var);
1493 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001494 }
1495
1496 /// \brief Build a new C++ catch statement.
1497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001501 VarDecl *ExceptionDecl,
1502 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001503 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1504 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001505 }
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregorebe10102009-08-20 07:17:43 +00001507 /// \brief Build a new C++ try statement.
1508 ///
1509 /// By default, performs semantic analysis to build the new statement.
1510 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001511 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1512 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001513 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Richard Smith02e85f32011-04-14 22:09:26 +00001516 /// \brief Build a new C++0x range-based for statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1520 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1521 SourceLocation ColonLoc,
1522 Stmt *Range, Stmt *BeginEnd,
1523 Expr *Cond, Expr *Inc,
1524 Stmt *LoopVar,
1525 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001526 // If we've just learned that the range is actually an Objective-C
1527 // collection, treat this as an Objective-C fast enumeration loop.
1528 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1529 if (RangeStmt->isSingleDecl()) {
1530 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001531 if (RangeVar->isInvalidDecl())
1532 return StmtError();
1533
Douglas Gregorf7106af2013-04-08 18:40:13 +00001534 Expr *RangeExpr = RangeVar->getInit();
1535 if (!RangeExpr->isTypeDependent() &&
1536 RangeExpr->getType()->isObjCObjectPointerType())
1537 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1538 RParenLoc);
1539 }
1540 }
1541 }
1542
Richard Smith02e85f32011-04-14 22:09:26 +00001543 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001544 Cond, Inc, LoopVar, RParenLoc,
1545 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001546 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001547
1548 /// \brief Build a new C++0x range-based for statement.
1549 ///
1550 /// By default, performs semantic analysis to build the new statement.
1551 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001552 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001553 bool IsIfExists,
1554 NestedNameSpecifierLoc QualifierLoc,
1555 DeclarationNameInfo NameInfo,
1556 Stmt *Nested) {
1557 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1558 QualifierLoc, NameInfo, Nested);
1559 }
1560
Richard Smith02e85f32011-04-14 22:09:26 +00001561 /// \brief Attach body to a C++0x range-based for statement.
1562 ///
1563 /// By default, performs semantic analysis to finish the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
1565 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1566 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001568
David Majnemerfad8f482013-10-15 09:33:02 +00001569 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1570 Stmt *TryBlock, Stmt *Handler) {
1571 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001572 }
1573
David Majnemerfad8f482013-10-15 09:33:02 +00001574 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001575 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001576 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001577 }
1578
David Majnemerfad8f482013-10-15 09:33:02 +00001579 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1580 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001581 }
1582
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// \brief Build a new expression that references a declaration.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001588 LookupResult &R,
1589 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001590 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1591 }
1592
1593
1594 /// \brief Build a new expression that references a declaration.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001598 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 ValueDecl *VD,
1600 const DeclarationNameInfo &NameInfo,
1601 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001602 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001603 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001604
1605 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001606
1607 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001611 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001616 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 }
1618
Douglas Gregorad8a3362009-09-04 17:36:40 +00001619 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001620 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001624 SourceLocation OperatorLoc,
1625 bool isArrow,
1626 CXXScopeSpec &SS,
1627 TypeSourceInfo *ScopeType,
1628 SourceLocation CCLoc,
1629 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001630 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001637 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001638 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001639 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregor882211c2010-04-28 22:16:22 +00001642 /// \brief Build a new builtin offsetof expression.
1643 ///
1644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001646 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001647 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001648 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001649 unsigned NumComponents,
1650 SourceLocation RParenLoc) {
1651 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1652 NumComponents, RParenLoc);
1653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001654
1655 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001656 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001657 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001660 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1661 SourceLocation OpLoc,
1662 UnaryExprOrTypeTrait ExprKind,
1663 SourceRange R) {
1664 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
Peter Collingbournee190dee2011-03-11 19:24:49 +00001667 /// \brief Build a new sizeof, alignof or vec step expression with an
1668 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001669 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001672 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1673 UnaryExprOrTypeTrait ExprKind,
1674 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001676 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001679
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001680 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001684 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001687 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001689 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001691 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001692 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 RBracketLoc);
1694 }
1695
1696 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001697 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001702 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001703 Expr *ExecConfig = nullptr) {
1704 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001705 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001713 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001714 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001715 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001716 const DeclarationNameInfo &MemberNameInfo,
1717 ValueDecl *Member,
1718 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001719 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001720 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001721 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1722 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001723 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001724 // We have a reference to an unnamed field. This is always the
1725 // base of an anonymous struct/union member access, i.e. the
1726 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001727 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001728 assert(Member->getType()->isRecordType() &&
1729 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001730
Richard Smithcab9a7d2011-10-26 19:06:56 +00001731 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001732 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001733 QualifierLoc.getNestedNameSpecifier(),
1734 FoundDecl, Member);
1735 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001736 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001737 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001738 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001739 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001740 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001741 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001742 cast<FieldDecl>(Member)->getType(),
1743 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001744 return getSema().Owned(ME);
1745 }
Mike Stump11289f42009-09-09 15:08:12 +00001746
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001747 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001748 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001749
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001750 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001751 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001752
John McCall16df1e52010-03-30 21:47:33 +00001753 // FIXME: this involves duplicating earlier analysis in a lot of
1754 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001755 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001756 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001757 R.resolveKind();
1758
John McCallb268a282010-08-23 23:25:46 +00001759 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001760 SS, TemplateKWLoc,
1761 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001762 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 }
Mike Stump11289f42009-09-09 15:08:12 +00001764
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001766 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001770 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001771 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001772 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 }
1774
1775 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001780 SourceLocation QuestionLoc,
1781 Expr *LHS,
1782 SourceLocation ColonLoc,
1783 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001784 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1785 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001795 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001796 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001797 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001805 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001807 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001808 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001809 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001813 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation OpLoc,
1818 SourceLocation AccessorLoc,
1819 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001820
John McCall10eae182009-11-30 22:42:35 +00001821 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001822 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001823 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001824 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001825 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001826 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001827 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001828 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
Mike Stump11289f42009-09-09 15:08:12 +00001830
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001836 MultiExprArg Inits,
1837 SourceLocation RBraceLoc,
1838 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001840 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001841 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001842 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001843
Douglas Gregord3d93062009-11-09 17:16:50 +00001844 // Patch in the result type we were given, which may have been computed
1845 // when the initial InitListExpr was built.
1846 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1847 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001848 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 MultiExprArg ArrayExprs,
1857 SourceLocation EqualOrColonLoc,
1858 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001859 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001862 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001865
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001866 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 }
Mike Stump11289f42009-09-09 15:08:12 +00001868
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001870 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// By default, builds the implicit value initialization without performing
1872 /// any semantic analysis. Subclasses may override this routine to provide
1873 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001874 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1876 }
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001879 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001883 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001884 SourceLocation RParenLoc) {
1885 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001886 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001887 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 }
1889
1890 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001891 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001895 MultiExprArg SubExprs,
1896 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001897 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 }
Mike Stump11289f42009-09-09 15:08:12 +00001899
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001901 ///
1902 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// rather than attempting to map the label statement itself.
1904 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001906 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001907 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 }
Mike Stump11289f42009-09-09 15:08:12 +00001909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001911 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001915 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001917 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 }
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 /// \brief Build a new __builtin_choose_expr expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001925 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 SourceLocation RParenLoc) {
1927 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001928 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 RParenLoc);
1930 }
Mike Stump11289f42009-09-09 15:08:12 +00001931
Peter Collingbourne91147592011-04-15 00:35:48 +00001932 /// \brief Build a new generic selection expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1937 SourceLocation DefaultLoc,
1938 SourceLocation RParenLoc,
1939 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001940 ArrayRef<TypeSourceInfo *> Types,
1941 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001942 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001943 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001944 }
1945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new overloaded operator call expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// The semantic analysis provides the behavior of template instantiation,
1950 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001951 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// argument-dependent lookup, etc. Subclasses may override this routine to
1953 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001956 Expr *Callee,
1957 Expr *First,
1958 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001959
1960 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 /// reinterpret_cast.
1962 ///
1963 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001964 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 Stmt::StmtClass Class,
1968 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001969 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 SourceLocation RAngleLoc,
1971 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001972 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 SourceLocation RParenLoc) {
1974 switch (Class) {
1975 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001976 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001977 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001979
1980 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001981 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001982 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001986 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001987 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001988 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001992 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001993 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001994 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001997 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 }
Mike Stump11289f42009-09-09 15:08:12 +00002000
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// \brief Build a new C++ static_cast expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002005 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002007 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 SourceLocation RAngleLoc,
2009 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002012 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002013 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002014 SourceRange(LAngleLoc, RAngleLoc),
2015 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
2017
2018 /// \brief Build a new C++ dynamic_cast expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002024 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 SourceLocation RAngleLoc,
2026 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002029 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002030 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002031 SourceRange(LAngleLoc, RAngleLoc),
2032 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new C++ reinterpret_cast expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002039 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002041 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 SourceLocation RAngleLoc,
2043 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002044 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002046 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002047 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002048 SourceRange(LAngleLoc, RAngleLoc),
2049 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
2051
2052 /// \brief Build a new C++ const_cast expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002058 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation RAngleLoc,
2060 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002061 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002063 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002064 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002065 SourceRange(LAngleLoc, RAngleLoc),
2066 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// \brief Build a new C++ functional-style cast expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002073 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2074 SourceLocation LParenLoc,
2075 Expr *Sub,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002078 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 RParenLoc);
2080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// \brief Build a new C++ typeid(type) expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002086 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002087 SourceLocation TypeidLoc,
2088 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002090 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002091 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Francois Pichet9f4f2072010-09-08 12:20:18 +00002094
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// \brief Build a new C++ typeid(expr) expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002100 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002101 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002103 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002104 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002105 }
2106
Francois Pichet9f4f2072010-09-08 12:20:18 +00002107 /// \brief Build a new C++ __uuidof(type) expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2112 SourceLocation TypeidLoc,
2113 TypeSourceInfo *Operand,
2114 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002115 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002116 RParenLoc);
2117 }
2118
2119 /// \brief Build a new C++ __uuidof(expr) expression.
2120 ///
2121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
2123 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2124 SourceLocation TypeidLoc,
2125 Expr *Operand,
2126 SourceLocation RParenLoc) {
2127 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2128 RParenLoc);
2129 }
2130
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 /// \brief Build a new C++ "this" expression.
2132 ///
2133 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002134 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002137 QualType ThisType,
2138 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002139 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002141 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2142 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new C++ throw expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002149 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2150 bool IsThrownVariableInScope) {
2151 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 }
2153
2154 /// \brief Build a new C++ default-argument expression.
2155 ///
2156 /// By default, builds a new default-argument expression, which does not
2157 /// require any semantic analysis. Subclasses may override this routine to
2158 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002159 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002160 ParmVarDecl *Param) {
2161 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2162 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 }
2164
Richard Smith852c9db2013-04-20 22:23:05 +00002165 /// \brief Build a new C++11 default-initialization expression.
2166 ///
2167 /// By default, builds a new default field initialization expression, which
2168 /// does not require any semantic analysis. Subclasses may override this
2169 /// routine to provide different behavior.
2170 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2171 FieldDecl *Field) {
2172 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2173 Field));
2174 }
2175
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 /// \brief Build a new C++ zero-initialization expression.
2177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002180 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2181 SourceLocation LParenLoc,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002184 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 /// \brief Build a new C++ "new" expression.
2188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002192 bool UseGlobal,
2193 SourceLocation PlacementLParen,
2194 MultiExprArg PlacementArgs,
2195 SourceLocation PlacementRParen,
2196 SourceRange TypeIdParens,
2197 QualType AllocatedType,
2198 TypeSourceInfo *AllocatedTypeInfo,
2199 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002200 SourceRange DirectInitRange,
2201 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002202 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002204 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002206 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002207 AllocatedType,
2208 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002209 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002210 DirectInitRange,
2211 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 }
Mike Stump11289f42009-09-09 15:08:12 +00002213
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// \brief Build a new C++ "delete" expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 bool IsGlobalDelete,
2220 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002221 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002223 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 }
Mike Stump11289f42009-09-09 15:08:12 +00002225
Douglas Gregor29c42f22012-02-24 07:38:34 +00002226 /// \brief Build a new type trait expression.
2227 ///
2228 /// By default, performs semantic analysis to build the new expression.
2229 /// Subclasses may override this routine to provide different behavior.
2230 ExprResult RebuildTypeTrait(TypeTrait Trait,
2231 SourceLocation StartLoc,
2232 ArrayRef<TypeSourceInfo *> Args,
2233 SourceLocation RParenLoc) {
2234 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002236
John Wiegley6242b6a2011-04-28 00:16:57 +00002237 /// \brief Build a new array type trait expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
2241 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2242 SourceLocation StartLoc,
2243 TypeSourceInfo *TSInfo,
2244 Expr *DimExpr,
2245 SourceLocation RParenLoc) {
2246 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2247 }
2248
John Wiegleyf9f65842011-04-25 06:54:41 +00002249 /// \brief Build a new expression trait expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
2253 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2254 SourceLocation StartLoc,
2255 Expr *Queried,
2256 SourceLocation RParenLoc) {
2257 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2258 }
2259
Mike Stump11289f42009-09-09 15:08:12 +00002260 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 /// expression.
2262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002265 ExprResult RebuildDependentScopeDeclRefExpr(
2266 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002267 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002268 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002269 const TemplateArgumentListInfo *TemplateArgs,
2270 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002272 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002273
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002274 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002275 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002276 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002277
Richard Smithdb2630f2012-10-21 03:28:35 +00002278 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2279 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 }
2281
2282 /// \brief Build a new template-id expression.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002287 SourceLocation TemplateKWLoc,
2288 LookupResult &R,
2289 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002290 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002291 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2292 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 }
2294
2295 /// \brief Build a new object-construction expression.
2296 ///
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002299 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002300 SourceLocation Loc,
2301 CXXConstructorDecl *Constructor,
2302 bool IsElidable,
2303 MultiExprArg Args,
2304 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002305 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002306 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002307 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002308 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002309 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002310 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002311 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002312 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002313
Douglas Gregordb121ba2009-12-14 16:27:04 +00002314 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002315 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002316 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002317 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002318 RequiresZeroInit, ConstructKind,
2319 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 }
2321
2322 /// \brief Build a new object-construction expression.
2323 ///
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002326 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2327 SourceLocation LParenLoc,
2328 MultiExprArg Args,
2329 SourceLocation RParenLoc) {
2330 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002332 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 RParenLoc);
2334 }
2335
2336 /// \brief Build a new object-construction expression.
2337 ///
2338 /// By default, performs semantic analysis to build the new expression.
2339 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002340 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2341 SourceLocation LParenLoc,
2342 MultiExprArg Args,
2343 SourceLocation RParenLoc) {
2344 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002346 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 RParenLoc);
2348 }
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 /// \brief Build a new member reference expression.
2351 ///
2352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002355 QualType BaseType,
2356 bool IsArrow,
2357 SourceLocation OperatorLoc,
2358 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002359 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002360 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002361 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002362 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002364 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002365
John McCallb268a282010-08-23 23:25:46 +00002366 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002367 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002368 SS, TemplateKWLoc,
2369 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002370 MemberNameInfo,
2371 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 }
2373
John McCall10eae182009-11-30 22:42:35 +00002374 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002378 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2379 SourceLocation OperatorLoc,
2380 bool IsArrow,
2381 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002382 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002383 NamedDecl *FirstQualifierInScope,
2384 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002385 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002386 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002387 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002388
John McCallb268a282010-08-23 23:25:46 +00002389 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002390 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002391 SS, TemplateKWLoc,
2392 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002393 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002394 }
Mike Stump11289f42009-09-09 15:08:12 +00002395
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002396 /// \brief Build a new noexcept expression.
2397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
2400 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2401 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2402 }
2403
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002404 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002405 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2406 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002407 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002408 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002409 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002410 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2411 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002412 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002413
2414 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2415 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002416 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002417 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002418
Patrick Beard0caa3942012-04-19 00:25:12 +00002419 /// \brief Build a new Objective-C boxed expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
2423 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2424 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002426
Ted Kremeneke65b0862012-03-06 20:05:56 +00002427 /// \brief Build a new Objective-C array literal.
2428 ///
2429 /// By default, performs semantic analysis to build the new expression.
2430 /// Subclasses may override this routine to provide different behavior.
2431 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2432 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002433 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002434 MultiExprArg(Elements, NumElements));
2435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002436
2437 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002438 Expr *Base, Expr *Key,
2439 ObjCMethodDecl *getterMethod,
2440 ObjCMethodDecl *setterMethod) {
2441 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2442 getterMethod, setterMethod);
2443 }
2444
2445 /// \brief Build a new Objective-C dictionary literal.
2446 ///
2447 /// By default, performs semantic analysis to build the new expression.
2448 /// Subclasses may override this routine to provide different behavior.
2449 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2450 ObjCDictionaryElement *Elements,
2451 unsigned NumElements) {
2452 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002454
James Dennett2a4d13c2012-06-15 07:13:21 +00002455 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002456 ///
2457 /// By default, performs semantic analysis to build the new expression.
2458 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002460 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002462 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002464 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002465
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002466 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002467 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002469 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002470 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002471 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002472 MultiExprArg Args,
2473 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002474 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2475 ReceiverTypeInfo->getType(),
2476 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002477 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002478 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002479 }
2480
2481 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002482 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002483 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002484 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002486 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002487 MultiExprArg Args,
2488 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002489 return SemaRef.BuildInstanceMessage(Receiver,
2490 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002491 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002492 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002493 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002494 }
2495
Douglas Gregord51d90d2010-04-26 20:11:03 +00002496 /// \brief Build a new Objective-C ivar reference expression.
2497 ///
2498 /// By default, performs semantic analysis to build the new expression.
2499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002500 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002501 SourceLocation IvarLoc,
2502 bool IsArrow, bool IsFreeIvar) {
2503 // FIXME: We lose track of the IsFreeIvar bit.
2504 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002505 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002506 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2507 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002509 /*FIME:*/IvarLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002510 SS, nullptr,
John McCalle9cccd82010-06-16 08:42:20 +00002511 false);
John Wiegley01296292011-04-08 18:41:53 +00002512 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002514
Douglas Gregord51d90d2010-04-26 20:11:03 +00002515 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002516 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002517
John Wiegley01296292011-04-08 18:41:53 +00002518 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002519 /*FIXME:*/IvarLoc, IsArrow,
2520 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002521 /*FirstQualifierInScope=*/nullptr,
Chad Rosier1dcde962012-08-08 18:46:20 +00002522 R,
Craig Topperc3ec1492014-05-26 06:22:03 +00002523 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002524 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002525
2526 /// \brief Build a new Objective-C property reference expression.
2527 ///
2528 /// By default, performs semantic analysis to build the new expression.
2529 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002530 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002531 ObjCPropertyDecl *Property,
2532 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002533 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002534 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002535 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2536 Sema::LookupMemberName);
2537 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002538 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002539 /*FIME:*/PropertyLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002540 SS, nullptr, false);
John Wiegley01296292011-04-08 18:41:53 +00002541 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002542 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002543
Douglas Gregor9faee212010-04-26 20:47:02 +00002544 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002545 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002546
John Wiegley01296292011-04-08 18:41:53 +00002547 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002548 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002549 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002550 /*FirstQualifierInScope=*/nullptr,
2551 R, /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002553
John McCallb7bd14f2010-12-02 01:19:52 +00002554 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002555 ///
2556 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002557 /// Subclasses may override this routine to provide different behavior.
2558 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2559 ObjCMethodDecl *Getter,
2560 ObjCMethodDecl *Setter,
2561 SourceLocation PropertyLoc) {
2562 // Since these expressions can only be value-dependent, we do not
2563 // need to perform semantic analysis again.
2564 return Owned(
2565 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2566 VK_LValue, OK_ObjCProperty,
2567 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002568 }
2569
Douglas Gregord51d90d2010-04-26 20:11:03 +00002570 /// \brief Build a new Objective-C "isa" expression.
2571 ///
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002574 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002575 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002576 bool IsArrow) {
2577 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002578 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002579 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2580 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002581 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002582 OpLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002583 SS, nullptr, false);
John Wiegley01296292011-04-08 18:41:53 +00002584 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002585 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002586
Douglas Gregord51d90d2010-04-26 20:11:03 +00002587 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002588 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002589
John Wiegley01296292011-04-08 18:41:53 +00002590 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002591 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002592 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002593 /*FirstQualifierInScope=*/nullptr,
Chad Rosier1dcde962012-08-08 18:46:20 +00002594 R,
Craig Topperc3ec1492014-05-26 06:22:03 +00002595 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002597
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 /// \brief Build a new shuffle vector expression.
2599 ///
2600 /// By default, performs semantic analysis to build the new expression.
2601 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002602 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002603 MultiExprArg SubExprs,
2604 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002606 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2608 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2609 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002610 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002611
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002613 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002614 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2615 SemaRef.Context.BuiltinFnTy,
2616 VK_RValue, BuiltinLoc);
2617 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2618 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002619 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002620
2621 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002622 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2623 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2624 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002625
Douglas Gregora16548e2009-08-11 05:31:07 +00002626 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002627 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 }
John McCall31f82722010-11-12 08:19:04 +00002629
Hal Finkelc4d7c822013-09-18 03:29:45 +00002630 /// \brief Build a new convert vector expression.
2631 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2632 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2633 SourceLocation RParenLoc) {
2634 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2635 BuiltinLoc, RParenLoc);
2636 }
2637
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002638 /// \brief Build a new template argument pack expansion.
2639 ///
2640 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002641 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002642 /// different behavior.
2643 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002644 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002645 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002646 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002647 case TemplateArgument::Expression: {
2648 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002649 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2650 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002651 if (Result.isInvalid())
2652 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002653
Douglas Gregor98318c22011-01-03 21:37:45 +00002654 return TemplateArgumentLoc(Result.get(), Result.get());
2655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002656
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002657 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002658 return TemplateArgumentLoc(TemplateArgument(
2659 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002660 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002661 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002662 Pattern.getTemplateNameLoc(),
2663 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002664
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002665 case TemplateArgument::Null:
2666 case TemplateArgument::Integral:
2667 case TemplateArgument::Declaration:
2668 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002669 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002670 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002671 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002672
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002673 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002674 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002675 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002676 EllipsisLoc,
2677 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002678 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2679 Expansion);
2680 break;
2681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002682
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002683 return TemplateArgumentLoc();
2684 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002685
Douglas Gregor968f23a2011-01-03 19:31:53 +00002686 /// \brief Build a new expression pack expansion.
2687 ///
2688 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002689 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002690 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002691 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002692 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002693 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002694 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002695
2696 /// \brief Build a new atomic operation expression.
2697 ///
2698 /// By default, performs semantic analysis to build the new expression.
2699 /// Subclasses may override this routine to provide different behavior.
2700 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2701 MultiExprArg SubExprs,
2702 QualType RetTy,
2703 AtomicExpr::AtomicOp Op,
2704 SourceLocation RParenLoc) {
2705 // Just create the expression; there is not any interesting semantic
2706 // analysis here because we can't actually build an AtomicExpr until
2707 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002708 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002709 RParenLoc);
2710 }
2711
John McCall31f82722010-11-12 08:19:04 +00002712private:
Douglas Gregor14454802011-02-25 02:25:35 +00002713 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2714 QualType ObjectType,
2715 NamedDecl *FirstQualifierInScope,
2716 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002717
2718 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2719 QualType ObjectType,
2720 NamedDecl *FirstQualifierInScope,
2721 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002722
2723 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2724 NamedDecl *FirstQualifierInScope,
2725 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726};
Douglas Gregora16548e2009-08-11 05:31:07 +00002727
Douglas Gregorebe10102009-08-20 07:17:43 +00002728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002729StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002730 if (!S)
2731 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002732
Douglas Gregorebe10102009-08-20 07:17:43 +00002733 switch (S->getStmtClass()) {
2734 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002735
Douglas Gregorebe10102009-08-20 07:17:43 +00002736 // Transform individual statement nodes
2737#define STMT(Node, Parent) \
2738 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002739#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002740#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002741#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregorebe10102009-08-20 07:17:43 +00002743 // Transform expressions by calling TransformExpr.
2744#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002745#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002746#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002747#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002748 {
John McCalldadc5752010-08-24 06:29:42 +00002749 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002750 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002751 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002752
Richard Smith945f8d32013-01-14 22:39:08 +00002753 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755 }
2756
John McCallc3007a22010-10-26 07:05:15 +00002757 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002758}
Mike Stump11289f42009-09-09 15:08:12 +00002759
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002760template<typename Derived>
2761OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2762 if (!S)
2763 return S;
2764
2765 switch (S->getClauseKind()) {
2766 default: break;
2767 // Transform individual clause nodes
2768#define OPENMP_CLAUSE(Name, Class) \
2769 case OMPC_ ## Name : \
2770 return getDerived().Transform ## Class(cast<Class>(S));
2771#include "clang/Basic/OpenMPKinds.def"
2772 }
2773
2774 return S;
2775}
2776
Mike Stump11289f42009-09-09 15:08:12 +00002777
Douglas Gregore922c772009-08-04 22:27:00 +00002778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002779ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002780 if (!E)
2781 return SemaRef.Owned(E);
2782
2783 switch (E->getStmtClass()) {
2784 case Stmt::NoStmtClass: break;
2785#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002786#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002787#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002788 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002789#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002790 }
2791
John McCallc3007a22010-10-26 07:05:15 +00002792 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002793}
2794
2795template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002796ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2797 bool CXXDirectInit) {
2798 // Initializers are instantiated like expressions, except that various outer
2799 // layers are stripped.
2800 if (!Init)
2801 return SemaRef.Owned(Init);
2802
2803 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2804 Init = ExprTemp->getSubExpr();
2805
Richard Smithe6ca4752013-05-30 22:40:16 +00002806 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2807 Init = MTE->GetTemporaryExpr();
2808
Richard Smithd59b8322012-12-19 01:39:02 +00002809 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2810 Init = Binder->getSubExpr();
2811
2812 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2813 Init = ICE->getSubExprAsWritten();
2814
Richard Smithcc1b96d2013-06-12 22:31:48 +00002815 if (CXXStdInitializerListExpr *ILE =
2816 dyn_cast<CXXStdInitializerListExpr>(Init))
2817 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2818
Richard Smith38a549b2012-12-21 08:13:35 +00002819 // If this is not a direct-initializer, we only need to reconstruct
2820 // InitListExprs. Other forms of copy-initialization will be a no-op if
2821 // the initializer is already the right type.
2822 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2823 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2824 return getDerived().TransformExpr(Init);
2825
2826 // Revert value-initialization back to empty parens.
2827 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2828 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002829 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002830 Parens.getEnd());
2831 }
2832
2833 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2834 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002835 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002836 SourceLocation());
2837
2838 // Revert initialization by constructor back to a parenthesized or braced list
2839 // of expressions. Any other form of initializer can just be reused directly.
2840 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002841 return getDerived().TransformExpr(Init);
2842
2843 SmallVector<Expr*, 8> NewArgs;
2844 bool ArgChanged = false;
2845 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2846 /*IsCall*/true, NewArgs, &ArgChanged))
2847 return ExprError();
2848
2849 // If this was list initialization, revert to list form.
2850 if (Construct->isListInitialization())
2851 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2852 Construct->getLocEnd(),
2853 Construct->getType());
2854
Richard Smithd59b8322012-12-19 01:39:02 +00002855 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002856 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002857 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2858 Parens.getEnd());
2859}
2860
2861template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002862bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2863 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002864 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002865 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002866 bool *ArgChanged) {
2867 for (unsigned I = 0; I != NumInputs; ++I) {
2868 // If requested, drop call arguments that need to be dropped.
2869 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2870 if (ArgChanged)
2871 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002872
Douglas Gregora3efea12011-01-03 19:04:46 +00002873 break;
2874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002875
Douglas Gregor968f23a2011-01-03 19:31:53 +00002876 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2877 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002878
Chris Lattner01cf8db2011-07-20 06:58:45 +00002879 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002880 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2881 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002882
Douglas Gregor968f23a2011-01-03 19:31:53 +00002883 // Determine whether the set of unexpanded parameter packs can and should
2884 // be expanded.
2885 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002886 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002887 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2888 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002889 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2890 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002891 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002892 Expand, RetainExpansion,
2893 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002894 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002895
Douglas Gregor968f23a2011-01-03 19:31:53 +00002896 if (!Expand) {
2897 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002898 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002899 // expansion.
2900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2901 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2902 if (OutPattern.isInvalid())
2903 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002904
2905 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002906 Expansion->getEllipsisLoc(),
2907 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002908 if (Out.isInvalid())
2909 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002910
Douglas Gregor968f23a2011-01-03 19:31:53 +00002911 if (ArgChanged)
2912 *ArgChanged = true;
2913 Outputs.push_back(Out.get());
2914 continue;
2915 }
John McCall542e7c62011-07-06 07:30:07 +00002916
2917 // Record right away that the argument was changed. This needs
2918 // to happen even if the array expands to nothing.
2919 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002920
Douglas Gregor968f23a2011-01-03 19:31:53 +00002921 // The transform has determined that we should perform an elementwise
2922 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002923 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002924 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2925 ExprResult Out = getDerived().TransformExpr(Pattern);
2926 if (Out.isInvalid())
2927 return true;
2928
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002929 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002930 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2931 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002932 if (Out.isInvalid())
2933 return true;
2934 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002935
Douglas Gregor968f23a2011-01-03 19:31:53 +00002936 Outputs.push_back(Out.get());
2937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002938
Douglas Gregor968f23a2011-01-03 19:31:53 +00002939 continue;
2940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002941
Richard Smithd59b8322012-12-19 01:39:02 +00002942 ExprResult Result =
2943 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2944 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002945 if (Result.isInvalid())
2946 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002947
Douglas Gregora3efea12011-01-03 19:04:46 +00002948 if (Result.get() != Inputs[I] && ArgChanged)
2949 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002950
2951 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002952 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002953
Douglas Gregora3efea12011-01-03 19:04:46 +00002954 return false;
2955}
2956
2957template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002958NestedNameSpecifierLoc
2959TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2960 NestedNameSpecifierLoc NNS,
2961 QualType ObjectType,
2962 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002963 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002964 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002965 Qualifier = Qualifier.getPrefix())
2966 Qualifiers.push_back(Qualifier);
2967
2968 CXXScopeSpec SS;
2969 while (!Qualifiers.empty()) {
2970 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2971 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002972
Douglas Gregor14454802011-02-25 02:25:35 +00002973 switch (QNNS->getKind()) {
2974 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002975 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002976 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002977 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002978 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002979 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002980 FirstQualifierInScope, false))
2981 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002982
Douglas Gregor14454802011-02-25 02:25:35 +00002983 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregor14454802011-02-25 02:25:35 +00002985 case NestedNameSpecifier::Namespace: {
2986 NamespaceDecl *NS
2987 = cast_or_null<NamespaceDecl>(
2988 getDerived().TransformDecl(
2989 Q.getLocalBeginLoc(),
2990 QNNS->getAsNamespace()));
2991 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2992 break;
2993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
Douglas Gregor14454802011-02-25 02:25:35 +00002995 case NestedNameSpecifier::NamespaceAlias: {
2996 NamespaceAliasDecl *Alias
2997 = cast_or_null<NamespaceAliasDecl>(
2998 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2999 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003000 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003001 Q.getLocalEndLoc());
3002 break;
3003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Douglas Gregor14454802011-02-25 02:25:35 +00003005 case NestedNameSpecifier::Global:
3006 // There is no meaningful transformation that one could perform on the
3007 // global scope.
3008 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3009 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor14454802011-02-25 02:25:35 +00003011 case NestedNameSpecifier::TypeSpecWithTemplate:
3012 case NestedNameSpecifier::TypeSpec: {
3013 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3014 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003015
Douglas Gregor14454802011-02-25 02:25:35 +00003016 if (!TL)
3017 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003018
Douglas Gregor14454802011-02-25 02:25:35 +00003019 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003020 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003021 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003022 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003023 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003024 if (TL.getType()->isEnumeralType())
3025 SemaRef.Diag(TL.getBeginLoc(),
3026 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003027 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3028 Q.getLocalEndLoc());
3029 break;
3030 }
Richard Trieude756fb2011-05-07 01:36:37 +00003031 // If the nested-name-specifier is an invalid type def, don't emit an
3032 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003033 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3034 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003035 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003036 << TL.getType() << SS.getRange();
3037 }
Douglas Gregor14454802011-02-25 02:25:35 +00003038 return NestedNameSpecifierLoc();
3039 }
Douglas Gregore16af532011-02-28 18:50:33 +00003040 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003041
Douglas Gregore16af532011-02-28 18:50:33 +00003042 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003043 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003044 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003046
Douglas Gregor14454802011-02-25 02:25:35 +00003047 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003048 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003049 !getDerived().AlwaysRebuild())
3050 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
3052 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003053 // nested-name-specifier, do so.
3054 if (SS.location_size() == NNS.getDataLength() &&
3055 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3056 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3057
3058 // Allocate new nested-name-specifier location information.
3059 return SS.getWithLocInContext(SemaRef.Context);
3060}
3061
3062template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003063DeclarationNameInfo
3064TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003065::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003066 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003067 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003068 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003069
3070 switch (Name.getNameKind()) {
3071 case DeclarationName::Identifier:
3072 case DeclarationName::ObjCZeroArgSelector:
3073 case DeclarationName::ObjCOneArgSelector:
3074 case DeclarationName::ObjCMultiArgSelector:
3075 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003076 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003077 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003078 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003079
Douglas Gregorf816bd72009-09-03 22:13:48 +00003080 case DeclarationName::CXXConstructorName:
3081 case DeclarationName::CXXDestructorName:
3082 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003083 TypeSourceInfo *NewTInfo;
3084 CanQualType NewCanTy;
3085 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003086 NewTInfo = getDerived().TransformType(OldTInfo);
3087 if (!NewTInfo)
3088 return DeclarationNameInfo();
3089 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003090 }
3091 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003092 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003093 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003094 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003095 if (NewT.isNull())
3096 return DeclarationNameInfo();
3097 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3098 }
Mike Stump11289f42009-09-09 15:08:12 +00003099
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003100 DeclarationName NewName
3101 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3102 NewCanTy);
3103 DeclarationNameInfo NewNameInfo(NameInfo);
3104 NewNameInfo.setName(NewName);
3105 NewNameInfo.setNamedTypeInfo(NewTInfo);
3106 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003107 }
Mike Stump11289f42009-09-09 15:08:12 +00003108 }
3109
David Blaikie83d382b2011-09-23 05:06:16 +00003110 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003111}
3112
3113template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003114TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003115TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3116 TemplateName Name,
3117 SourceLocation NameLoc,
3118 QualType ObjectType,
3119 NamedDecl *FirstQualifierInScope) {
3120 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3121 TemplateDecl *Template = QTN->getTemplateDecl();
3122 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Douglas Gregor9db53502011-03-02 18:07:45 +00003124 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003125 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003126 Template));
3127 if (!TransTemplate)
3128 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003129
Douglas Gregor9db53502011-03-02 18:07:45 +00003130 if (!getDerived().AlwaysRebuild() &&
3131 SS.getScopeRep() == QTN->getQualifier() &&
3132 TransTemplate == Template)
3133 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3136 TransTemplate);
3137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003138
Douglas Gregor9db53502011-03-02 18:07:45 +00003139 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3140 if (SS.getScopeRep()) {
3141 // These apply to the scope specifier, not the template.
3142 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003143 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003144 }
3145
Douglas Gregor9db53502011-03-02 18:07:45 +00003146 if (!getDerived().AlwaysRebuild() &&
3147 SS.getScopeRep() == DTN->getQualifier() &&
3148 ObjectType.isNull())
3149 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregor9db53502011-03-02 18:07:45 +00003151 if (DTN->isIdentifier()) {
3152 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003153 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003154 NameLoc,
3155 ObjectType,
3156 FirstQualifierInScope);
3157 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003158
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3160 ObjectType);
3161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor9db53502011-03-02 18:07:45 +00003163 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3164 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003165 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003166 Template));
3167 if (!TransTemplate)
3168 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor9db53502011-03-02 18:07:45 +00003170 if (!getDerived().AlwaysRebuild() &&
3171 TransTemplate == Template)
3172 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor9db53502011-03-02 18:07:45 +00003174 return TemplateName(TransTemplate);
3175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor9db53502011-03-02 18:07:45 +00003177 if (SubstTemplateTemplateParmPackStorage *SubstPack
3178 = Name.getAsSubstTemplateTemplateParmPack()) {
3179 TemplateTemplateParmDecl *TransParam
3180 = cast_or_null<TemplateTemplateParmDecl>(
3181 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3182 if (!TransParam)
3183 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003184
Douglas Gregor9db53502011-03-02 18:07:45 +00003185 if (!getDerived().AlwaysRebuild() &&
3186 TransParam == SubstPack->getParameterPack())
3187 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003188
3189 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003190 SubstPack->getArgumentPack());
3191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Douglas Gregor9db53502011-03-02 18:07:45 +00003193 // These should be getting filtered out before they reach the AST.
3194 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003195}
3196
3197template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003198void TreeTransform<Derived>::InventTemplateArgumentLoc(
3199 const TemplateArgument &Arg,
3200 TemplateArgumentLoc &Output) {
3201 SourceLocation Loc = getDerived().getBaseLocation();
3202 switch (Arg.getKind()) {
3203 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003204 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003205 break;
3206
3207 case TemplateArgument::Type:
3208 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003209 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003210
John McCall0ad16662009-10-29 08:12:44 +00003211 break;
3212
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003213 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003214 case TemplateArgument::TemplateExpansion: {
3215 NestedNameSpecifierLocBuilder Builder;
3216 TemplateName Template = Arg.getAsTemplate();
3217 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3218 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3219 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3220 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregor9d802122011-03-02 17:09:35 +00003222 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003223 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003224 Builder.getWithLocInContext(SemaRef.Context),
3225 Loc);
3226 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003227 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003228 Builder.getWithLocInContext(SemaRef.Context),
3229 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003231 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003232 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003233
John McCall0ad16662009-10-29 08:12:44 +00003234 case TemplateArgument::Expression:
3235 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3236 break;
3237
3238 case TemplateArgument::Declaration:
3239 case TemplateArgument::Integral:
3240 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003241 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003242 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003243 break;
3244 }
3245}
3246
3247template<typename Derived>
3248bool TreeTransform<Derived>::TransformTemplateArgument(
3249 const TemplateArgumentLoc &Input,
3250 TemplateArgumentLoc &Output) {
3251 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003252 switch (Arg.getKind()) {
3253 case TemplateArgument::Null:
3254 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003255 case TemplateArgument::Pack:
3256 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003257 case TemplateArgument::NullPtr:
3258 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003259
Douglas Gregore922c772009-08-04 22:27:00 +00003260 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003261 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003262 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003263 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003264
3265 DI = getDerived().TransformType(DI);
3266 if (!DI) return true;
3267
3268 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3269 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003270 }
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003272 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003273 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3274 if (QualifierLoc) {
3275 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3276 if (!QualifierLoc)
3277 return true;
3278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregordf846d12011-03-02 18:46:51 +00003280 CXXScopeSpec SS;
3281 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003282 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003283 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3284 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003285 if (Template.isNull())
3286 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003287
Douglas Gregor9d802122011-03-02 17:09:35 +00003288 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003289 Input.getTemplateNameLoc());
3290 return false;
3291 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003292
3293 case TemplateArgument::TemplateExpansion:
3294 llvm_unreachable("Caller should expand pack expansions");
3295
Douglas Gregore922c772009-08-04 22:27:00 +00003296 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003297 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003298 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003299 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003300
John McCall0ad16662009-10-29 08:12:44 +00003301 Expr *InputExpr = Input.getSourceExpression();
3302 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3303
Chris Lattnercdb591a2011-04-25 20:37:58 +00003304 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003305 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003306 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003307 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003308 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003309 }
Douglas Gregore922c772009-08-04 22:27:00 +00003310 }
Mike Stump11289f42009-09-09 15:08:12 +00003311
Douglas Gregore922c772009-08-04 22:27:00 +00003312 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003313 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003314}
3315
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316/// \brief Iterator adaptor that invents template argument location information
3317/// for each of the template arguments in its underlying iterator.
3318template<typename Derived, typename InputIterator>
3319class TemplateArgumentLocInventIterator {
3320 TreeTransform<Derived> &Self;
3321 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003322
Douglas Gregorfe921a72010-12-20 23:36:19 +00003323public:
3324 typedef TemplateArgumentLoc value_type;
3325 typedef TemplateArgumentLoc reference;
3326 typedef typename std::iterator_traits<InputIterator>::difference_type
3327 difference_type;
3328 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 class pointer {
3331 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
Douglas Gregorfe921a72010-12-20 23:36:19 +00003333 public:
3334 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 const TemplateArgumentLoc *operator->() const { return &Arg; }
3337 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregorfe921a72010-12-20 23:36:19 +00003339 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregorfe921a72010-12-20 23:36:19 +00003341 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3342 InputIterator Iter)
3343 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Douglas Gregorfe921a72010-12-20 23:36:19 +00003345 TemplateArgumentLocInventIterator &operator++() {
3346 ++Iter;
3347 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregorfe921a72010-12-20 23:36:19 +00003350 TemplateArgumentLocInventIterator operator++(int) {
3351 TemplateArgumentLocInventIterator Old(*this);
3352 ++(*this);
3353 return Old;
3354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregorfe921a72010-12-20 23:36:19 +00003356 reference operator*() const {
3357 TemplateArgumentLoc Result;
3358 Self.InventTemplateArgumentLoc(*Iter, Result);
3359 return Result;
3360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Douglas Gregorfe921a72010-12-20 23:36:19 +00003362 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregorfe921a72010-12-20 23:36:19 +00003364 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3365 const TemplateArgumentLocInventIterator &Y) {
3366 return X.Iter == Y.Iter;
3367 }
Douglas Gregor62e06f22010-12-20 17:31:10 +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 }
3373};
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregor42cafa82010-12-20 17:42:22 +00003375template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003376template<typename InputIterator>
3377bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3378 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003379 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003380 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003381 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003382 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003383
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003384 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3385 // Unpack argument packs, which we translate them into separate
3386 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003387 // FIXME: We could do much better if we could guarantee that the
3388 // TemplateArgumentLocInfo for the pack expansion would be usable for
3389 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003390 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003391 TemplateArgument::pack_iterator>
3392 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003393 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003394 In.getArgument().pack_begin()),
3395 PackLocIterator(*this,
3396 In.getArgument().pack_end()),
3397 Outputs))
3398 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003400 continue;
3401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003403 if (In.getArgument().isPackExpansion()) {
3404 // We have a pack expansion, for which we will be substituting into
3405 // the pattern.
3406 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003407 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003408 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003409 = getSema().getTemplateArgumentPackExpansionPattern(
3410 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Chris Lattner01cf8db2011-07-20 06:58:45 +00003412 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003413 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3414 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003416 // Determine whether the set of unexpanded parameter packs can and should
3417 // be expanded.
3418 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003419 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003420 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 if (getDerived().TryExpandParameterPacks(Ellipsis,
3422 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003423 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003424 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003425 RetainExpansion,
3426 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003427 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003429 if (!Expand) {
3430 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003431 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003432 // expansion.
3433 TemplateArgumentLoc OutPattern;
3434 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3435 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3436 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003438 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3439 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003440 if (Out.getArgument().isNull())
3441 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003443 Outputs.addArgument(Out);
3444 continue;
3445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003447 // The transform has determined that we should perform an elementwise
3448 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003449 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003450 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3451
3452 if (getDerived().TransformTemplateArgument(Pattern, Out))
3453 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003454
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003455 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003456 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3457 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003458 if (Out.getArgument().isNull())
3459 return true;
3460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003462 Outputs.addArgument(Out);
3463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor48d24112011-01-10 20:53:55 +00003465 // If we're supposed to retain a pack expansion, do so by temporarily
3466 // forgetting the partially-substituted parameter pack.
3467 if (RetainExpansion) {
3468 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor48d24112011-01-10 20:53:55 +00003470 if (getDerived().TransformTemplateArgument(Pattern, Out))
3471 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003473 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3474 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003475 if (Out.getArgument().isNull())
3476 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor48d24112011-01-10 20:53:55 +00003478 Outputs.addArgument(Out);
3479 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003480
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003481 continue;
3482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
3484 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003485 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003486 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Douglas Gregor42cafa82010-12-20 17:42:22 +00003488 Outputs.addArgument(Out);
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor42cafa82010-12-20 17:42:22 +00003491 return false;
3492
3493}
3494
Douglas Gregord6ff3322009-08-04 16:50:30 +00003495//===----------------------------------------------------------------------===//
3496// Type transformation
3497//===----------------------------------------------------------------------===//
3498
3499template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003500QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003501 if (getDerived().AlreadyTransformed(T))
3502 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003503
John McCall550e0c22009-10-21 00:40:46 +00003504 // Temporary workaround. All of these transformations should
3505 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003506 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3507 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
John McCall31f82722010-11-12 08:19:04 +00003509 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003510
John McCall550e0c22009-10-21 00:40:46 +00003511 if (!NewDI)
3512 return QualType();
3513
3514 return NewDI->getType();
3515}
3516
3517template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003518TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003519 // Refine the base location to the type's location.
3520 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3521 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003522 if (getDerived().AlreadyTransformed(DI->getType()))
3523 return DI;
3524
3525 TypeLocBuilder TLB;
3526
3527 TypeLoc TL = DI->getTypeLoc();
3528 TLB.reserve(TL.getFullDataSize());
3529
John McCall31f82722010-11-12 08:19:04 +00003530 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003531 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003532 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003533
John McCallbcd03502009-12-07 02:54:59 +00003534 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003535}
3536
3537template<typename Derived>
3538QualType
John McCall31f82722010-11-12 08:19:04 +00003539TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003540 switch (T.getTypeLocClass()) {
3541#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003542#define TYPELOC(CLASS, PARENT) \
3543 case TypeLoc::CLASS: \
3544 return getDerived().Transform##CLASS##Type(TLB, \
3545 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003546#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003547 }
Mike Stump11289f42009-09-09 15:08:12 +00003548
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003549 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003550}
3551
3552/// FIXME: By default, this routine adds type qualifiers only to types
3553/// that can have qualifiers, and silently suppresses those qualifiers
3554/// that are not permitted (e.g., qualifiers on reference or function
3555/// types). This is the right thing for template instantiation, but
3556/// probably not for other clients.
3557template<typename Derived>
3558QualType
3559TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003560 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003561 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003562
John McCall31f82722010-11-12 08:19:04 +00003563 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003564 if (Result.isNull())
3565 return QualType();
3566
3567 // Silently suppress qualifiers if the result type can't be qualified.
3568 // FIXME: this is the right thing for template instantiation, but
3569 // probably not for other clients.
3570 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003571 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003572
John McCall31168b02011-06-15 23:02:42 +00003573 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003574 // resulting type.
3575 if (Quals.hasObjCLifetime()) {
3576 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3577 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003578 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003579 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003580 // A lifetime qualifier applied to a substituted template parameter
3581 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003582 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003583 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003584 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3585 QualType Replacement = SubstTypeParam->getReplacementType();
3586 Qualifiers Qs = Replacement.getQualifiers();
3587 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003588 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003589 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3590 Qs);
3591 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003592 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003593 Replacement);
3594 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003595 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3596 // 'auto' types behave the same way as template parameters.
3597 QualType Deduced = AutoTy->getDeducedType();
3598 Qualifiers Qs = Deduced.getQualifiers();
3599 Qs.removeObjCLifetime();
3600 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3601 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003602 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3603 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003604 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003605 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003606 // Otherwise, complain about the addition of a qualifier to an
3607 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003608 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003609 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003610 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregore46db902011-06-17 22:11:49 +00003612 Quals.removeObjCLifetime();
3613 }
3614 }
3615 }
John McCallcb0f89a2010-06-05 06:41:15 +00003616 if (!Quals.empty()) {
3617 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003618 // BuildQualifiedType might not add qualifiers if they are invalid.
3619 if (Result.hasLocalQualifiers())
3620 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003621 // No location information to preserve.
3622 }
John McCall550e0c22009-10-21 00:40:46 +00003623
3624 return Result;
3625}
3626
Douglas Gregor14454802011-02-25 02:25:35 +00003627template<typename Derived>
3628TypeLoc
3629TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3630 QualType ObjectType,
3631 NamedDecl *UnqualLookup,
3632 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003633 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003634 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003636 TypeSourceInfo *TSI =
3637 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3638 if (TSI)
3639 return TSI->getTypeLoc();
3640 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003641}
3642
Douglas Gregor579c15f2011-03-02 18:32:08 +00003643template<typename Derived>
3644TypeSourceInfo *
3645TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3646 QualType ObjectType,
3647 NamedDecl *UnqualLookup,
3648 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003649 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003650 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003652 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3653 UnqualLookup, SS);
3654}
3655
3656template <typename Derived>
3657TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3658 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3659 CXXScopeSpec &SS) {
3660 QualType T = TL.getType();
3661 assert(!getDerived().AlreadyTransformed(T));
3662
Douglas Gregor579c15f2011-03-02 18:32:08 +00003663 TypeLocBuilder TLB;
3664 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
Douglas Gregor579c15f2011-03-02 18:32:08 +00003666 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003667 TemplateSpecializationTypeLoc SpecTL =
3668 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor579c15f2011-03-02 18:32:08 +00003670 TemplateName Template
3671 = getDerived().TransformTemplateName(SS,
3672 SpecTL.getTypePtr()->getTemplateName(),
3673 SpecTL.getTemplateNameLoc(),
3674 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003675 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003676 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
3678 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 Template);
3680 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003681 DependentTemplateSpecializationTypeLoc SpecTL =
3682 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003683
Douglas Gregor579c15f2011-03-02 18:32:08 +00003684 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003685 = getDerived().RebuildTemplateName(SS,
3686 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003687 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003688 ObjectType, UnqualLookup);
3689 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003690 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
3692 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003693 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003694 Template,
3695 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003696 } else {
3697 // Nothing special needs to be done for these.
3698 Result = getDerived().TransformType(TLB, TL);
3699 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
3701 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003702 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003703
Douglas Gregor579c15f2011-03-02 18:32:08 +00003704 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3705}
3706
John McCall550e0c22009-10-21 00:40:46 +00003707template <class TyLoc> static inline
3708QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3709 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3710 NewT.setNameLoc(T.getNameLoc());
3711 return T.getType();
3712}
3713
John McCall550e0c22009-10-21 00:40:46 +00003714template<typename Derived>
3715QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003716 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003717 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3718 NewT.setBuiltinLoc(T.getBuiltinLoc());
3719 if (T.needsExtraLocalData())
3720 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3721 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003722}
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregord6ff3322009-08-04 16:50:30 +00003724template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003725QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003726 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003727 // FIXME: recurse?
3728 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003729}
Mike Stump11289f42009-09-09 15:08:12 +00003730
Reid Kleckner0503a872013-12-05 01:23:43 +00003731template <typename Derived>
3732QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3733 AdjustedTypeLoc TL) {
3734 // Adjustments applied during transformation are handled elsewhere.
3735 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3736}
3737
Douglas Gregord6ff3322009-08-04 16:50:30 +00003738template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003739QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3740 DecayedTypeLoc TL) {
3741 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3742 if (OriginalType.isNull())
3743 return QualType();
3744
3745 QualType Result = TL.getType();
3746 if (getDerived().AlwaysRebuild() ||
3747 OriginalType != TL.getOriginalLoc().getType())
3748 Result = SemaRef.Context.getDecayedType(OriginalType);
3749 TLB.push<DecayedTypeLoc>(Result);
3750 // Nothing to set for DecayedTypeLoc.
3751 return Result;
3752}
3753
3754template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003755QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003756 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003757 QualType PointeeType
3758 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003759 if (PointeeType.isNull())
3760 return QualType();
3761
3762 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003763 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003764 // A dependent pointer type 'T *' has is being transformed such
3765 // that an Objective-C class type is being replaced for 'T'. The
3766 // resulting pointer type is an ObjCObjectPointerType, not a
3767 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003768 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
John McCall8b07ec22010-05-15 11:32:37 +00003770 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3771 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003772 return Result;
3773 }
John McCall31f82722010-11-12 08:19:04 +00003774
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003775 if (getDerived().AlwaysRebuild() ||
3776 PointeeType != TL.getPointeeLoc().getType()) {
3777 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3778 if (Result.isNull())
3779 return QualType();
3780 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003781
John McCall31168b02011-06-15 23:02:42 +00003782 // Objective-C ARC can add lifetime qualifiers to the type that we're
3783 // pointing to.
3784 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003785
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003786 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3787 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003788 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003789}
Mike Stump11289f42009-09-09 15:08:12 +00003790
3791template<typename Derived>
3792QualType
John McCall550e0c22009-10-21 00:40:46 +00003793TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003794 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003795 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003796 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3797 if (PointeeType.isNull())
3798 return QualType();
3799
3800 QualType Result = TL.getType();
3801 if (getDerived().AlwaysRebuild() ||
3802 PointeeType != TL.getPointeeLoc().getType()) {
3803 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003804 TL.getSigilLoc());
3805 if (Result.isNull())
3806 return QualType();
3807 }
3808
Douglas Gregor049211a2010-04-22 16:50:51 +00003809 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003810 NewT.setSigilLoc(TL.getSigilLoc());
3811 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812}
3813
John McCall70dd5f62009-10-30 00:06:24 +00003814/// Transforms a reference type. Note that somewhat paradoxically we
3815/// don't care whether the type itself is an l-value type or an r-value
3816/// type; we only care if the type was *written* as an l-value type
3817/// or an r-value type.
3818template<typename Derived>
3819QualType
3820TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003821 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003822 const ReferenceType *T = TL.getTypePtr();
3823
3824 // Note that this works with the pointee-as-written.
3825 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3826 if (PointeeType.isNull())
3827 return QualType();
3828
3829 QualType Result = TL.getType();
3830 if (getDerived().AlwaysRebuild() ||
3831 PointeeType != T->getPointeeTypeAsWritten()) {
3832 Result = getDerived().RebuildReferenceType(PointeeType,
3833 T->isSpelledAsLValue(),
3834 TL.getSigilLoc());
3835 if (Result.isNull())
3836 return QualType();
3837 }
3838
John McCall31168b02011-06-15 23:02:42 +00003839 // Objective-C ARC can add lifetime qualifiers to the type that we're
3840 // referring to.
3841 TLB.TypeWasModifiedSafely(
3842 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3843
John McCall70dd5f62009-10-30 00:06:24 +00003844 // r-value references can be rebuilt as l-value references.
3845 ReferenceTypeLoc NewTL;
3846 if (isa<LValueReferenceType>(Result))
3847 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3848 else
3849 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3850 NewTL.setSigilLoc(TL.getSigilLoc());
3851
3852 return Result;
3853}
3854
Mike Stump11289f42009-09-09 15:08:12 +00003855template<typename Derived>
3856QualType
John McCall550e0c22009-10-21 00:40:46 +00003857TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003858 LValueReferenceTypeLoc TL) {
3859 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003860}
3861
Mike Stump11289f42009-09-09 15:08:12 +00003862template<typename Derived>
3863QualType
John McCall550e0c22009-10-21 00:40:46 +00003864TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003865 RValueReferenceTypeLoc TL) {
3866 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003867}
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003870QualType
John McCall550e0c22009-10-21 00:40:46 +00003871TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003872 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003873 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003874 if (PointeeType.isNull())
3875 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003876
Abramo Bagnara509357842011-03-05 14:42:21 +00003877 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003878 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003879 if (OldClsTInfo) {
3880 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3881 if (!NewClsTInfo)
3882 return QualType();
3883 }
3884
3885 const MemberPointerType *T = TL.getTypePtr();
3886 QualType OldClsType = QualType(T->getClass(), 0);
3887 QualType NewClsType;
3888 if (NewClsTInfo)
3889 NewClsType = NewClsTInfo->getType();
3890 else {
3891 NewClsType = getDerived().TransformType(OldClsType);
3892 if (NewClsType.isNull())
3893 return QualType();
3894 }
Mike Stump11289f42009-09-09 15:08:12 +00003895
John McCall550e0c22009-10-21 00:40:46 +00003896 QualType Result = TL.getType();
3897 if (getDerived().AlwaysRebuild() ||
3898 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003899 NewClsType != OldClsType) {
3900 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003901 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003902 if (Result.isNull())
3903 return QualType();
3904 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905
Reid Kleckner0503a872013-12-05 01:23:43 +00003906 // If we had to adjust the pointee type when building a member pointer, make
3907 // sure to push TypeLoc info for it.
3908 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3909 if (MPT && PointeeType != MPT->getPointeeType()) {
3910 assert(isa<AdjustedType>(MPT->getPointeeType()));
3911 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3912 }
3913
John McCall550e0c22009-10-21 00:40:46 +00003914 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3915 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003916 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003917
3918 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919}
3920
Mike Stump11289f42009-09-09 15:08:12 +00003921template<typename Derived>
3922QualType
John McCall550e0c22009-10-21 00:40:46 +00003923TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003924 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003925 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003926 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003927 if (ElementType.isNull())
3928 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003929
John McCall550e0c22009-10-21 00:40:46 +00003930 QualType Result = TL.getType();
3931 if (getDerived().AlwaysRebuild() ||
3932 ElementType != T->getElementType()) {
3933 Result = getDerived().RebuildConstantArrayType(ElementType,
3934 T->getSizeModifier(),
3935 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003936 T->getIndexTypeCVRQualifiers(),
3937 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003938 if (Result.isNull())
3939 return QualType();
3940 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003941
3942 // We might have either a ConstantArrayType or a VariableArrayType now:
3943 // a ConstantArrayType is allowed to have an element type which is a
3944 // VariableArrayType if the type is dependent. Fortunately, all array
3945 // types have the same location layout.
3946 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003947 NewTL.setLBracketLoc(TL.getLBracketLoc());
3948 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003949
John McCall550e0c22009-10-21 00:40:46 +00003950 Expr *Size = TL.getSizeExpr();
3951 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003952 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3953 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003954 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3955 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003956 }
3957 NewTL.setSizeExpr(Size);
3958
3959 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003960}
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003964 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003965 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003966 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003967 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968 if (ElementType.isNull())
3969 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003970
John McCall550e0c22009-10-21 00:40:46 +00003971 QualType Result = TL.getType();
3972 if (getDerived().AlwaysRebuild() ||
3973 ElementType != T->getElementType()) {
3974 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003975 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003976 T->getIndexTypeCVRQualifiers(),
3977 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003978 if (Result.isNull())
3979 return QualType();
3980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003981
John McCall550e0c22009-10-21 00:40:46 +00003982 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3983 NewTL.setLBracketLoc(TL.getLBracketLoc());
3984 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003985 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003986
3987 return Result;
3988}
3989
3990template<typename Derived>
3991QualType
3992TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003993 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003994 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003995 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3996 if (ElementType.isNull())
3997 return QualType();
3998
John McCalldadc5752010-08-24 06:29:42 +00003999 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004000 = getDerived().TransformExpr(T->getSizeExpr());
4001 if (SizeResult.isInvalid())
4002 return QualType();
4003
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004004 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004005
4006 QualType Result = TL.getType();
4007 if (getDerived().AlwaysRebuild() ||
4008 ElementType != T->getElementType() ||
4009 Size != T->getSizeExpr()) {
4010 Result = getDerived().RebuildVariableArrayType(ElementType,
4011 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004012 Size,
John McCall550e0c22009-10-21 00:40:46 +00004013 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004014 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004015 if (Result.isNull())
4016 return QualType();
4017 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004018
Serge Pavlov774c6d02014-02-06 03:49:11 +00004019 // We might have constant size array now, but fortunately it has the same
4020 // location layout.
4021 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004022 NewTL.setLBracketLoc(TL.getLBracketLoc());
4023 NewTL.setRBracketLoc(TL.getRBracketLoc());
4024 NewTL.setSizeExpr(Size);
4025
4026 return Result;
4027}
4028
4029template<typename Derived>
4030QualType
4031TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004032 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004033 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004034 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4035 if (ElementType.isNull())
4036 return QualType();
4037
Richard Smith764d2fe2011-12-20 02:08:33 +00004038 // Array bounds are constant expressions.
4039 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4040 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004041
John McCall33ddac02011-01-19 10:06:00 +00004042 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4043 Expr *origSize = TL.getSizeExpr();
4044 if (!origSize) origSize = T->getSizeExpr();
4045
4046 ExprResult sizeResult
4047 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004048 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004049 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004050 return QualType();
4051
John McCall33ddac02011-01-19 10:06:00 +00004052 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004053
4054 QualType Result = TL.getType();
4055 if (getDerived().AlwaysRebuild() ||
4056 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004057 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004058 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4059 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004060 size,
John McCall550e0c22009-10-21 00:40:46 +00004061 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004062 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004063 if (Result.isNull())
4064 return QualType();
4065 }
John McCall550e0c22009-10-21 00:40:46 +00004066
4067 // We might have any sort of array type now, but fortunately they
4068 // all have the same location layout.
4069 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4070 NewTL.setLBracketLoc(TL.getLBracketLoc());
4071 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004072 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004073
4074 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075}
Mike Stump11289f42009-09-09 15:08:12 +00004076
4077template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004078QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004079 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004080 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004081 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004082
4083 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004084 QualType ElementType = getDerived().TransformType(T->getElementType());
4085 if (ElementType.isNull())
4086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004087
Richard Smith764d2fe2011-12-20 02:08:33 +00004088 // Vector sizes are constant expressions.
4089 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4090 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004091
John McCalldadc5752010-08-24 06:29:42 +00004092 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004093 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094 if (Size.isInvalid())
4095 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004096
John McCall550e0c22009-10-21 00:40:46 +00004097 QualType Result = TL.getType();
4098 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004099 ElementType != T->getElementType() ||
4100 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004101 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004102 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004104 if (Result.isNull())
4105 return QualType();
4106 }
John McCall550e0c22009-10-21 00:40:46 +00004107
4108 // Result might be dependent or not.
4109 if (isa<DependentSizedExtVectorType>(Result)) {
4110 DependentSizedExtVectorTypeLoc NewTL
4111 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4112 NewTL.setNameLoc(TL.getNameLoc());
4113 } else {
4114 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4115 NewTL.setNameLoc(TL.getNameLoc());
4116 }
4117
4118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004119}
Mike Stump11289f42009-09-09 15:08:12 +00004120
4121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004122QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004124 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125 QualType ElementType = getDerived().TransformType(T->getElementType());
4126 if (ElementType.isNull())
4127 return QualType();
4128
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004132 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004133 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004134 if (Result.isNull())
4135 return QualType();
4136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004137
John McCall550e0c22009-10-21 00:40:46 +00004138 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4139 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004140
John McCall550e0c22009-10-21 00:40:46 +00004141 return Result;
4142}
4143
4144template<typename Derived>
4145QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004146 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004147 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004148 QualType ElementType = getDerived().TransformType(T->getElementType());
4149 if (ElementType.isNull())
4150 return QualType();
4151
4152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
4154 ElementType != T->getElementType()) {
4155 Result = getDerived().RebuildExtVectorType(ElementType,
4156 T->getNumElements(),
4157 /*FIXME*/ SourceLocation());
4158 if (Result.isNull())
4159 return QualType();
4160 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004161
John McCall550e0c22009-10-21 00:40:46 +00004162 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4163 NewTL.setNameLoc(TL.getNameLoc());
4164
4165 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166}
Mike Stump11289f42009-09-09 15:08:12 +00004167
David Blaikie05785d12013-02-20 22:23:23 +00004168template <typename Derived>
4169ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4170 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4171 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004172 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004173 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004174
Douglas Gregor715e4612011-01-14 22:40:04 +00004175 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004176 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004177 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004178 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004179 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
Douglas Gregor715e4612011-01-14 22:40:04 +00004181 TypeLocBuilder TLB;
4182 TypeLoc NewTL = OldDI->getTypeLoc();
4183 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004184
4185 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004186 OldExpansionTL.getPatternLoc());
4187 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004188 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004189
4190 Result = RebuildPackExpansionType(Result,
4191 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004192 OldExpansionTL.getEllipsisLoc(),
4193 NumExpansions);
4194 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004195 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004196
Douglas Gregor715e4612011-01-14 22:40:04 +00004197 PackExpansionTypeLoc NewExpansionTL
4198 = TLB.push<PackExpansionTypeLoc>(Result);
4199 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4200 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4201 } else
4202 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004203 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004204 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004205
John McCall8fb0d9d2011-05-01 22:35:37 +00004206 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004207 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004208
4209 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4210 OldParm->getDeclContext(),
4211 OldParm->getInnerLocStart(),
4212 OldParm->getLocation(),
4213 OldParm->getIdentifier(),
4214 NewDI->getType(),
4215 NewDI,
4216 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004217 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004218 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4219 OldParm->getFunctionScopeIndex() + indexAdjustment);
4220 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004221}
4222
4223template<typename Derived>
4224bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004225 TransformFunctionTypeParams(SourceLocation Loc,
4226 ParmVarDecl **Params, unsigned NumParams,
4227 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004228 SmallVectorImpl<QualType> &OutParamTypes,
4229 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004230 int indexAdjustment = 0;
4231
Douglas Gregordd472162011-01-07 00:20:55 +00004232 for (unsigned i = 0; i != NumParams; ++i) {
4233 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004234 assert(OldParm->getFunctionScopeIndex() == i);
4235
David Blaikie05785d12013-02-20 22:23:23 +00004236 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004237 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004238 if (OldParm->isParameterPack()) {
4239 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004240 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004241
Douglas Gregor5499af42011-01-05 23:12:31 +00004242 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004243 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004244 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004245 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4246 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004247 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4248
Douglas Gregor5499af42011-01-05 23:12:31 +00004249 // Determine whether we should expand the parameter packs.
4250 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004251 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004252 Optional<unsigned> OrigNumExpansions =
4253 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004254 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004255 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4256 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004257 Unexpanded,
4258 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004259 RetainExpansion,
4260 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004261 return true;
4262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004263
Douglas Gregor5499af42011-01-05 23:12:31 +00004264 if (ShouldExpand) {
4265 // Expand the function parameter pack into multiple, separate
4266 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004267 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004268 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004269 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004270 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004271 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004272 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004273 OrigNumExpansions,
4274 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004275 if (!NewParm)
4276 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004277
Douglas Gregordd472162011-01-07 00:20:55 +00004278 OutParamTypes.push_back(NewParm->getType());
4279 if (PVars)
4280 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004281 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004282
4283 // If we're supposed to retain a pack expansion, do so by temporarily
4284 // forgetting the partially-substituted parameter pack.
4285 if (RetainExpansion) {
4286 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004287 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004288 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004289 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004290 OrigNumExpansions,
4291 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004292 if (!NewParm)
4293 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004294
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004295 OutParamTypes.push_back(NewParm->getType());
4296 if (PVars)
4297 PVars->push_back(NewParm);
4298 }
4299
John McCall8fb0d9d2011-05-01 22:35:37 +00004300 // The next parameter should have the same adjustment as the
4301 // last thing we pushed, but we post-incremented indexAdjustment
4302 // on every push. Also, if we push nothing, the adjustment should
4303 // go down by one.
4304 indexAdjustment--;
4305
Douglas Gregor5499af42011-01-05 23:12:31 +00004306 // We're done with the pack expansion.
4307 continue;
4308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004309
4310 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004312 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4313 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004314 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004315 NumExpansions,
4316 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004317 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004318 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004319 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004320 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004321
John McCall58f10c32010-03-11 09:03:00 +00004322 if (!NewParm)
4323 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004324
Douglas Gregordd472162011-01-07 00:20:55 +00004325 OutParamTypes.push_back(NewParm->getType());
4326 if (PVars)
4327 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004328 continue;
4329 }
John McCall58f10c32010-03-11 09:03:00 +00004330
4331 // Deal with the possibility that we don't have a parameter
4332 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004333 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004334 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004335 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004336 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004337 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 = dyn_cast<PackExpansionType>(OldType)) {
4339 // We have a function parameter pack that may need to be expanded.
4340 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004341 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004342 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004343
Douglas Gregor5499af42011-01-05 23:12:31 +00004344 // Determine whether we should expand the parameter packs.
4345 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004346 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004347 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004348 Unexpanded,
4349 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004350 RetainExpansion,
4351 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004352 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004354
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004356 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004357 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004358 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004359 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4360 QualType NewType = getDerived().TransformType(Pattern);
4361 if (NewType.isNull())
4362 return true;
John McCall58f10c32010-03-11 09:03:00 +00004363
Douglas Gregordd472162011-01-07 00:20:55 +00004364 OutParamTypes.push_back(NewType);
4365 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004366 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004368
Douglas Gregor5499af42011-01-05 23:12:31 +00004369 // We're done with the pack expansion.
4370 continue;
4371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor48d24112011-01-10 20:53:55 +00004373 // If we're supposed to retain a pack expansion, do so by temporarily
4374 // forgetting the partially-substituted parameter pack.
4375 if (RetainExpansion) {
4376 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4377 QualType NewType = getDerived().TransformType(Pattern);
4378 if (NewType.isNull())
4379 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004380
Douglas Gregor48d24112011-01-10 20:53:55 +00004381 OutParamTypes.push_back(NewType);
4382 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004383 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004384 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004385
Chad Rosier1dcde962012-08-08 18:46:20 +00004386 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004387 // expansion.
4388 OldType = Expansion->getPattern();
4389 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004390 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4391 NewType = getDerived().TransformType(OldType);
4392 } else {
4393 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004395
Douglas Gregor5499af42011-01-05 23:12:31 +00004396 if (NewType.isNull())
4397 return true;
4398
4399 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004400 NewType = getSema().Context.getPackExpansionType(NewType,
4401 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004402
Douglas Gregordd472162011-01-07 00:20:55 +00004403 OutParamTypes.push_back(NewType);
4404 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004405 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004406 }
4407
John McCall8fb0d9d2011-05-01 22:35:37 +00004408#ifndef NDEBUG
4409 if (PVars) {
4410 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4411 if (ParmVarDecl *parm = (*PVars)[i])
4412 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004413 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004414#endif
4415
4416 return false;
4417}
John McCall58f10c32010-03-11 09:03:00 +00004418
4419template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004420QualType
John McCall550e0c22009-10-21 00:40:46 +00004421TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004422 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004423 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004424}
4425
4426template<typename Derived>
4427QualType
4428TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4429 FunctionProtoTypeLoc TL,
4430 CXXRecordDecl *ThisContext,
4431 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004432 // Transform the parameters and return type.
4433 //
Richard Smithf623c962012-04-17 00:58:00 +00004434 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004435 // When the function has a trailing return type, we instantiate the
4436 // parameters before the return type, since the return type can then refer
4437 // to the parameters themselves (via decltype, sizeof, etc.).
4438 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004439 SmallVector<QualType, 4> ParamTypes;
4440 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004441 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004442
Douglas Gregor7fb25412010-10-01 18:44:50 +00004443 QualType ResultType;
4444
Richard Smith1226c602012-08-14 22:51:13 +00004445 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004446 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004447 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004448 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004449 return QualType();
4450
Douglas Gregor3024f072012-04-16 07:05:22 +00004451 {
4452 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004453 // If a declaration declares a member function or member function
4454 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004455 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004456 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004457 // declarator.
4458 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004459
Alp Toker42a16a62014-01-25 23:51:36 +00004460 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004461 if (ResultType.isNull())
4462 return QualType();
4463 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004464 }
4465 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004466 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004467 if (ResultType.isNull())
4468 return QualType();
4469
Alp Toker9cacbab2014-01-20 20:26:09 +00004470 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004471 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004472 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004473 return QualType();
4474 }
4475
Richard Smithf623c962012-04-17 00:58:00 +00004476 // FIXME: Need to transform the exception-specification too.
4477
John McCall550e0c22009-10-21 00:40:46 +00004478 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004479 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004480 T->getNumParams() != ParamTypes.size() ||
4481 !std::equal(T->param_type_begin(), T->param_type_end(),
4482 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004483 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004484 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004485 if (Result.isNull())
4486 return QualType();
4487 }
Mike Stump11289f42009-09-09 15:08:12 +00004488
John McCall550e0c22009-10-21 00:40:46 +00004489 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004490 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004491 NewTL.setLParenLoc(TL.getLParenLoc());
4492 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004493 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004494 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4495 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004496
4497 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004498}
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregord6ff3322009-08-04 16:50:30 +00004500template<typename Derived>
4501QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004502 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004503 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004504 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004505 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004506 if (ResultType.isNull())
4507 return QualType();
4508
4509 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004510 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004511 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4512
4513 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004514 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004515 NewTL.setLParenLoc(TL.getLParenLoc());
4516 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004517 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004518
4519 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004520}
Mike Stump11289f42009-09-09 15:08:12 +00004521
John McCallb96ec562009-12-04 22:46:56 +00004522template<typename Derived> QualType
4523TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004524 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004525 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004526 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004527 if (!D)
4528 return QualType();
4529
4530 QualType Result = TL.getType();
4531 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4532 Result = getDerived().RebuildUnresolvedUsingType(D);
4533 if (Result.isNull())
4534 return QualType();
4535 }
4536
4537 // We might get an arbitrary type spec type back. We should at
4538 // least always get a type spec type, though.
4539 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4540 NewTL.setNameLoc(TL.getNameLoc());
4541
4542 return Result;
4543}
4544
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004546QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004547 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004548 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004549 TypedefNameDecl *Typedef
4550 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4551 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552 if (!Typedef)
4553 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004554
John McCall550e0c22009-10-21 00:40:46 +00004555 QualType Result = TL.getType();
4556 if (getDerived().AlwaysRebuild() ||
4557 Typedef != T->getDecl()) {
4558 Result = getDerived().RebuildTypedefType(Typedef);
4559 if (Result.isNull())
4560 return QualType();
4561 }
Mike Stump11289f42009-09-09 15:08:12 +00004562
John McCall550e0c22009-10-21 00:40:46 +00004563 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4564 NewTL.setNameLoc(TL.getNameLoc());
4565
4566 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004567}
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004570QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004571 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004572 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4574 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCalldadc5752010-08-24 06:29:42 +00004576 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004577 if (E.isInvalid())
4578 return QualType();
4579
Eli Friedmane4f22df2012-02-29 04:03:55 +00004580 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4581 if (E.isInvalid())
4582 return QualType();
4583
John McCall550e0c22009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004586 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004587 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004591 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCall550e0c22009-10-21 00:40:46 +00004593 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004594 NewTL.setTypeofLoc(TL.getTypeofLoc());
4595 NewTL.setLParenLoc(TL.getLParenLoc());
4596 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004597
4598 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004599}
Mike Stump11289f42009-09-09 15:08:12 +00004600
4601template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004602QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004603 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004604 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4605 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4606 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004607 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004608
John McCall550e0c22009-10-21 00:40:46 +00004609 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004610 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4611 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004612 if (Result.isNull())
4613 return QualType();
4614 }
Mike Stump11289f42009-09-09 15:08:12 +00004615
John McCall550e0c22009-10-21 00:40:46 +00004616 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004617 NewTL.setTypeofLoc(TL.getTypeofLoc());
4618 NewTL.setLParenLoc(TL.getLParenLoc());
4619 NewTL.setRParenLoc(TL.getRParenLoc());
4620 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004621
4622 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004623}
Mike Stump11289f42009-09-09 15:08:12 +00004624
4625template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004626QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004627 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004628 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004629
Douglas Gregore922c772009-08-04 22:27:00 +00004630 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004631 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4632 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004633
John McCalldadc5752010-08-24 06:29:42 +00004634 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004635 if (E.isInvalid())
4636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004637
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004638 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004639 if (E.isInvalid())
4640 return QualType();
4641
John McCall550e0c22009-10-21 00:40:46 +00004642 QualType Result = TL.getType();
4643 if (getDerived().AlwaysRebuild() ||
4644 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004645 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004646 if (Result.isNull())
4647 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004649 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004650
John McCall550e0c22009-10-21 00:40:46 +00004651 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4652 NewTL.setNameLoc(TL.getNameLoc());
4653
4654 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004655}
4656
4657template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004658QualType TreeTransform<Derived>::TransformUnaryTransformType(
4659 TypeLocBuilder &TLB,
4660 UnaryTransformTypeLoc TL) {
4661 QualType Result = TL.getType();
4662 if (Result->isDependentType()) {
4663 const UnaryTransformType *T = TL.getTypePtr();
4664 QualType NewBase =
4665 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4666 Result = getDerived().RebuildUnaryTransformType(NewBase,
4667 T->getUTTKind(),
4668 TL.getKWLoc());
4669 if (Result.isNull())
4670 return QualType();
4671 }
4672
4673 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4674 NewTL.setKWLoc(TL.getKWLoc());
4675 NewTL.setParensRange(TL.getParensRange());
4676 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4677 return Result;
4678}
4679
4680template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004681QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4682 AutoTypeLoc TL) {
4683 const AutoType *T = TL.getTypePtr();
4684 QualType OldDeduced = T->getDeducedType();
4685 QualType NewDeduced;
4686 if (!OldDeduced.isNull()) {
4687 NewDeduced = getDerived().TransformType(OldDeduced);
4688 if (NewDeduced.isNull())
4689 return QualType();
4690 }
4691
4692 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004693 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4694 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004695 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004696 if (Result.isNull())
4697 return QualType();
4698 }
4699
4700 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4701 NewTL.setNameLoc(TL.getNameLoc());
4702
4703 return Result;
4704}
4705
4706template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004707QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004708 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004709 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004710 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004711 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4712 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004713 if (!Record)
4714 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCall550e0c22009-10-21 00:40:46 +00004716 QualType Result = TL.getType();
4717 if (getDerived().AlwaysRebuild() ||
4718 Record != T->getDecl()) {
4719 Result = getDerived().RebuildRecordType(Record);
4720 if (Result.isNull())
4721 return QualType();
4722 }
Mike Stump11289f42009-09-09 15:08:12 +00004723
John McCall550e0c22009-10-21 00:40:46 +00004724 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4725 NewTL.setNameLoc(TL.getNameLoc());
4726
4727 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728}
Mike Stump11289f42009-09-09 15:08:12 +00004729
4730template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004731QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004732 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004733 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004734 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004735 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4736 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004737 if (!Enum)
4738 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004739
John McCall550e0c22009-10-21 00:40:46 +00004740 QualType Result = TL.getType();
4741 if (getDerived().AlwaysRebuild() ||
4742 Enum != T->getDecl()) {
4743 Result = getDerived().RebuildEnumType(Enum);
4744 if (Result.isNull())
4745 return QualType();
4746 }
Mike Stump11289f42009-09-09 15:08:12 +00004747
John McCall550e0c22009-10-21 00:40:46 +00004748 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4749 NewTL.setNameLoc(TL.getNameLoc());
4750
4751 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004752}
John McCallfcc33b02009-09-05 00:15:47 +00004753
John McCalle78aac42010-03-10 03:28:59 +00004754template<typename Derived>
4755QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4756 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004757 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004758 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4759 TL.getTypePtr()->getDecl());
4760 if (!D) return QualType();
4761
4762 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4763 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4764 return T;
4765}
4766
Douglas Gregord6ff3322009-08-04 16:50:30 +00004767template<typename Derived>
4768QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004769 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004770 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004771 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772}
4773
Mike Stump11289f42009-09-09 15:08:12 +00004774template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004775QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004776 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004777 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004778 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004779
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004780 // Substitute into the replacement type, which itself might involve something
4781 // that needs to be transformed. This only tends to occur with default
4782 // template arguments of template template parameters.
4783 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4784 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4785 if (Replacement.isNull())
4786 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004787
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004788 // Always canonicalize the replacement type.
4789 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4790 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004791 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004792 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004794 // Propagate type-source information.
4795 SubstTemplateTypeParmTypeLoc NewTL
4796 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4797 NewTL.setNameLoc(TL.getNameLoc());
4798 return Result;
4799
John McCallcebee162009-10-18 09:09:24 +00004800}
4801
4802template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004803QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4804 TypeLocBuilder &TLB,
4805 SubstTemplateTypeParmPackTypeLoc TL) {
4806 return TransformTypeSpecType(TLB, TL);
4807}
4808
4809template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004810QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004811 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004812 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004813 const TemplateSpecializationType *T = TL.getTypePtr();
4814
Douglas Gregordf846d12011-03-02 18:46:51 +00004815 // The nested-name-specifier never matters in a TemplateSpecializationType,
4816 // because we can't have a dependent nested-name-specifier anyway.
4817 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004818 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004819 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4820 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004821 if (Template.isNull())
4822 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004823
John McCall31f82722010-11-12 08:19:04 +00004824 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4825}
4826
Eli Friedman0dfb8892011-10-06 23:00:33 +00004827template<typename Derived>
4828QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4829 AtomicTypeLoc TL) {
4830 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4831 if (ValueType.isNull())
4832 return QualType();
4833
4834 QualType Result = TL.getType();
4835 if (getDerived().AlwaysRebuild() ||
4836 ValueType != TL.getValueLoc().getType()) {
4837 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4838 if (Result.isNull())
4839 return QualType();
4840 }
4841
4842 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4843 NewTL.setKWLoc(TL.getKWLoc());
4844 NewTL.setLParenLoc(TL.getLParenLoc());
4845 NewTL.setRParenLoc(TL.getRParenLoc());
4846
4847 return Result;
4848}
4849
Chad Rosier1dcde962012-08-08 18:46:20 +00004850 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004851 /// container that provides a \c getArgLoc() member function.
4852 ///
4853 /// This iterator is intended to be used with the iterator form of
4854 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4855 template<typename ArgLocContainer>
4856 class TemplateArgumentLocContainerIterator {
4857 ArgLocContainer *Container;
4858 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004859
Douglas Gregorfe921a72010-12-20 23:36:19 +00004860 public:
4861 typedef TemplateArgumentLoc value_type;
4862 typedef TemplateArgumentLoc reference;
4863 typedef int difference_type;
4864 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
Douglas Gregorfe921a72010-12-20 23:36:19 +00004866 class pointer {
4867 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004868
Douglas Gregorfe921a72010-12-20 23:36:19 +00004869 public:
4870 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
Douglas Gregorfe921a72010-12-20 23:36:19 +00004872 const TemplateArgumentLoc *operator->() const {
4873 return &Arg;
4874 }
4875 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004876
4877
Douglas Gregorfe921a72010-12-20 23:36:19 +00004878 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
Douglas Gregorfe921a72010-12-20 23:36:19 +00004880 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4881 unsigned Index)
4882 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004883
Douglas Gregorfe921a72010-12-20 23:36:19 +00004884 TemplateArgumentLocContainerIterator &operator++() {
4885 ++Index;
4886 return *this;
4887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregorfe921a72010-12-20 23:36:19 +00004889 TemplateArgumentLocContainerIterator operator++(int) {
4890 TemplateArgumentLocContainerIterator Old(*this);
4891 ++(*this);
4892 return Old;
4893 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004894
Douglas Gregorfe921a72010-12-20 23:36:19 +00004895 TemplateArgumentLoc operator*() const {
4896 return Container->getArgLoc(Index);
4897 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004898
Douglas Gregorfe921a72010-12-20 23:36:19 +00004899 pointer operator->() const {
4900 return pointer(Container->getArgLoc(Index));
4901 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004902
Douglas Gregorfe921a72010-12-20 23:36:19 +00004903 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004904 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004905 return X.Container == Y.Container && X.Index == Y.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 == Y);
4911 }
4912 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004913
4914
John McCall31f82722010-11-12 08:19:04 +00004915template <typename Derived>
4916QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4917 TypeLocBuilder &TLB,
4918 TemplateSpecializationTypeLoc TL,
4919 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004920 TemplateArgumentListInfo NewTemplateArgs;
4921 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4922 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004923 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4924 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004925 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004926 ArgIterator(TL, TL.getNumArgs()),
4927 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004928 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004929
John McCall0ad16662009-10-29 08:12:44 +00004930 // FIXME: maybe don't rebuild if all the template arguments are the same.
4931
4932 QualType Result =
4933 getDerived().RebuildTemplateSpecializationType(Template,
4934 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004935 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004936
4937 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004938 // Specializations of template template parameters are represented as
4939 // TemplateSpecializationTypes, and substitution of type alias templates
4940 // within a dependent context can transform them into
4941 // DependentTemplateSpecializationTypes.
4942 if (isa<DependentTemplateSpecializationType>(Result)) {
4943 DependentTemplateSpecializationTypeLoc NewTL
4944 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004945 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004946 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004947 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004948 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004949 NewTL.setLAngleLoc(TL.getLAngleLoc());
4950 NewTL.setRAngleLoc(TL.getRAngleLoc());
4951 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4952 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4953 return Result;
4954 }
4955
John McCall0ad16662009-10-29 08:12:44 +00004956 TemplateSpecializationTypeLoc NewTL
4957 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004958 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004959 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4960 NewTL.setLAngleLoc(TL.getLAngleLoc());
4961 NewTL.setRAngleLoc(TL.getRAngleLoc());
4962 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4963 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004964 }
Mike Stump11289f42009-09-09 15:08:12 +00004965
John McCall0ad16662009-10-29 08:12:44 +00004966 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004967}
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregor5a064722011-02-28 17:23:35 +00004969template <typename Derived>
4970QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4971 TypeLocBuilder &TLB,
4972 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004973 TemplateName Template,
4974 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004975 TemplateArgumentListInfo NewTemplateArgs;
4976 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4977 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4978 typedef TemplateArgumentLocContainerIterator<
4979 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004980 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004981 ArgIterator(TL, TL.getNumArgs()),
4982 NewTemplateArgs))
4983 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004984
Douglas Gregor5a064722011-02-28 17:23:35 +00004985 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004986
Douglas Gregor5a064722011-02-28 17:23:35 +00004987 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4988 QualType Result
4989 = getSema().Context.getDependentTemplateSpecializationType(
4990 TL.getTypePtr()->getKeyword(),
4991 DTN->getQualifier(),
4992 DTN->getIdentifier(),
4993 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004994
Douglas Gregor5a064722011-02-28 17:23:35 +00004995 DependentTemplateSpecializationTypeLoc NewTL
4996 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004997 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004998 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004999 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005000 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005001 NewTL.setLAngleLoc(TL.getLAngleLoc());
5002 NewTL.setRAngleLoc(TL.getRAngleLoc());
5003 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5004 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5005 return Result;
5006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
5008 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005009 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005010 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005011 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005012
Douglas Gregor5a064722011-02-28 17:23:35 +00005013 if (!Result.isNull()) {
5014 /// FIXME: Wrap this in an elaborated-type-specifier?
5015 TemplateSpecializationTypeLoc NewTL
5016 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005017 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005018 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005019 NewTL.setLAngleLoc(TL.getLAngleLoc());
5020 NewTL.setRAngleLoc(TL.getRAngleLoc());
5021 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5022 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005024
Douglas Gregor5a064722011-02-28 17:23:35 +00005025 return Result;
5026}
5027
Mike Stump11289f42009-09-09 15:08:12 +00005028template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005029QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005030TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005031 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005032 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005033
Douglas Gregor844cb502011-03-01 18:12:44 +00005034 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005035 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005036 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005037 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005038 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5039 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005040 return QualType();
5041 }
Mike Stump11289f42009-09-09 15:08:12 +00005042
John McCall31f82722010-11-12 08:19:04 +00005043 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5044 if (NamedT.isNull())
5045 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005046
Richard Smith3f1b5d02011-05-05 21:57:07 +00005047 // C++0x [dcl.type.elab]p2:
5048 // If the identifier resolves to a typedef-name or the simple-template-id
5049 // resolves to an alias template specialization, the
5050 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005051 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5052 if (const TemplateSpecializationType *TST =
5053 NamedT->getAs<TemplateSpecializationType>()) {
5054 TemplateName Template = TST->getTemplateName();
5055 if (TypeAliasTemplateDecl *TAT =
5056 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5057 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5058 diag::err_tag_reference_non_tag) << 4;
5059 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5060 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005061 }
5062 }
5063
John McCall550e0c22009-10-21 00:40:46 +00005064 QualType Result = TL.getType();
5065 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005066 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005067 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005068 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005069 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005070 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005071 if (Result.isNull())
5072 return QualType();
5073 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005074
Abramo Bagnara6150c882010-05-11 21:36:43 +00005075 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005076 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005077 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005079}
Mike Stump11289f42009-09-09 15:08:12 +00005080
5081template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005082QualType TreeTransform<Derived>::TransformAttributedType(
5083 TypeLocBuilder &TLB,
5084 AttributedTypeLoc TL) {
5085 const AttributedType *oldType = TL.getTypePtr();
5086 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5087 if (modifiedType.isNull())
5088 return QualType();
5089
5090 QualType result = TL.getType();
5091
5092 // FIXME: dependent operand expressions?
5093 if (getDerived().AlwaysRebuild() ||
5094 modifiedType != oldType->getModifiedType()) {
5095 // TODO: this is really lame; we should really be rebuilding the
5096 // equivalent type from first principles.
5097 QualType equivalentType
5098 = getDerived().TransformType(oldType->getEquivalentType());
5099 if (equivalentType.isNull())
5100 return QualType();
5101 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5102 modifiedType,
5103 equivalentType);
5104 }
5105
5106 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5107 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5108 if (TL.hasAttrOperand())
5109 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5110 if (TL.hasAttrExprOperand())
5111 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5112 else if (TL.hasAttrEnumOperand())
5113 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5114
5115 return result;
5116}
5117
5118template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005119QualType
5120TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5121 ParenTypeLoc TL) {
5122 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5123 if (Inner.isNull())
5124 return QualType();
5125
5126 QualType Result = TL.getType();
5127 if (getDerived().AlwaysRebuild() ||
5128 Inner != TL.getInnerLoc().getType()) {
5129 Result = getDerived().RebuildParenType(Inner);
5130 if (Result.isNull())
5131 return QualType();
5132 }
5133
5134 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5135 NewTL.setLParenLoc(TL.getLParenLoc());
5136 NewTL.setRParenLoc(TL.getRParenLoc());
5137 return Result;
5138}
5139
5140template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005141QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005142 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005143 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005144
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005145 NestedNameSpecifierLoc QualifierLoc
5146 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5147 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005148 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005149
John McCallc392f372010-06-11 00:33:02 +00005150 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005151 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005152 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005153 QualifierLoc,
5154 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005155 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005156 if (Result.isNull())
5157 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005158
Abramo Bagnarad7548482010-05-19 21:37:53 +00005159 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5160 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005161 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5162
Abramo Bagnarad7548482010-05-19 21:37:53 +00005163 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005164 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005165 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005166 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005167 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005168 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005169 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005170 NewTL.setNameLoc(TL.getNameLoc());
5171 }
John McCall550e0c22009-10-21 00:40:46 +00005172 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173}
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregord6ff3322009-08-04 16:50:30 +00005175template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005176QualType TreeTransform<Derived>::
5177 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005178 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005179 NestedNameSpecifierLoc QualifierLoc;
5180 if (TL.getQualifierLoc()) {
5181 QualifierLoc
5182 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5183 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005184 return QualType();
5185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005186
John McCall31f82722010-11-12 08:19:04 +00005187 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005189}
5190
5191template<typename Derived>
5192QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005193TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5194 DependentTemplateSpecializationTypeLoc TL,
5195 NestedNameSpecifierLoc QualifierLoc) {
5196 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005197
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198 TemplateArgumentListInfo NewTemplateArgs;
5199 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5200 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005201
Douglas Gregora7a795b2011-03-01 20:11:18 +00005202 typedef TemplateArgumentLocContainerIterator<
5203 DependentTemplateSpecializationTypeLoc> ArgIterator;
5204 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5205 ArgIterator(TL, TL.getNumArgs()),
5206 NewTemplateArgs))
5207 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
Douglas Gregora7a795b2011-03-01 20:11:18 +00005209 QualType Result
5210 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5211 QualifierLoc,
5212 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005213 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005214 NewTemplateArgs);
5215 if (Result.isNull())
5216 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005217
Douglas Gregora7a795b2011-03-01 20:11:18 +00005218 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5219 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005220
Douglas Gregora7a795b2011-03-01 20:11:18 +00005221 // Copy information relevant to the template specialization.
5222 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005223 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005224 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005225 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005226 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5227 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005228 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005229 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
Douglas Gregora7a795b2011-03-01 20:11:18 +00005231 // Copy information relevant to the elaborated type.
5232 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005233 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005234 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005235 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5236 DependentTemplateSpecializationTypeLoc SpecTL
5237 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005238 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005239 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005240 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005241 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005242 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5243 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005244 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005245 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005246 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005247 TemplateSpecializationTypeLoc SpecTL
5248 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005249 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005250 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005251 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5252 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005253 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005254 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005255 }
5256 return Result;
5257}
5258
5259template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005260QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5261 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005262 QualType Pattern
5263 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005264 if (Pattern.isNull())
5265 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005266
5267 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005268 if (getDerived().AlwaysRebuild() ||
5269 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005270 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005271 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005272 TL.getEllipsisLoc(),
5273 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005274 if (Result.isNull())
5275 return QualType();
5276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005277
Douglas Gregor822d0302011-01-12 17:07:58 +00005278 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5279 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5280 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005281}
5282
5283template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005284QualType
5285TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005286 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005287 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005288 TLB.pushFullCopy(TL);
5289 return TL.getType();
5290}
5291
5292template<typename Derived>
5293QualType
5294TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005295 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005296 // ObjCObjectType is never dependent.
5297 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005298 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005299}
Mike Stump11289f42009-09-09 15:08:12 +00005300
5301template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005302QualType
5303TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005304 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005305 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005306 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005307 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005308}
5309
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005311// Statement transformation
5312//===----------------------------------------------------------------------===//
5313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005314StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005315TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005316 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005317}
5318
5319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005320StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005321TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5322 return getDerived().TransformCompoundStmt(S, false);
5323}
5324
5325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005326StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005327TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005329 Sema::CompoundScopeRAII CompoundScope(getSema());
5330
John McCall1ababa62010-08-27 19:56:05 +00005331 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005332 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005333 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005334 for (auto *B : S->body()) {
5335 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005336 if (Result.isInvalid()) {
5337 // Immediately fail if this was a DeclStmt, since it's very
5338 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005339 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005340 return StmtError();
5341
5342 // Otherwise, just keep processing substatements and fail later.
5343 SubStmtInvalid = true;
5344 continue;
5345 }
Mike Stump11289f42009-09-09 15:08:12 +00005346
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005347 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005348 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 }
Mike Stump11289f42009-09-09 15:08:12 +00005350
John McCall1ababa62010-08-27 19:56:05 +00005351 if (SubStmtInvalid)
5352 return StmtError();
5353
Douglas Gregorebe10102009-08-20 07:17:43 +00005354 if (!getDerived().AlwaysRebuild() &&
5355 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005356 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005357
5358 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005359 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005360 S->getRBracLoc(),
5361 IsStmtExpr);
5362}
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregorebe10102009-08-20 07:17:43 +00005364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005365StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005366TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005367 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005368 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005369 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5370 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005371
Eli Friedman06577382009-11-19 03:14:00 +00005372 // Transform the left-hand case value.
5373 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005374 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005375 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005376 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005377
Eli Friedman06577382009-11-19 03:14:00 +00005378 // Transform the right-hand case value (for the GNU case-range extension).
5379 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005380 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005381 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005383 }
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 // Build the case statement.
5386 // Case statements are always rebuilt so that they will attached to their
5387 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005388 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005389 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005390 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005391 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005392 S->getColonLoc());
5393 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregorebe10102009-08-20 07:17:43 +00005396 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005397 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 if (SubStmt.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 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005402 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005403}
5404
5405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005406StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005407TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005409 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005410 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 // Default statements are always rebuilt
5414 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005415 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005416}
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregorebe10102009-08-20 07:17:43 +00005418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005420TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005421 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005422 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005424
Chris Lattnercab02a62011-02-17 20:34:02 +00005425 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5426 S->getDecl());
5427 if (!LD)
5428 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005429
5430
Douglas Gregorebe10102009-08-20 07:17:43 +00005431 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005432 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005433 cast<LabelDecl>(LD), SourceLocation(),
5434 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005435}
Mike Stump11289f42009-09-09 15:08:12 +00005436
Douglas Gregorebe10102009-08-20 07:17:43 +00005437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005438StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005439TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5440 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5441 if (SubStmt.isInvalid())
5442 return StmtError();
5443
5444 // TODO: transform attributes
5445 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5446 return S;
5447
5448 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5449 S->getAttrs(),
5450 SubStmt.get());
5451}
5452
5453template<typename Derived>
5454StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005455TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005456 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005457 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005458 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005459 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005460 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005461 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005462 getDerived().TransformDefinition(
5463 S->getConditionVariable()->getLocation(),
5464 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005465 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005467 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005468 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005469
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005470 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005472
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005473 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005474 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005475 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005476 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005477 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005478 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
John McCallb268a282010-08-23 23:25:46 +00005480 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005481 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005483
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005484 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005485 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005489 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005494 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005495 if (Else.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 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005499 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005500 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 Then.get() == S->getThen() &&
5502 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005503 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005505 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005506 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005507 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005508}
5509
5510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005511StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005512TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005513 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005514 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005515 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005516 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005517 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005518 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005519 getDerived().TransformDefinition(
5520 S->getConditionVariable()->getLocation(),
5521 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005522 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005524 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005525 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005526
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005527 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005529 }
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregorebe10102009-08-20 07:17:43 +00005531 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005532 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005533 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005534 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005535 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005537
Douglas Gregorebe10102009-08-20 07:17:43 +00005538 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005539 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 if (Body.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 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005544 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5545 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorebe10102009-08-20 07:17:43 +00005548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005550TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005552 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005553 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005554 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005555 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005556 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005557 getDerived().TransformDefinition(
5558 S->getConditionVariable()->getLocation(),
5559 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005560 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005562 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005563 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005564
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005567
5568 if (S->getCond()) {
5569 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005570 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5571 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005572 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005573 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005575 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005576 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005577 }
Mike Stump11289f42009-09-09 15:08:12 +00005578
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005579 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005580 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005582
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005584 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005589 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005590 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005591 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005592 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005594 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005595 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005596}
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregorebe10102009-08-20 07:17:43 +00005598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005599StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005600TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005602 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005606 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005607 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005608 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005610
Douglas Gregorebe10102009-08-20 07:17:43 +00005611 if (!getDerived().AlwaysRebuild() &&
5612 Cond.get() == S->getCond() &&
5613 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005614 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005615
John McCallb268a282010-08-23 23:25:46 +00005616 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5617 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005618 S->getRParenLoc());
5619}
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregorebe10102009-08-20 07:17:43 +00005621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005622StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005623TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005625 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005626 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005627 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregorebe10102009-08-20 07:17:43 +00005629 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005630 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005631 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005632 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005633 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005634 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005635 getDerived().TransformDefinition(
5636 S->getConditionVariable()->getLocation(),
5637 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005638 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005640 } else {
5641 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005642
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005643 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005645
5646 if (S->getCond()) {
5647 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005648 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5649 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005650 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005651 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005653
John McCallb268a282010-08-23 23:25:46 +00005654 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005655 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005656 }
Mike Stump11289f42009-09-09 15:08:12 +00005657
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005658 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005659 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005661
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005663 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005664 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005666
Richard Smith945f8d32013-01-14 22:39:08 +00005667 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005668 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005672 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 if (!getDerived().AlwaysRebuild() &&
5677 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005678 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 Inc.get() == S->getInc() &&
5680 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005681 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005684 Init.get(), FullCond, ConditionVar,
5685 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686}
5687
5688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005690TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005691 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5692 S->getLabel());
5693 if (!LD)
5694 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005695
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005697 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005698 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005699}
5700
5701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005702StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005703TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005704 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005707 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregorebe10102009-08-20 07:17:43 +00005709 if (!getDerived().AlwaysRebuild() &&
5710 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005711 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005712
5713 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005714 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005715}
5716
5717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005718StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005719TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005720 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005721}
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregorebe10102009-08-20 07:17:43 +00005723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005724StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005725TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005726 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005727}
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregorebe10102009-08-20 07:17:43 +00005729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005730StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005731TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005732 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005733 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005734 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005735
Mike Stump11289f42009-09-09 15:08:12 +00005736 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005737 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005738 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005739}
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregorebe10102009-08-20 07:17:43 +00005741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005742StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005743TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005744 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005745 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005746 for (auto *D : S->decls()) {
5747 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005748 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005749 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005750
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005751 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005752 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregorebe10102009-08-20 07:17:43 +00005754 Decls.push_back(Transformed);
5755 }
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005758 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005759
Rafael Espindolaab417692013-07-09 12:05:01 +00005760 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005761}
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregorebe10102009-08-20 07:17:43 +00005763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005764StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005765TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005766
Benjamin Kramerf0623432012-08-23 22:51:59 +00005767 SmallVector<Expr*, 8> Constraints;
5768 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005769 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005770
John McCalldadc5752010-08-24 06:29:42 +00005771 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005772 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005773
5774 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005775
Anders Carlssonaaeef072010-01-24 05:50:09 +00005776 // Go through the outputs.
5777 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005778 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005779
Anders Carlssonaaeef072010-01-24 05:50:09 +00005780 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005781 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
Anders Carlssonaaeef072010-01-24 05:50:09 +00005783 // Transform the output expr.
5784 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005785 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005786 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005788
Anders Carlssonaaeef072010-01-24 05:50:09 +00005789 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
John McCallb268a282010-08-23 23:25:46 +00005791 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005793
Anders Carlssonaaeef072010-01-24 05:50:09 +00005794 // Go through the inputs.
5795 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005796 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005797
Anders Carlssonaaeef072010-01-24 05:50:09 +00005798 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005799 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005800
Anders Carlssonaaeef072010-01-24 05:50:09 +00005801 // Transform the input expr.
5802 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005803 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005804 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005805 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005806
Anders Carlssonaaeef072010-01-24 05:50:09 +00005807 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005808
John McCallb268a282010-08-23 23:25:46 +00005809 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Anders Carlssonaaeef072010-01-24 05:50:09 +00005812 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005813 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005814
5815 // Go through the clobbers.
5816 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005817 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005818
5819 // No need to transform the asm string literal.
5820 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005821 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5822 S->isVolatile(), S->getNumOutputs(),
5823 S->getNumInputs(), Names.data(),
5824 Constraints, Exprs, AsmString.get(),
5825 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005826}
5827
Chad Rosier32503022012-06-11 20:47:18 +00005828template<typename Derived>
5829StmtResult
5830TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005831 ArrayRef<Token> AsmToks =
5832 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005833
John McCallf413f5e2013-05-03 00:10:13 +00005834 bool HadError = false, HadChange = false;
5835
5836 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5837 SmallVector<Expr*, 8> TransformedExprs;
5838 TransformedExprs.reserve(SrcExprs.size());
5839 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5840 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5841 if (!Result.isUsable()) {
5842 HadError = true;
5843 } else {
5844 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005845 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005846 }
5847 }
5848
5849 if (HadError) return StmtError();
5850 if (!HadChange && !getDerived().AlwaysRebuild())
5851 return Owned(S);
5852
Chad Rosierb6f46c12012-08-15 16:53:30 +00005853 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005854 AsmToks, S->getAsmString(),
5855 S->getNumOutputs(), S->getNumInputs(),
5856 S->getAllConstraints(), S->getClobbers(),
5857 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005858}
Douglas Gregorebe10102009-08-20 07:17:43 +00005859
5860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005861StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005862TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005863 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005864 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005865 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005866 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
Douglas Gregor96c79492010-04-23 22:50:49 +00005868 // Transform the @catch statements (if present).
5869 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005870 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005871 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005872 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005873 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005874 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005875 if (Catch.get() != S->getCatchStmt(I))
5876 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005877 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005879
Douglas Gregor306de2f2010-04-22 23:59:56 +00005880 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005881 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005882 if (S->getFinallyStmt()) {
5883 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5884 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005886 }
5887
5888 // If nothing changed, just retain this statement.
5889 if (!getDerived().AlwaysRebuild() &&
5890 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005891 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005892 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005893 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005894
Douglas Gregor306de2f2010-04-22 23:59:56 +00005895 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005896 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005897 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005898}
Mike Stump11289f42009-09-09 15:08:12 +00005899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005901StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005902TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005903 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005904 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005905 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005906 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005907 if (FromVar->getTypeSourceInfo()) {
5908 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5909 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005912
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005913 QualType T;
5914 if (TSInfo)
5915 T = TSInfo->getType();
5916 else {
5917 T = getDerived().TransformType(FromVar->getType());
5918 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005919 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005921
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005922 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5923 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005924 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005926
John McCalldadc5752010-08-24 06:29:42 +00005927 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005928 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005930
5931 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005932 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005933 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005934}
Mike Stump11289f42009-09-09 15:08:12 +00005935
Douglas Gregorebe10102009-08-20 07:17:43 +00005936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005937StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005938TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005939 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005940 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005941 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005942 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Douglas Gregor306de2f2010-04-22 23:59:56 +00005944 // If nothing changed, just retain this statement.
5945 if (!getDerived().AlwaysRebuild() &&
5946 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005947 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005948
5949 // Build a new statement.
5950 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005951 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005952}
Mike Stump11289f42009-09-09 15:08:12 +00005953
Douglas Gregorebe10102009-08-20 07:17:43 +00005954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005955StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005956TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005957 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005958 if (S->getThrowExpr()) {
5959 Operand = getDerived().TransformExpr(S->getThrowExpr());
5960 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005961 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
Douglas Gregor2900c162010-04-22 21:44:01 +00005964 if (!getDerived().AlwaysRebuild() &&
5965 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005966 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005967
John McCallb268a282010-08-23 23:25:46 +00005968 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005969}
Mike Stump11289f42009-09-09 15:08:12 +00005970
Douglas Gregorebe10102009-08-20 07:17:43 +00005971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005972StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005973TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005974 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005975 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005976 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005977 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005979 Object =
5980 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5981 Object.get());
5982 if (Object.isInvalid())
5983 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
Douglas Gregor6148de72010-04-22 22:01:21 +00005985 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005986 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005987 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregor6148de72010-04-22 22:01:21 +00005990 // If nothing change, just retain the current statement.
5991 if (!getDerived().AlwaysRebuild() &&
5992 Object.get() == S->getSynchExpr() &&
5993 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005994 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005995
5996 // Build a new statement.
5997 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005998 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005999}
6000
6001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006002StmtResult
John McCall31168b02011-06-15 23:02:42 +00006003TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6004 ObjCAutoreleasePoolStmt *S) {
6005 // Transform the body.
6006 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6007 if (Body.isInvalid())
6008 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006009
John McCall31168b02011-06-15 23:02:42 +00006010 // If nothing changed, just retain this statement.
6011 if (!getDerived().AlwaysRebuild() &&
6012 Body.get() == S->getSubStmt())
6013 return SemaRef.Owned(S);
6014
6015 // Build a new statement.
6016 return getDerived().RebuildObjCAutoreleasePoolStmt(
6017 S->getAtLoc(), Body.get());
6018}
6019
6020template<typename Derived>
6021StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006022TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006023 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006024 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006025 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006026 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006027 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006028
Douglas Gregorf68a5082010-04-22 23:10:45 +00006029 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006030 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006031 if (Collection.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 body.
John McCalldadc5752010-08-24 06:29:42 +00006035 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006036 if (Body.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 // If nothing changed, just retain this statement.
6040 if (!getDerived().AlwaysRebuild() &&
6041 Element.get() == S->getElement() &&
6042 Collection.get() == S->getCollection() &&
6043 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00006044 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00006045
Douglas Gregorf68a5082010-04-22 23:10:45 +00006046 // Build a new statement.
6047 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006048 Element.get(),
6049 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006050 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006051 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
6053
David Majnemer5f7efef2013-10-15 09:50:08 +00006054template <typename Derived>
6055StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006056 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006057 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006058 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6059 TypeSourceInfo *T =
6060 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006061 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
David Majnemer5f7efef2013-10-15 09:50:08 +00006064 Var = getDerived().RebuildExceptionDecl(
6065 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6066 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006067 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006068 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006069 }
Mike Stump11289f42009-09-09 15:08:12 +00006070
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006072 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006073 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006075
David Majnemer5f7efef2013-10-15 09:50:08 +00006076 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006077 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006078 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006079
David Majnemer5f7efef2013-10-15 09:50:08 +00006080 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006081}
Mike Stump11289f42009-09-09 15:08:12 +00006082
David Majnemer5f7efef2013-10-15 09:50:08 +00006083template <typename Derived>
6084StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006086 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006087 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006089
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 // Transform the handlers.
6091 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006092 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006093 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006094 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006099 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 }
Mike Stump11289f42009-09-09 15:08:12 +00006101
David Majnemer5f7efef2013-10-15 09:50:08 +00006102 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006104 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006105
John McCallb268a282010-08-23 23:25:46 +00006106 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006107 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Richard Smith02e85f32011-04-14 22:09:26 +00006110template<typename Derived>
6111StmtResult
6112TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6113 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6114 if (Range.isInvalid())
6115 return StmtError();
6116
6117 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6118 if (BeginEnd.isInvalid())
6119 return StmtError();
6120
6121 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6122 if (Cond.isInvalid())
6123 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006124 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006125 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006126 if (Cond.isInvalid())
6127 return StmtError();
6128 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006129 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006130
6131 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6132 if (Inc.isInvalid())
6133 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006134 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006135 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006136
6137 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6138 if (LoopVar.isInvalid())
6139 return StmtError();
6140
6141 StmtResult NewStmt = S;
6142 if (getDerived().AlwaysRebuild() ||
6143 Range.get() != S->getRangeStmt() ||
6144 BeginEnd.get() != S->getBeginEndStmt() ||
6145 Cond.get() != S->getCond() ||
6146 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006147 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006148 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6149 S->getColonLoc(), Range.get(),
6150 BeginEnd.get(), Cond.get(),
6151 Inc.get(), LoopVar.get(),
6152 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006153 if (NewStmt.isInvalid())
6154 return StmtError();
6155 }
Richard Smith02e85f32011-04-14 22:09:26 +00006156
6157 StmtResult Body = getDerived().TransformStmt(S->getBody());
6158 if (Body.isInvalid())
6159 return StmtError();
6160
6161 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6162 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006163 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006164 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6165 S->getColonLoc(), Range.get(),
6166 BeginEnd.get(), Cond.get(),
6167 Inc.get(), LoopVar.get(),
6168 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006169 if (NewStmt.isInvalid())
6170 return StmtError();
6171 }
Richard Smith02e85f32011-04-14 22:09:26 +00006172
6173 if (NewStmt.get() == S)
6174 return SemaRef.Owned(S);
6175
6176 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6177}
6178
John Wiegley1c0675e2011-04-28 01:08:34 +00006179template<typename Derived>
6180StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006181TreeTransform<Derived>::TransformMSDependentExistsStmt(
6182 MSDependentExistsStmt *S) {
6183 // Transform the nested-name-specifier, if any.
6184 NestedNameSpecifierLoc QualifierLoc;
6185 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006186 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006187 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6188 if (!QualifierLoc)
6189 return StmtError();
6190 }
6191
6192 // Transform the declaration name.
6193 DeclarationNameInfo NameInfo = S->getNameInfo();
6194 if (NameInfo.getName()) {
6195 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6196 if (!NameInfo.getName())
6197 return StmtError();
6198 }
6199
6200 // Check whether anything changed.
6201 if (!getDerived().AlwaysRebuild() &&
6202 QualifierLoc == S->getQualifierLoc() &&
6203 NameInfo.getName() == S->getNameInfo().getName())
6204 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006205
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006206 // Determine whether this name exists, if we can.
6207 CXXScopeSpec SS;
6208 SS.Adopt(QualifierLoc);
6209 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006210 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006211 case Sema::IER_Exists:
6212 if (S->isIfExists())
6213 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006214
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006215 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6216
6217 case Sema::IER_DoesNotExist:
6218 if (S->isIfNotExists())
6219 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006220
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006221 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006222
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006223 case Sema::IER_Dependent:
6224 Dependent = true;
6225 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006226
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006227 case Sema::IER_Error:
6228 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006230
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006231 // We need to continue with the instantiation, so do so now.
6232 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6233 if (SubStmt.isInvalid())
6234 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006235
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006236 // If we have resolved the name, just transform to the substatement.
6237 if (!Dependent)
6238 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006240 // The name is still dependent, so build a dependent expression again.
6241 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6242 S->isIfExists(),
6243 QualifierLoc,
6244 NameInfo,
6245 SubStmt.get());
6246}
6247
6248template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006249ExprResult
6250TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6251 NestedNameSpecifierLoc QualifierLoc;
6252 if (E->getQualifierLoc()) {
6253 QualifierLoc
6254 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6255 if (!QualifierLoc)
6256 return ExprError();
6257 }
6258
6259 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6260 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6261 if (!PD)
6262 return ExprError();
6263
6264 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6265 if (Base.isInvalid())
6266 return ExprError();
6267
6268 return new (SemaRef.getASTContext())
6269 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6270 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6271 QualifierLoc, E->getMemberLoc());
6272}
6273
David Majnemerfad8f482013-10-15 09:33:02 +00006274template <typename Derived>
6275StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006276 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006277 if (TryBlock.isInvalid())
6278 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006279
6280 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006281 if (Handler.isInvalid())
6282 return StmtError();
6283
David Majnemerfad8f482013-10-15 09:33:02 +00006284 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6285 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006286 return SemaRef.Owned(S);
6287
David Majnemerfad8f482013-10-15 09:33:02 +00006288 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006289 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006290}
6291
David Majnemerfad8f482013-10-15 09:33:02 +00006292template <typename Derived>
6293StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006294 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006295 if (Block.isInvalid())
6296 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006297
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006298 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006299}
6300
David Majnemerfad8f482013-10-15 09:33:02 +00006301template <typename Derived>
6302StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006303 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006304 if (FilterExpr.isInvalid())
6305 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006306
David Majnemer7e755502013-10-15 09:30:14 +00006307 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006308 if (Block.isInvalid())
6309 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006310
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006311 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6312 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006313}
6314
David Majnemerfad8f482013-10-15 09:33:02 +00006315template <typename Derived>
6316StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6317 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006318 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6319 else
6320 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6321}
6322
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006323template<typename Derived>
6324StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006325TreeTransform<Derived>::TransformOMPExecutableDirective(
6326 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006327
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006328 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006329 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006330 ArrayRef<OMPClause *> Clauses = D->clauses();
6331 TClauses.reserve(Clauses.size());
6332 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6333 I != E; ++I) {
6334 if (*I) {
6335 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006336 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006337 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006338 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006339 TClauses.push_back(Clause);
6340 }
6341 else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006342 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006343 }
6344 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006345 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006346 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006347 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006348 StmtResult AssociatedStmt =
6349 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006350 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006351 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006352 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006353
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006354 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6355 TClauses,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006356 AssociatedStmt.get(),
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006357 D->getLocStart(),
6358 D->getLocEnd());
6359}
6360
6361template<typename Derived>
6362StmtResult
6363TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6364 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006365 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006366 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6367 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6368 return Res;
6369}
6370
6371template<typename Derived>
6372StmtResult
6373TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6374 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006375 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006376 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6377 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006378 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006379}
6380
6381template<typename Derived>
6382OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006383TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006384 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6385 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006386 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006387 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006388 C->getLParenLoc(), C->getLocEnd());
6389}
6390
6391template<typename Derived>
6392OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006393TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6394 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6395 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006396 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006397 return getDerived().RebuildOMPNumThreadsClause(NumThreads.get(),
Alexey Bataev568a8332014-03-06 06:15:19 +00006398 C->getLocStart(),
6399 C->getLParenLoc(),
6400 C->getLocEnd());
6401}
6402
Alexey Bataev62c87d22014-03-21 04:51:18 +00006403template <typename Derived>
6404OMPClause *
6405TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6406 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6407 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006408 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006409 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006410 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006411}
6412
Alexander Musman8bd31e62014-05-27 15:12:19 +00006413template <typename Derived>
6414OMPClause *
6415TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6416 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6417 if (E.isInvalid())
6418 return 0;
6419 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006420 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006421}
6422
Alexey Bataev568a8332014-03-06 06:15:19 +00006423template<typename Derived>
6424OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006425TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6426 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6427 C->getDefaultKindKwLoc(),
6428 C->getLocStart(),
6429 C->getLParenLoc(),
6430 C->getLocEnd());
6431}
6432
6433template<typename Derived>
6434OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006435TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
6436 return getDerived().RebuildOMPProcBindClause(C->getProcBindKind(),
6437 C->getProcBindKindKwLoc(),
6438 C->getLocStart(),
6439 C->getLParenLoc(),
6440 C->getLocEnd());
6441}
6442
6443template<typename Derived>
6444OMPClause *
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 }
6454 return getDerived().RebuildOMPPrivateClause(Vars,
6455 C->getLocStart(),
6456 C->getLParenLoc(),
6457 C->getLocEnd());
6458}
6459
Alexey Bataev758e55e2013-09-06 18:03:48 +00006460template<typename Derived>
6461OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006462TreeTransform<Derived>::TransformOMPFirstprivateClause(
6463 OMPFirstprivateClause *C) {
6464 llvm::SmallVector<Expr *, 16> Vars;
6465 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006466 for (auto *VE : C->varlists()) {
6467 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006468 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006469 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006470 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006471 }
6472 return getDerived().RebuildOMPFirstprivateClause(Vars,
6473 C->getLocStart(),
6474 C->getLParenLoc(),
6475 C->getLocEnd());
6476}
6477
6478template<typename Derived>
6479OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006480TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6481 llvm::SmallVector<Expr *, 16> Vars;
6482 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006483 for (auto *VE : C->varlists()) {
6484 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006485 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006486 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006487 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006488 }
6489 return getDerived().RebuildOMPSharedClause(Vars,
6490 C->getLocStart(),
6491 C->getLParenLoc(),
6492 C->getLocEnd());
6493}
6494
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006495template<typename Derived>
6496OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006497TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6498 llvm::SmallVector<Expr *, 16> Vars;
6499 Vars.reserve(C->varlist_size());
6500 for (auto *VE : C->varlists()) {
6501 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6502 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006503 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006504 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006505 }
6506 ExprResult Step = getDerived().TransformExpr(C->getStep());
6507 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006508 return nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +00006509 return getDerived().RebuildOMPLinearClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006510 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexander Musman8dba6642014-04-22 13:09:42 +00006511 C->getLocEnd());
6512}
6513
6514template<typename Derived>
6515OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006516TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6517 llvm::SmallVector<Expr *, 16> Vars;
6518 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006519 for (auto *VE : C->varlists()) {
6520 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006521 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006522 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006523 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006524 }
6525 return getDerived().RebuildOMPCopyinClause(Vars,
6526 C->getLocStart(),
6527 C->getLParenLoc(),
6528 C->getLocEnd());
6529}
6530
Douglas Gregorebe10102009-08-20 07:17:43 +00006531//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006532// Expression transformation
6533//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006536TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006537 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006538}
Mike Stump11289f42009-09-09 15:08:12 +00006539
6540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006542TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006543 NestedNameSpecifierLoc QualifierLoc;
6544 if (E->getQualifierLoc()) {
6545 QualifierLoc
6546 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6547 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006549 }
John McCallce546572009-12-08 09:08:17 +00006550
6551 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006552 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6553 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006554 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006556
John McCall815039a2010-08-17 21:27:17 +00006557 DeclarationNameInfo NameInfo = E->getNameInfo();
6558 if (NameInfo.getName()) {
6559 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6560 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006561 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006562 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006563
6564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006565 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006566 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006567 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006568 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006569
6570 // Mark it referenced in the new context regardless.
6571 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006572 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006573
John McCallc3007a22010-10-26 07:05:15 +00006574 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006575 }
John McCallce546572009-12-08 09:08:17 +00006576
Craig Topperc3ec1492014-05-26 06:22:03 +00006577 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006578 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006579 TemplateArgs = &TransArgs;
6580 TransArgs.setLAngleLoc(E->getLAngleLoc());
6581 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006582 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6583 E->getNumTemplateArgs(),
6584 TransArgs))
6585 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006586 }
6587
Chad Rosier1dcde962012-08-08 18:46:20 +00006588 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006589 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006590}
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregora16548e2009-08-11 05:31:07 +00006592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006594TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006595 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006596}
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregora16548e2009-08-11 05:31:07 +00006598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006601 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006602}
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregora16548e2009-08-11 05:31:07 +00006604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006606TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006607 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006608}
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregora16548e2009-08-11 05:31:07 +00006610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006612TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006613 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006614}
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregora16548e2009-08-11 05:31:07 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006619 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006620}
6621
6622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006624TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006625 if (FunctionDecl *FD = E->getDirectCallee())
6626 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006627 return SemaRef.MaybeBindToTemporary(E);
6628}
6629
6630template<typename Derived>
6631ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006632TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6633 ExprResult ControllingExpr =
6634 getDerived().TransformExpr(E->getControllingExpr());
6635 if (ControllingExpr.isInvalid())
6636 return ExprError();
6637
Chris Lattner01cf8db2011-07-20 06:58:45 +00006638 SmallVector<Expr *, 4> AssocExprs;
6639 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006640 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6641 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6642 if (TS) {
6643 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6644 if (!AssocType)
6645 return ExprError();
6646 AssocTypes.push_back(AssocType);
6647 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006648 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006649 }
6650
6651 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6652 if (AssocExpr.isInvalid())
6653 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006654 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006655 }
6656
6657 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6658 E->getDefaultLoc(),
6659 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006660 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006661 AssocTypes,
6662 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006663}
6664
6665template<typename Derived>
6666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006667TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006668 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregora16548e2009-08-11 05:31:07 +00006672 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006673 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006674
John McCallb268a282010-08-23 23:25:46 +00006675 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 E->getRParen());
6677}
6678
Richard Smithdb2630f2012-10-21 03:28:35 +00006679/// \brief The operand of a unary address-of operator has special rules: it's
6680/// allowed to refer to a non-static member of a class even if there's no 'this'
6681/// object available.
6682template<typename Derived>
6683ExprResult
6684TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6685 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6686 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6687 else
6688 return getDerived().TransformExpr(E);
6689}
6690
Mike Stump11289f42009-09-09 15:08:12 +00006691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006693TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006694 ExprResult SubExpr;
6695 if (E->getOpcode() == UO_AddrOf)
6696 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6697 else
6698 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006703 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6706 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006707 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006708}
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregora16548e2009-08-11 05:31:07 +00006710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006712TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6713 // Transform the type.
6714 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6715 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregor882211c2010-04-28 22:16:22 +00006718 // Transform all of the components into components similar to what the
6719 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006720 // FIXME: It would be slightly more efficient in the non-dependent case to
6721 // just map FieldDecls, rather than requiring the rebuilder to look for
6722 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006723 // template code that we don't care.
6724 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006725 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006726 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006727 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006728 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6729 const Node &ON = E->getComponent(I);
6730 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006731 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006732 Comp.LocStart = ON.getSourceRange().getBegin();
6733 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006734 switch (ON.getKind()) {
6735 case Node::Array: {
6736 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006737 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006738 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006740
Douglas Gregor882211c2010-04-28 22:16:22 +00006741 ExprChanged = ExprChanged || Index.get() != FromIndex;
6742 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006743 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006744 break;
6745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006746
Douglas Gregor882211c2010-04-28 22:16:22 +00006747 case Node::Field:
6748 case Node::Identifier:
6749 Comp.isBrackets = false;
6750 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006751 if (!Comp.U.IdentInfo)
6752 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006753
Douglas Gregor882211c2010-04-28 22:16:22 +00006754 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006755
Douglas Gregord1702062010-04-29 00:18:15 +00006756 case Node::Base:
6757 // Will be recomputed during the rebuild.
6758 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006760
Douglas Gregor882211c2010-04-28 22:16:22 +00006761 Components.push_back(Comp);
6762 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006763
Douglas Gregor882211c2010-04-28 22:16:22 +00006764 // If nothing changed, retain the existing expression.
6765 if (!getDerived().AlwaysRebuild() &&
6766 Type == E->getTypeSourceInfo() &&
6767 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006768 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Douglas Gregor882211c2010-04-28 22:16:22 +00006770 // Build a new offsetof expression.
6771 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6772 Components.data(), Components.size(),
6773 E->getRParenLoc());
6774}
6775
6776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006777ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006778TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6779 assert(getDerived().AlreadyTransformed(E->getType()) &&
6780 "opaque value expression requires transformation");
6781 return SemaRef.Owned(E);
6782}
6783
6784template<typename Derived>
6785ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006786TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006787 // Rebuild the syntactic form. The original syntactic form has
6788 // opaque-value expressions in it, so strip those away and rebuild
6789 // the result. This is a really awful way of doing this, but the
6790 // better solution (rebuilding the semantic expressions and
6791 // rebinding OVEs as necessary) doesn't work; we'd need
6792 // TreeTransform to not strip away implicit conversions.
6793 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6794 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006795 if (result.isInvalid()) return ExprError();
6796
6797 // If that gives us a pseudo-object result back, the pseudo-object
6798 // expression must have been an lvalue-to-rvalue conversion which we
6799 // should reapply.
6800 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006801 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006802
6803 return result;
6804}
6805
6806template<typename Derived>
6807ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006808TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6809 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006810 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006811 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006812
John McCallbcd03502009-12-07 02:54:59 +00006813 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006814 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006816
John McCall4c98fd82009-11-04 07:28:41 +00006817 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006818 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006819
Peter Collingbournee190dee2011-03-11 19:24:49 +00006820 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6821 E->getKind(),
6822 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006823 }
Mike Stump11289f42009-09-09 15:08:12 +00006824
Eli Friedmane4f22df2012-02-29 04:03:55 +00006825 // C++0x [expr.sizeof]p1:
6826 // The operand is either an expression, which is an unevaluated operand
6827 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006828 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6829 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006830
Eli Friedmane4f22df2012-02-29 04:03:55 +00006831 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6832 if (SubExpr.isInvalid())
6833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006834
Eli Friedmane4f22df2012-02-29 04:03:55 +00006835 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6836 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006837
Peter Collingbournee190dee2011-03-11 19:24:49 +00006838 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6839 E->getOperatorLoc(),
6840 E->getKind(),
6841 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006842}
Mike Stump11289f42009-09-09 15:08:12 +00006843
Douglas Gregora16548e2009-08-11 05:31:07 +00006844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006846TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006847 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006848 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006850
John McCalldadc5752010-08-24 06:29:42 +00006851 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006852 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
6855
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 if (!getDerived().AlwaysRebuild() &&
6857 LHS.get() == E->getLHS() &&
6858 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006859 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006860
John McCallb268a282010-08-23 23:25:46 +00006861 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006863 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006864 E->getRBracketLoc());
6865}
Mike Stump11289f42009-09-09 15:08:12 +00006866
6867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006868ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006869TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006871 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006872 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006874
6875 // Transform arguments.
6876 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006877 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006878 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006879 &ArgChanged))
6880 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882 if (!getDerived().AlwaysRebuild() &&
6883 Callee.get() == E->getCallee() &&
6884 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006885 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006888 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006889 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006890 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006891 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 E->getRParenLoc());
6893}
Mike Stump11289f42009-09-09 15:08:12 +00006894
6895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006896ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006897TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006898 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006899 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006901
Douglas Gregorea972d32011-02-28 21:54:11 +00006902 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006903 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006904 QualifierLoc
6905 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006906
Douglas Gregorea972d32011-02-28 21:54:11 +00006907 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006908 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006909 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006910 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006911
Eli Friedman2cfcef62009-12-04 06:40:45 +00006912 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006913 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6914 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006915 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006917
John McCall16df1e52010-03-30 21:47:33 +00006918 NamedDecl *FoundDecl = E->getFoundDecl();
6919 if (FoundDecl == E->getMemberDecl()) {
6920 FoundDecl = Member;
6921 } else {
6922 FoundDecl = cast_or_null<NamedDecl>(
6923 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6924 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006925 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006926 }
6927
Douglas Gregora16548e2009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() &&
6929 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006930 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006931 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006932 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006933 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006934
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006935 // Mark it referenced in the new context regardless.
6936 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006937 SemaRef.MarkMemberReferenced(E);
6938
John McCallc3007a22010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006940 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006941
John McCall6b51f282009-11-23 01:53:49 +00006942 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006943 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006944 TransArgs.setLAngleLoc(E->getLAngleLoc());
6945 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006946 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6947 E->getNumTemplateArgs(),
6948 TransArgs))
6949 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006953 SourceLocation FakeOperatorLoc =
6954 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006955
John McCall38836f02010-01-15 08:34:02 +00006956 // FIXME: to do this check properly, we will need to preserve the
6957 // first-qualifier-in-scope here, just in case we had a dependent
6958 // base (and therefore couldn't do the check) and a
6959 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00006960 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00006961
John McCallb268a282010-08-23 23:25:46 +00006962 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006963 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006964 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006965 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006966 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006967 Member,
John McCall16df1e52010-03-30 21:47:33 +00006968 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006969 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00006970 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00006971 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006972}
Mike Stump11289f42009-09-09 15:08:12 +00006973
Douglas Gregora16548e2009-08-11 05:31:07 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006977 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006980
John McCalldadc5752010-08-24 06:29:42 +00006981 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006984
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 if (!getDerived().AlwaysRebuild() &&
6986 LHS.get() == E->getLHS() &&
6987 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006988 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006989
Lang Hames5de91cc2012-10-02 04:45:10 +00006990 Sema::FPContractStateRAII FPContractState(getSema());
6991 getSema().FPFeatures.fp_contract = E->isFPContractable();
6992
Douglas Gregora16548e2009-08-11 05:31:07 +00006993 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006994 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006995}
6996
Mike Stump11289f42009-09-09 15:08:12 +00006997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006998ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006999TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007000 CompoundAssignOperator *E) {
7001 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007002}
Mike Stump11289f42009-09-09 15:08:12 +00007003
Douglas Gregora16548e2009-08-11 05:31:07 +00007004template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007005ExprResult TreeTransform<Derived>::
7006TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7007 // Just rebuild the common and RHS expressions and see whether we
7008 // get any changes.
7009
7010 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7011 if (commonExpr.isInvalid())
7012 return ExprError();
7013
7014 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7015 if (rhs.isInvalid())
7016 return ExprError();
7017
7018 if (!getDerived().AlwaysRebuild() &&
7019 commonExpr.get() == e->getCommon() &&
7020 rhs.get() == e->getFalseExpr())
7021 return SemaRef.Owned(e);
7022
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007023 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007024 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007025 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007026 e->getColonLoc(),
7027 rhs.get());
7028}
7029
7030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007031ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007032TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007033 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007034 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007036
John McCalldadc5752010-08-24 06:29:42 +00007037 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007039 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007040
John McCalldadc5752010-08-24 06:29:42 +00007041 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007042 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045 if (!getDerived().AlwaysRebuild() &&
7046 Cond.get() == E->getCond() &&
7047 LHS.get() == E->getLHS() &&
7048 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007049 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007050
John McCallb268a282010-08-23 23:25:46 +00007051 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007052 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007053 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007054 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007055 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007056}
Mike Stump11289f42009-09-09 15:08:12 +00007057
7058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007059ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007060TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007061 // Implicit casts are eliminated during transformation, since they
7062 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007063 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007064}
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregora16548e2009-08-11 05:31:07 +00007066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007069 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7070 if (!Type)
7071 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007072
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007074 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007075 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007077
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007079 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007081 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007082
John McCall97513962010-01-15 18:39:57 +00007083 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007084 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007086 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007087}
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007091TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007092 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7093 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7094 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007096
John McCalldadc5752010-08-24 06:29:42 +00007097 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007102 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007104 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007105
John McCall5d7aa7f2010-01-19 22:33:45 +00007106 // Note: the expression type doesn't necessarily match the
7107 // type-as-written, but that's okay, because it should always be
7108 // derivable from the initializer.
7109
John McCalle15bbff2010-01-18 19:35:47 +00007110 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007111 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007112 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007113}
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregora16548e2009-08-11 05:31:07 +00007115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007118 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007119 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007121
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 if (!getDerived().AlwaysRebuild() &&
7123 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007124 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007125
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007127 SourceLocation FakeOperatorLoc =
7128 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007129 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 E->getAccessorLoc(),
7131 E->getAccessor());
7132}
Mike Stump11289f42009-09-09 15:08:12 +00007133
Douglas Gregora16548e2009-08-11 05:31:07 +00007134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007137 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007138
Benjamin Kramerf0623432012-08-23 22:51:59 +00007139 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007140 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007141 Inits, &InitChanged))
7142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007143
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007146
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007147 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007148 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007149}
Mike Stump11289f42009-09-09 15:08:12 +00007150
Douglas Gregora16548e2009-08-11 05:31:07 +00007151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007152ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007153TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007154 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregorebe10102009-08-20 07:17:43 +00007156 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007157 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007158 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007160
Douglas Gregorebe10102009-08-20 07:17:43 +00007161 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007162 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 bool ExprChanged = false;
7164 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7165 DEnd = E->designators_end();
7166 D != DEnd; ++D) {
7167 if (D->isFieldDesignator()) {
7168 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7169 D->getDotLoc(),
7170 D->getFieldLoc()));
7171 continue;
7172 }
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007175 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007176 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007178
7179 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007181
Douglas Gregora16548e2009-08-11 05:31:07 +00007182 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007183 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 continue;
7185 }
Mike Stump11289f42009-09-09 15:08:12 +00007186
Douglas Gregora16548e2009-08-11 05:31:07 +00007187 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007188 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007189 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7190 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007192
John McCalldadc5752010-08-24 06:29:42 +00007193 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007196
7197 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007198 End.get(),
7199 D->getLBracketLoc(),
7200 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007201
Douglas Gregora16548e2009-08-11 05:31:07 +00007202 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7203 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007204
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007205 ArrayExprs.push_back(Start.get());
7206 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 }
Mike Stump11289f42009-09-09 15:08:12 +00007208
Douglas Gregora16548e2009-08-11 05:31:07 +00007209 if (!getDerived().AlwaysRebuild() &&
7210 Init.get() == E->getInit() &&
7211 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007212 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007213
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007214 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007216 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007217}
Mike Stump11289f42009-09-09 15:08:12 +00007218
Douglas Gregora16548e2009-08-11 05:31:07 +00007219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007221TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007222 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007223 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007224
Douglas Gregor3da3c062009-10-28 00:29:27 +00007225 // FIXME: Will we ever have proper type location here? Will we actually
7226 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 QualType T = getDerived().TransformType(E->getType());
7228 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007230
Douglas Gregora16548e2009-08-11 05:31:07 +00007231 if (!getDerived().AlwaysRebuild() &&
7232 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007233 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007234
Douglas Gregora16548e2009-08-11 05:31:07 +00007235 return getDerived().RebuildImplicitValueInitExpr(T);
7236}
Mike Stump11289f42009-09-09 15:08:12 +00007237
Douglas Gregora16548e2009-08-11 05:31:07 +00007238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007240TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007241 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7242 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007244
John McCalldadc5752010-08-24 06:29:42 +00007245 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007247 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007248
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007250 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007252 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007253
John McCallb268a282010-08-23 23:25:46 +00007254 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007255 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007256}
7257
7258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007261 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007262 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007263 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7264 &ArgumentChanged))
7265 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007266
Douglas Gregora16548e2009-08-11 05:31:07 +00007267 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007268 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007269 E->getRParenLoc());
7270}
Mike Stump11289f42009-09-09 15:08:12 +00007271
Douglas Gregora16548e2009-08-11 05:31:07 +00007272/// \brief Transform an address-of-label expression.
7273///
7274/// By default, the transformation of an address-of-label expression always
7275/// rebuilds the expression, so that the label identifier can be resolved to
7276/// the corresponding label statement by semantic analysis.
7277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007279TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007280 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7281 E->getLabel());
7282 if (!LD)
7283 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007284
Douglas Gregora16548e2009-08-11 05:31:07 +00007285 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007286 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007287}
Mike Stump11289f42009-09-09 15:08:12 +00007288
7289template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007291TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007292 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007293 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007295 if (SubStmt.isInvalid()) {
7296 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007298 }
Mike Stump11289f42009-09-09 15:08:12 +00007299
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007301 SubStmt.get() == E->getSubStmt()) {
7302 // Calling this an 'error' is unintuitive, but it does the right thing.
7303 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007304 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007305 }
Mike Stump11289f42009-09-09 15:08:12 +00007306
7307 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007308 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007309 E->getRParenLoc());
7310}
Mike Stump11289f42009-09-09 15:08:12 +00007311
Douglas Gregora16548e2009-08-11 05:31:07 +00007312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007314TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007315 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007318
John McCalldadc5752010-08-24 06:29:42 +00007319 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007320 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
John McCalldadc5752010-08-24 06:29:42 +00007323 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007324 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007326
Douglas Gregora16548e2009-08-11 05:31:07 +00007327 if (!getDerived().AlwaysRebuild() &&
7328 Cond.get() == E->getCond() &&
7329 LHS.get() == E->getLHS() &&
7330 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007331 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007332
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007334 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007335 E->getRParenLoc());
7336}
Mike Stump11289f42009-09-09 15:08:12 +00007337
Douglas Gregora16548e2009-08-11 05:31:07 +00007338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007340TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007341 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007342}
7343
7344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007346TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007347 switch (E->getOperator()) {
7348 case OO_New:
7349 case OO_Delete:
7350 case OO_Array_New:
7351 case OO_Array_Delete:
7352 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007353
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007354 case OO_Call: {
7355 // This is a call to an object's operator().
7356 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7357
7358 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007359 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007360 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007361 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007362
7363 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007364 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7365 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007366
7367 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007368 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007369 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007370 Args))
7371 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007372
John McCallb268a282010-08-23 23:25:46 +00007373 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007374 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007375 E->getLocEnd());
7376 }
7377
7378#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7379 case OO_##Name:
7380#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7381#include "clang/Basic/OperatorKinds.def"
7382 case OO_Subscript:
7383 // Handled below.
7384 break;
7385
7386 case OO_Conditional:
7387 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007388
7389 case OO_None:
7390 case NUM_OVERLOADED_OPERATORS:
7391 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007392 }
7393
John McCalldadc5752010-08-24 06:29:42 +00007394 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007395 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007397
Richard Smithdb2630f2012-10-21 03:28:35 +00007398 ExprResult First;
7399 if (E->getOperator() == OO_Amp)
7400 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7401 else
7402 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007403 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007404 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007405
John McCalldadc5752010-08-24 06:29:42 +00007406 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007407 if (E->getNumArgs() == 2) {
7408 Second = getDerived().TransformExpr(E->getArg(1));
7409 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007410 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 }
Mike Stump11289f42009-09-09 15:08:12 +00007412
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 if (!getDerived().AlwaysRebuild() &&
7414 Callee.get() == E->getCallee() &&
7415 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007416 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007417 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007418
Lang Hames5de91cc2012-10-02 04:45:10 +00007419 Sema::FPContractStateRAII FPContractState(getSema());
7420 getSema().FPFeatures.fp_contract = E->isFPContractable();
7421
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7423 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007424 Callee.get(),
7425 First.get(),
7426 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007427}
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora16548e2009-08-11 05:31:07 +00007429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007431TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7432 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007433}
Mike Stump11289f42009-09-09 15:08:12 +00007434
Douglas Gregora16548e2009-08-11 05:31:07 +00007435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007436ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007437TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7438 // Transform the callee.
7439 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7440 if (Callee.isInvalid())
7441 return ExprError();
7442
7443 // Transform exec config.
7444 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7445 if (EC.isInvalid())
7446 return ExprError();
7447
7448 // Transform arguments.
7449 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007450 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007451 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007452 &ArgChanged))
7453 return ExprError();
7454
7455 if (!getDerived().AlwaysRebuild() &&
7456 Callee.get() == E->getCallee() &&
7457 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007458 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007459
7460 // FIXME: Wrong source location information for the '('.
7461 SourceLocation FakeLParenLoc
7462 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7463 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007464 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007465 E->getRParenLoc(), EC.get());
7466}
7467
7468template<typename Derived>
7469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007470TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007471 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7472 if (!Type)
7473 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007474
John McCalldadc5752010-08-24 06:29:42 +00007475 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007476 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007477 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007479
Douglas Gregora16548e2009-08-11 05:31:07 +00007480 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007481 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007482 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007483 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007484 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007485 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007486 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007487 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007488 E->getAngleBrackets().getEnd(),
7489 // FIXME. this should be '(' location
7490 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007491 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007492 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007493}
Mike Stump11289f42009-09-09 15:08:12 +00007494
Douglas Gregora16548e2009-08-11 05:31:07 +00007495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007496ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007497TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7498 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007499}
Mike Stump11289f42009-09-09 15:08:12 +00007500
7501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007503TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7504 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007505}
7506
Douglas Gregora16548e2009-08-11 05:31:07 +00007507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007508ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007509TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007510 CXXReinterpretCastExpr *E) {
7511 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007512}
Mike Stump11289f42009-09-09 15:08:12 +00007513
Douglas Gregora16548e2009-08-11 05:31:07 +00007514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007516TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7517 return getDerived().TransformCXXNamedCastExpr(E);
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
Douglas Gregora16548e2009-08-11 05:31:07 +00007522TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007523 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007524 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7525 if (!Type)
7526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007527
John McCalldadc5752010-08-24 06:29:42 +00007528 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007529 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007532
Douglas Gregora16548e2009-08-11 05:31:07 +00007533 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007534 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007536 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007537
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007538 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007539 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007540 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 E->getRParenLoc());
7542}
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregora16548e2009-08-11 05:31:07 +00007544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007546TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007548 TypeSourceInfo *TInfo
7549 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7550 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007552
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007554 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007555 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007556
Douglas Gregor9da64192010-04-26 22:37:10 +00007557 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7558 E->getLocStart(),
7559 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 E->getLocEnd());
7561 }
Mike Stump11289f42009-09-09 15:08:12 +00007562
Eli Friedman456f0182012-01-20 01:26:23 +00007563 // We don't know whether the subexpression is potentially evaluated until
7564 // after we perform semantic analysis. We speculatively assume it is
7565 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007567 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7568 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007569
John McCalldadc5752010-08-24 06:29:42 +00007570 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007571 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007572 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007573
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 if (!getDerived().AlwaysRebuild() &&
7575 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007576 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregor9da64192010-04-26 22:37:10 +00007578 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7579 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007580 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 E->getLocEnd());
7582}
7583
7584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007585ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007586TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7587 if (E->isTypeOperand()) {
7588 TypeSourceInfo *TInfo
7589 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7590 if (!TInfo)
7591 return ExprError();
7592
7593 if (!getDerived().AlwaysRebuild() &&
7594 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007595 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007596
Douglas Gregor69735112011-03-06 17:40:41 +00007597 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007598 E->getLocStart(),
7599 TInfo,
7600 E->getLocEnd());
7601 }
7602
Francois Pichet9f4f2072010-09-08 12:20:18 +00007603 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7604
7605 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7606 if (SubExpr.isInvalid())
7607 return ExprError();
7608
7609 if (!getDerived().AlwaysRebuild() &&
7610 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007611 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007612
7613 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7614 E->getLocStart(),
7615 SubExpr.get(),
7616 E->getLocEnd());
7617}
7618
7619template<typename Derived>
7620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007621TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007622 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007623}
Mike Stump11289f42009-09-09 15:08:12 +00007624
Douglas Gregora16548e2009-08-11 05:31:07 +00007625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007626ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007627TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007628 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007629 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007630}
Mike Stump11289f42009-09-09 15:08:12 +00007631
Douglas Gregora16548e2009-08-11 05:31:07 +00007632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007633ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007634TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007635 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007636
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007637 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7638 // Make sure that we capture 'this'.
7639 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007640 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007642
Douglas Gregorb15af892010-01-07 23:12:05 +00007643 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007644}
Mike Stump11289f42009-09-09 15:08:12 +00007645
Douglas Gregora16548e2009-08-11 05:31:07 +00007646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007648TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007649 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (!getDerived().AlwaysRebuild() &&
7654 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007655 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007656
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007657 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7658 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007659}
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregora16548e2009-08-11 05:31:07 +00007661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007663TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007664 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007665 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7666 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007669
Chandler Carruth794da4c2010-02-08 06:42:49 +00007670 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007672 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregor033f6752009-12-23 23:03:06 +00007674 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007675}
Mike Stump11289f42009-09-09 15:08:12 +00007676
Douglas Gregora16548e2009-08-11 05:31:07 +00007677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007678ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007679TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7680 FieldDecl *Field
7681 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7682 E->getField()));
7683 if (!Field)
7684 return ExprError();
7685
7686 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7687 return SemaRef.Owned(E);
7688
7689 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7690}
7691
7692template<typename Derived>
7693ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007694TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7695 CXXScalarValueInitExpr *E) {
7696 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7697 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007698 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007699
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007701 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007702 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007703
Chad Rosier1dcde962012-08-08 18:46:20 +00007704 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007705 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007706 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007707}
Mike Stump11289f42009-09-09 15:08:12 +00007708
Douglas Gregora16548e2009-08-11 05:31:07 +00007709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007710ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007711TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007713 TypeSourceInfo *AllocTypeInfo
7714 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7715 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007719 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007722
Douglas Gregora16548e2009-08-11 05:31:07 +00007723 // Transform the placement arguments (if any).
7724 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007725 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007726 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007727 E->getNumPlacementArgs(), true,
7728 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007730
Sebastian Redl6047f072012-02-16 12:22:20 +00007731 // Transform the initializer (if any).
7732 Expr *OldInit = E->getInitializer();
7733 ExprResult NewInit;
7734 if (OldInit)
7735 NewInit = getDerived().TransformExpr(OldInit);
7736 if (NewInit.isInvalid())
7737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007738
Sebastian Redl6047f072012-02-16 12:22:20 +00007739 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007740 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007741 if (E->getOperatorNew()) {
7742 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007743 getDerived().TransformDecl(E->getLocStart(),
7744 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007745 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007746 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007747 }
7748
Craig Topperc3ec1492014-05-26 06:22:03 +00007749 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007750 if (E->getOperatorDelete()) {
7751 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007752 getDerived().TransformDecl(E->getLocStart(),
7753 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007754 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007755 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007757
Douglas Gregora16548e2009-08-11 05:31:07 +00007758 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007759 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007761 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007762 OperatorNew == E->getOperatorNew() &&
7763 OperatorDelete == E->getOperatorDelete() &&
7764 !ArgumentChanged) {
7765 // Mark any declarations we need as referenced.
7766 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007767 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007768 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007769 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007770 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007771
Sebastian Redl6047f072012-02-16 12:22:20 +00007772 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007773 QualType ElementType
7774 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7775 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7776 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7777 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007778 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007779 }
7780 }
7781 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007782
John McCallc3007a22010-10-26 07:05:15 +00007783 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007784 }
Mike Stump11289f42009-09-09 15:08:12 +00007785
Douglas Gregor0744ef62010-09-07 21:49:58 +00007786 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007787 if (!ArraySize.get()) {
7788 // If no array size was specified, but the new expression was
7789 // instantiated with an array type (e.g., "new T" where T is
7790 // instantiated with "int[4]"), extract the outer bound from the
7791 // array type as our array size. We do this with constant and
7792 // dependently-sized array types.
7793 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7794 if (!ArrayT) {
7795 // Do nothing
7796 } else if (const ConstantArrayType *ConsArrayT
7797 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007798 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007799 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007800 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007801 SemaRef.Context.getSizeType(),
7802 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007803 AllocType = ConsArrayT->getElementType();
7804 } else if (const DependentSizedArrayType *DepArrayT
7805 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7806 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007807 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007808 AllocType = DepArrayT->getElementType();
7809 }
7810 }
7811 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007812
Douglas Gregora16548e2009-08-11 05:31:07 +00007813 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7814 E->isGlobalNew(),
7815 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007816 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007817 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007818 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007819 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007820 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007821 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007822 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007823 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007824}
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007828TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007829 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007832
Douglas Gregord2d9da02010-02-26 00:38:10 +00007833 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007834 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007835 if (E->getOperatorDelete()) {
7836 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007837 getDerived().TransformDecl(E->getLocStart(),
7838 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007839 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007840 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007842
Douglas Gregora16548e2009-08-11 05:31:07 +00007843 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007844 Operand.get() == E->getArgument() &&
7845 OperatorDelete == E->getOperatorDelete()) {
7846 // Mark any declarations we need as referenced.
7847 // FIXME: instantiation-specific.
7848 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007849 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007850
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007851 if (!E->getArgument()->isTypeDependent()) {
7852 QualType Destroyed = SemaRef.Context.getBaseElementType(
7853 E->getDestroyedType());
7854 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7855 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007856 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007857 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007858 }
7859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007860
John McCallc3007a22010-10-26 07:05:15 +00007861 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007862 }
Mike Stump11289f42009-09-09 15:08:12 +00007863
Douglas Gregora16548e2009-08-11 05:31:07 +00007864 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7865 E->isGlobalDelete(),
7866 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007867 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007868}
Mike Stump11289f42009-09-09 15:08:12 +00007869
Douglas Gregora16548e2009-08-11 05:31:07 +00007870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007872TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007873 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007874 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007875 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007877
John McCallba7bf592010-08-24 05:47:05 +00007878 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007879 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007880 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007881 E->getOperatorLoc(),
7882 E->isArrow()? tok::arrow : tok::period,
7883 ObjectTypePtr,
7884 MayBePseudoDestructor);
7885 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007887
John McCallba7bf592010-08-24 05:47:05 +00007888 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007889 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7890 if (QualifierLoc) {
7891 QualifierLoc
7892 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7893 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007894 return ExprError();
7895 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007896 CXXScopeSpec SS;
7897 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007898
Douglas Gregor678f90d2010-02-25 01:56:36 +00007899 PseudoDestructorTypeStorage Destroyed;
7900 if (E->getDestroyedTypeInfo()) {
7901 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007902 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007903 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007904 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007905 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007906 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007907 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007908 // We aren't likely to be able to resolve the identifier down to a type
7909 // now anyway, so just retain the identifier.
7910 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7911 E->getDestroyedTypeLoc());
7912 } else {
7913 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007914 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007915 *E->getDestroyedTypeIdentifier(),
7916 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007917 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007918 SS, ObjectTypePtr,
7919 false);
7920 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007921 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007922
Douglas Gregor678f90d2010-02-25 01:56:36 +00007923 Destroyed
7924 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7925 E->getDestroyedTypeLoc());
7926 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007927
Craig Topperc3ec1492014-05-26 06:22:03 +00007928 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007929 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007930 CXXScopeSpec EmptySS;
7931 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007932 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007933 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007934 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007936
John McCallb268a282010-08-23 23:25:46 +00007937 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007938 E->getOperatorLoc(),
7939 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007940 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007941 ScopeTypeInfo,
7942 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007943 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007944 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007945}
Mike Stump11289f42009-09-09 15:08:12 +00007946
Douglas Gregorad8a3362009-09-04 17:36:40 +00007947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007948ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007949TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007950 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007951 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7952 Sema::LookupOrdinaryName);
7953
7954 // Transform all the decls.
7955 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7956 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007957 NamedDecl *InstD = static_cast<NamedDecl*>(
7958 getDerived().TransformDecl(Old->getNameLoc(),
7959 *I));
John McCall84d87672009-12-10 09:41:52 +00007960 if (!InstD) {
7961 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7962 // This can happen because of dependent hiding.
7963 if (isa<UsingShadowDecl>(*I))
7964 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007965 else {
7966 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007967 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007968 }
John McCall84d87672009-12-10 09:41:52 +00007969 }
John McCalle66edc12009-11-24 19:00:30 +00007970
7971 // Expand using declarations.
7972 if (isa<UsingDecl>(InstD)) {
7973 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007974 for (auto *I : UD->shadows())
7975 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007976 continue;
7977 }
7978
7979 R.addDecl(InstD);
7980 }
7981
7982 // Resolve a kind, but don't do any further analysis. If it's
7983 // ambiguous, the callee needs to deal with it.
7984 R.resolveKind();
7985
7986 // Rebuild the nested-name qualifier, if present.
7987 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007988 if (Old->getQualifierLoc()) {
7989 NestedNameSpecifierLoc QualifierLoc
7990 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7991 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007992 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007993
Douglas Gregor0da1d432011-02-28 20:01:57 +00007994 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007995 }
7996
Douglas Gregor9262f472010-04-27 18:19:34 +00007997 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007998 CXXRecordDecl *NamingClass
7999 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8000 Old->getNameLoc(),
8001 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008002 if (!NamingClass) {
8003 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008004 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008005 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008006
Douglas Gregorda7be082010-04-27 16:10:10 +00008007 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008008 }
8009
Abramo Bagnara7945c982012-01-27 09:46:47 +00008010 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8011
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008012 // If we have neither explicit template arguments, nor the template keyword,
8013 // it's a normal declaration name.
8014 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008015 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8016
8017 // If we have template arguments, rebuild them, then rebuild the
8018 // templateid expression.
8019 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008020 if (Old->hasExplicitTemplateArgs() &&
8021 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008022 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008023 TransArgs)) {
8024 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008025 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008026 }
John McCalle66edc12009-11-24 19:00:30 +00008027
Abramo Bagnara7945c982012-01-27 09:46:47 +00008028 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008029 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008030}
Mike Stump11289f42009-09-09 15:08:12 +00008031
Douglas Gregora16548e2009-08-11 05:31:07 +00008032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008033ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008034TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8035 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008036 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008037 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8038 TypeSourceInfo *From = E->getArg(I);
8039 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008040 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008041 TypeLocBuilder TLB;
8042 TLB.reserve(FromTL.getFullDataSize());
8043 QualType To = getDerived().TransformType(TLB, FromTL);
8044 if (To.isNull())
8045 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008046
Douglas Gregor29c42f22012-02-24 07:38:34 +00008047 if (To == From->getType())
8048 Args.push_back(From);
8049 else {
8050 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8051 ArgChanged = true;
8052 }
8053 continue;
8054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008055
Douglas Gregor29c42f22012-02-24 07:38:34 +00008056 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008057
Douglas Gregor29c42f22012-02-24 07:38:34 +00008058 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008059 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008060 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8061 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8062 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008063
Douglas Gregor29c42f22012-02-24 07:38:34 +00008064 // Determine whether the set of unexpanded parameter packs can and should
8065 // be expanded.
8066 bool Expand = true;
8067 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008068 Optional<unsigned> OrigNumExpansions =
8069 ExpansionTL.getTypePtr()->getNumExpansions();
8070 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008071 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8072 PatternTL.getSourceRange(),
8073 Unexpanded,
8074 Expand, RetainExpansion,
8075 NumExpansions))
8076 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008077
Douglas Gregor29c42f22012-02-24 07:38:34 +00008078 if (!Expand) {
8079 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008080 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008081 // expansion.
8082 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008083
Douglas Gregor29c42f22012-02-24 07:38:34 +00008084 TypeLocBuilder TLB;
8085 TLB.reserve(From->getTypeLoc().getFullDataSize());
8086
8087 QualType To = getDerived().TransformType(TLB, PatternTL);
8088 if (To.isNull())
8089 return ExprError();
8090
Chad Rosier1dcde962012-08-08 18:46:20 +00008091 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008092 PatternTL.getSourceRange(),
8093 ExpansionTL.getEllipsisLoc(),
8094 NumExpansions);
8095 if (To.isNull())
8096 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008097
Douglas Gregor29c42f22012-02-24 07:38:34 +00008098 PackExpansionTypeLoc ToExpansionTL
8099 = TLB.push<PackExpansionTypeLoc>(To);
8100 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8101 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8102 continue;
8103 }
8104
8105 // Expand the pack expansion by substituting for each argument in the
8106 // pack(s).
8107 for (unsigned I = 0; I != *NumExpansions; ++I) {
8108 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8109 TypeLocBuilder TLB;
8110 TLB.reserve(PatternTL.getFullDataSize());
8111 QualType To = getDerived().TransformType(TLB, PatternTL);
8112 if (To.isNull())
8113 return ExprError();
8114
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008115 if (To->containsUnexpandedParameterPack()) {
8116 To = getDerived().RebuildPackExpansionType(To,
8117 PatternTL.getSourceRange(),
8118 ExpansionTL.getEllipsisLoc(),
8119 NumExpansions);
8120 if (To.isNull())
8121 return ExprError();
8122
8123 PackExpansionTypeLoc ToExpansionTL
8124 = TLB.push<PackExpansionTypeLoc>(To);
8125 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8126 }
8127
Douglas Gregor29c42f22012-02-24 07:38:34 +00008128 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8129 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008130
Douglas Gregor29c42f22012-02-24 07:38:34 +00008131 if (!RetainExpansion)
8132 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008133
Douglas Gregor29c42f22012-02-24 07:38:34 +00008134 // If we're supposed to retain a pack expansion, do so by temporarily
8135 // forgetting the partially-substituted parameter pack.
8136 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8137
8138 TypeLocBuilder TLB;
8139 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008140
Douglas Gregor29c42f22012-02-24 07:38:34 +00008141 QualType To = getDerived().TransformType(TLB, PatternTL);
8142 if (To.isNull())
8143 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008144
8145 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008146 PatternTL.getSourceRange(),
8147 ExpansionTL.getEllipsisLoc(),
8148 NumExpansions);
8149 if (To.isNull())
8150 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008151
Douglas Gregor29c42f22012-02-24 07:38:34 +00008152 PackExpansionTypeLoc ToExpansionTL
8153 = TLB.push<PackExpansionTypeLoc>(To);
8154 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8155 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008157
Douglas Gregor29c42f22012-02-24 07:38:34 +00008158 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8159 return SemaRef.Owned(E);
8160
8161 return getDerived().RebuildTypeTrait(E->getTrait(),
8162 E->getLocStart(),
8163 Args,
8164 E->getLocEnd());
8165}
8166
8167template<typename Derived>
8168ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008169TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8170 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8171 if (!T)
8172 return ExprError();
8173
8174 if (!getDerived().AlwaysRebuild() &&
8175 T == E->getQueriedTypeSourceInfo())
8176 return SemaRef.Owned(E);
8177
8178 ExprResult SubExpr;
8179 {
8180 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8181 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8182 if (SubExpr.isInvalid())
8183 return ExprError();
8184
8185 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8186 return SemaRef.Owned(E);
8187 }
8188
8189 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8190 E->getLocStart(),
8191 T,
8192 SubExpr.get(),
8193 E->getLocEnd());
8194}
8195
8196template<typename Derived>
8197ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008198TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8199 ExprResult SubExpr;
8200 {
8201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8202 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8203 if (SubExpr.isInvalid())
8204 return ExprError();
8205
8206 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8207 return SemaRef.Owned(E);
8208 }
8209
8210 return getDerived().RebuildExpressionTrait(
8211 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8212}
8213
8214template<typename Derived>
8215ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008216TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008217 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008218 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8219}
8220
8221template<typename Derived>
8222ExprResult
8223TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8224 DependentScopeDeclRefExpr *E,
8225 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008226 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008227 NestedNameSpecifierLoc QualifierLoc
8228 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8229 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008230 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008231 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008232
John McCall31f82722010-11-12 08:19:04 +00008233 // TODO: If this is a conversion-function-id, verify that the
8234 // destination type name (if present) resolves the same way after
8235 // instantiation as it did in the local scope.
8236
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008237 DeclarationNameInfo NameInfo
8238 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8239 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008241
John McCalle66edc12009-11-24 19:00:30 +00008242 if (!E->hasExplicitTemplateArgs()) {
8243 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008244 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008245 // Note: it is sufficient to compare the Name component of NameInfo:
8246 // if name has not changed, DNLoc has not changed either.
8247 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008248 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008249
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008250 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00008251 TemplateKWLoc,
8252 NameInfo,
8253 /*TemplateArgs*/nullptr,
8254 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008255 }
John McCall6b51f282009-11-23 01:53:49 +00008256
8257 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008258 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8259 E->getNumTemplateArgs(),
8260 TransArgs))
8261 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008262
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008263 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008264 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008265 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008266 &TransArgs,
8267 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008268}
8269
8270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008272TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008273 // CXXConstructExprs other than for list-initialization and
8274 // CXXTemporaryObjectExpr are always implicit, so when we have
8275 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008276 if ((E->getNumArgs() == 1 ||
8277 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008278 (!getDerived().DropCallArgument(E->getArg(0))) &&
8279 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008280 return getDerived().TransformExpr(E->getArg(0));
8281
Douglas Gregora16548e2009-08-11 05:31:07 +00008282 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8283
8284 QualType T = getDerived().TransformType(E->getType());
8285 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008286 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008287
8288 CXXConstructorDecl *Constructor
8289 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008290 getDerived().TransformDecl(E->getLocStart(),
8291 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008292 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008294
Douglas Gregora16548e2009-08-11 05:31:07 +00008295 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008296 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008297 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008298 &ArgumentChanged))
8299 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008300
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 if (!getDerived().AlwaysRebuild() &&
8302 T == E->getType() &&
8303 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008304 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008305 // Mark the constructor as referenced.
8306 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008307 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008308 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008309 }
Mike Stump11289f42009-09-09 15:08:12 +00008310
Douglas Gregordb121ba2009-12-14 16:27:04 +00008311 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8312 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008313 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008314 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008315 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008316 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008317 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008318 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008319}
Mike Stump11289f42009-09-09 15:08:12 +00008320
Douglas Gregora16548e2009-08-11 05:31:07 +00008321/// \brief Transform a C++ temporary-binding expression.
8322///
Douglas Gregor363b1512009-12-24 18:51:59 +00008323/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8324/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008327TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008328 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008329}
Mike Stump11289f42009-09-09 15:08:12 +00008330
John McCall5d413782010-12-06 08:20:24 +00008331/// \brief Transform a C++ expression that contains cleanups that should
8332/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008333///
John McCall5d413782010-12-06 08:20:24 +00008334/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008335/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008337ExprResult
John McCall5d413782010-12-06 08:20:24 +00008338TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008339 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008340}
Mike Stump11289f42009-09-09 15:08:12 +00008341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008343ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008344TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008345 CXXTemporaryObjectExpr *E) {
8346 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8347 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 CXXConstructorDecl *Constructor
8351 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008352 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008353 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008358 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008359 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008360 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008361 &ArgumentChanged))
8362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008363
Douglas Gregora16548e2009-08-11 05:31:07 +00008364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008365 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008366 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008367 !ArgumentChanged) {
8368 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008369 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008370 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008372
Richard Smithd59b8322012-12-19 01:39:02 +00008373 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008374 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8375 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008376 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008377 E->getLocEnd());
8378}
Mike Stump11289f42009-09-09 15:08:12 +00008379
Douglas Gregora16548e2009-08-11 05:31:07 +00008380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008381ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008382TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008383
8384 // Transform any init-capture expressions before entering the scope of the
8385 // lambda body, because they are not semantically within that scope.
8386 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8387 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8388 E->explicit_capture_begin());
8389
8390 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8391 CEnd = E->capture_end();
8392 C != CEnd; ++C) {
8393 if (!C->isInitCapture())
8394 continue;
8395 EnterExpressionEvaluationContext EEEC(getSema(),
8396 Sema::PotentiallyEvaluated);
8397 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8398 C->getCapturedVar()->getInit(),
8399 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8400
8401 if (NewExprInitResult.isInvalid())
8402 return ExprError();
8403 Expr *NewExprInit = NewExprInitResult.get();
8404
8405 VarDecl *OldVD = C->getCapturedVar();
8406 QualType NewInitCaptureType =
8407 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8408 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8409 NewExprInit);
8410 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008411 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8412 std::make_pair(NewExprInitResult, NewInitCaptureType);
8413
8414 }
8415
Faisal Vali524ca282013-11-12 01:40:44 +00008416 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008417 // Transform the template parameters, and add them to the current
8418 // instantiation scope. The null case is handled correctly.
8419 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8420 E->getTemplateParameterList());
8421
8422 // Check to see if the TypeSourceInfo of the call operator needs to
8423 // be transformed, and if so do the transformation in the
8424 // CurrentInstantiationScope.
8425
8426 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8427 FunctionProtoTypeLoc OldCallOpFPTL =
8428 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008429 TypeSourceInfo *NewCallOpTSI = nullptr;
8430
Faisal Vali2cba1332013-10-23 06:44:28 +00008431 const bool CallOpWasAlreadyTransformed =
8432 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8433
8434 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8435 if (CallOpWasAlreadyTransformed)
8436 NewCallOpTSI = OldCallOpTSI;
8437 else {
8438 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8439 // The transformation MUST be done in the CurrentInstantiationScope since
8440 // it introduces a mapping of the original to the newly created
8441 // transformed parameters.
8442
8443 TypeLocBuilder NewCallOpTLBuilder;
8444 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8445 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008446 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008447 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8448 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008449 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008450 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8451 // the vector below - this will be used to synthesize the
8452 // NewCallOperator. Additionally, add the parameters of the untransformed
8453 // lambda call operator to the CurrentInstantiationScope.
8454 SmallVector<ParmVarDecl *, 4> Params;
8455 {
8456 FunctionProtoTypeLoc NewCallOpFPTL =
8457 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8458 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008459 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008460
8461 for (unsigned I = 0; I < NewNumArgs; ++I) {
8462 // If this call operator's type does not require transformation,
8463 // the parameters do not get added to the current instantiation scope,
8464 // - so ADD them! This allows the following to compile when the enclosing
8465 // template is specialized and the entire lambda expression has to be
8466 // transformed.
8467 // template<class T> void foo(T t) {
8468 // auto L = [](auto a) {
8469 // auto M = [](char b) { <-- note: non-generic lambda
8470 // auto N = [](auto c) {
8471 // int x = sizeof(a);
8472 // x = sizeof(b); <-- specifically this line
8473 // x = sizeof(c);
8474 // };
8475 // };
8476 // };
8477 // }
8478 // foo('a')
8479 if (CallOpWasAlreadyTransformed)
8480 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8481 NewParamDeclArray[I]);
8482 // Add to Params array, so these parameters can be used to create
8483 // the newly transformed call operator.
8484 Params.push_back(NewParamDeclArray[I]);
8485 }
8486 }
8487
8488 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008489 return ExprError();
8490
Eli Friedmand564afb2012-09-19 01:18:11 +00008491 // Create the local class that will describe the lambda.
8492 CXXRecordDecl *Class
8493 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008494 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008495 /*KnownDependent=*/false,
8496 E->getCaptureDefault());
8497
Eli Friedmand564afb2012-09-19 01:18:11 +00008498 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8499
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008500 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008501 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008502 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008503 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008504 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008505 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008506 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008507
Faisal Vali2cba1332013-10-23 06:44:28 +00008508 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8509
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008510 return getDerived().TransformLambdaScope(E, NewCallOperator,
8511 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008512}
8513
8514template<typename Derived>
8515ExprResult
8516TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008517 CXXMethodDecl *CallOperator,
8518 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008519 bool Invalid = false;
8520
Douglas Gregorb4328232012-02-14 00:00:48 +00008521 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008522 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8523 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008524
Faisal Vali2b391ab2013-09-26 19:54:12 +00008525 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008526 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008527 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008528 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008529 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008530 E->hasExplicitParameters(),
8531 E->hasExplicitResultType(),
8532 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008533
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008534 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008535 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008536 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008537 CEnd = E->capture_end();
8538 C != CEnd; ++C) {
8539 // When we hit the first implicit capture, tell Sema that we've finished
8540 // the list of explicit captures.
8541 if (!FinishedExplicitCaptures && C->isImplicit()) {
8542 getSema().finishLambdaExplicitCaptures(LSI);
8543 FinishedExplicitCaptures = true;
8544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008545
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008546 // Capturing 'this' is trivial.
8547 if (C->capturesThis()) {
8548 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8549 continue;
8550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008551
Richard Smithba71c082013-05-16 06:20:58 +00008552 // Rebuild init-captures, including the implied field declaration.
8553 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008554
8555 InitCaptureInfoTy InitExprTypePair =
8556 InitCaptureExprsAndTypes[C - E->capture_begin()];
8557 ExprResult Init = InitExprTypePair.first;
8558 QualType InitQualType = InitExprTypePair.second;
8559 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008560 Invalid = true;
8561 continue;
8562 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008563 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008564 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8565 OldVD->getLocation(), InitExprTypePair.second,
8566 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008567 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008568 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008569 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008570 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008571 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008572 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008573 continue;
8574 }
8575
8576 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8577
Douglas Gregor3e308b12012-02-14 19:27:52 +00008578 // Determine the capture kind for Sema.
8579 Sema::TryCaptureKind Kind
8580 = C->isImplicit()? Sema::TryCapture_Implicit
8581 : C->getCaptureKind() == LCK_ByCopy
8582 ? Sema::TryCapture_ExplicitByVal
8583 : Sema::TryCapture_ExplicitByRef;
8584 SourceLocation EllipsisLoc;
8585 if (C->isPackExpansion()) {
8586 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8587 bool ShouldExpand = false;
8588 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008589 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008590 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8591 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008592 Unexpanded,
8593 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008594 NumExpansions)) {
8595 Invalid = true;
8596 continue;
8597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008598
Douglas Gregor3e308b12012-02-14 19:27:52 +00008599 if (ShouldExpand) {
8600 // The transform has determined that we should perform an expansion;
8601 // transform and capture each of the arguments.
8602 // expansion of the pattern. Do so.
8603 VarDecl *Pack = C->getCapturedVar();
8604 for (unsigned I = 0; I != *NumExpansions; ++I) {
8605 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8606 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008607 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008608 Pack));
8609 if (!CapturedVar) {
8610 Invalid = true;
8611 continue;
8612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008613
Douglas Gregor3e308b12012-02-14 19:27:52 +00008614 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008615 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8616 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008617 continue;
8618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008619
Douglas Gregor3e308b12012-02-14 19:27:52 +00008620 EllipsisLoc = C->getEllipsisLoc();
8621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008622
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008623 // Transform the captured variable.
8624 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008625 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008626 C->getCapturedVar()));
8627 if (!CapturedVar) {
8628 Invalid = true;
8629 continue;
8630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008631
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008632 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008633 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008634 }
8635 if (!FinishedExplicitCaptures)
8636 getSema().finishLambdaExplicitCaptures(LSI);
8637
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008638
8639 // Enter a new evaluation context to insulate the lambda from any
8640 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008641 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008642
8643 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008644 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008645 /*IsInstantiation=*/true);
8646 return ExprError();
8647 }
8648
8649 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008650 StmtResult Body = getDerived().TransformStmt(E->getBody());
8651 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008652 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008653 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008654 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008655 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008656
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008657 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008658 /*CurScope=*/nullptr,
8659 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008660}
8661
8662template<typename Derived>
8663ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008664TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008665 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008666 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8667 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008669
Douglas Gregora16548e2009-08-11 05:31:07 +00008670 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008671 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008672 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008673 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008674 &ArgumentChanged))
8675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008676
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008678 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008680 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008681
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008683 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008684 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008685 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 E->getRParenLoc());
8687}
Mike Stump11289f42009-09-09 15:08:12 +00008688
Douglas Gregora16548e2009-08-11 05:31:07 +00008689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008690ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008691TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008692 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008693 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008694 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008695 Expr *OldBase;
8696 QualType BaseType;
8697 QualType ObjectType;
8698 if (!E->isImplicitAccess()) {
8699 OldBase = E->getBase();
8700 Base = getDerived().TransformExpr(OldBase);
8701 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008703
John McCall2d74de92009-12-01 22:10:20 +00008704 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008705 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008706 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008707 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008708 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008709 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008710 ObjectTy,
8711 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008712 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008713 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008714
John McCallba7bf592010-08-24 05:47:05 +00008715 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008716 BaseType = ((Expr*) Base.get())->getType();
8717 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008718 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008719 BaseType = getDerived().TransformType(E->getBaseType());
8720 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8721 }
Mike Stump11289f42009-09-09 15:08:12 +00008722
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008723 // Transform the first part of the nested-name-specifier that qualifies
8724 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008725 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008726 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008727 E->getFirstQualifierFoundInScope(),
8728 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008729
Douglas Gregore16af532011-02-28 18:50:33 +00008730 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008731 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008732 QualifierLoc
8733 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8734 ObjectType,
8735 FirstQualifierInScope);
8736 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008737 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008738 }
Mike Stump11289f42009-09-09 15:08:12 +00008739
Abramo Bagnara7945c982012-01-27 09:46:47 +00008740 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8741
John McCall31f82722010-11-12 08:19:04 +00008742 // TODO: If this is a conversion-function-id, verify that the
8743 // destination type name (if present) resolves the same way after
8744 // instantiation as it did in the local scope.
8745
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008746 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008747 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008748 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008750
John McCall2d74de92009-12-01 22:10:20 +00008751 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008752 // This is a reference to a member without an explicitly-specified
8753 // template argument list. Optimize for this common case.
8754 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008755 Base.get() == OldBase &&
8756 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008757 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008758 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008759 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008760 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008761
John McCallb268a282010-08-23 23:25:46 +00008762 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008763 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008764 E->isArrow(),
8765 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008766 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008767 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008768 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008769 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008770 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008771 }
8772
John McCall6b51f282009-11-23 01:53:49 +00008773 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008774 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8775 E->getNumTemplateArgs(),
8776 TransArgs))
8777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008778
John McCallb268a282010-08-23 23:25:46 +00008779 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008780 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008781 E->isArrow(),
8782 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008783 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008784 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008785 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008786 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008787 &TransArgs);
8788}
8789
8790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008792TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008793 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008794 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008795 QualType BaseType;
8796 if (!Old->isImplicitAccess()) {
8797 Base = getDerived().TransformExpr(Old->getBase());
8798 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008799 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008800 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008801 Old->isArrow());
8802 if (Base.isInvalid())
8803 return ExprError();
8804 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008805 } else {
8806 BaseType = getDerived().TransformType(Old->getBaseType());
8807 }
John McCall10eae182009-11-30 22:42:35 +00008808
Douglas Gregor0da1d432011-02-28 20:01:57 +00008809 NestedNameSpecifierLoc QualifierLoc;
8810 if (Old->getQualifierLoc()) {
8811 QualifierLoc
8812 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8813 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008814 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008815 }
8816
Abramo Bagnara7945c982012-01-27 09:46:47 +00008817 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8818
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008819 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008820 Sema::LookupOrdinaryName);
8821
8822 // Transform all the decls.
8823 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8824 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008825 NamedDecl *InstD = static_cast<NamedDecl*>(
8826 getDerived().TransformDecl(Old->getMemberLoc(),
8827 *I));
John McCall84d87672009-12-10 09:41:52 +00008828 if (!InstD) {
8829 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8830 // This can happen because of dependent hiding.
8831 if (isa<UsingShadowDecl>(*I))
8832 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008833 else {
8834 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008835 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008836 }
John McCall84d87672009-12-10 09:41:52 +00008837 }
John McCall10eae182009-11-30 22:42:35 +00008838
8839 // Expand using declarations.
8840 if (isa<UsingDecl>(InstD)) {
8841 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008842 for (auto *I : UD->shadows())
8843 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008844 continue;
8845 }
8846
8847 R.addDecl(InstD);
8848 }
8849
8850 R.resolveKind();
8851
Douglas Gregor9262f472010-04-27 18:19:34 +00008852 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008853 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008854 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008855 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008856 Old->getMemberLoc(),
8857 Old->getNamingClass()));
8858 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008859 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008860
Douglas Gregorda7be082010-04-27 16:10:10 +00008861 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008863
John McCall10eae182009-11-30 22:42:35 +00008864 TemplateArgumentListInfo TransArgs;
8865 if (Old->hasExplicitTemplateArgs()) {
8866 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8867 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008868 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8869 Old->getNumTemplateArgs(),
8870 TransArgs))
8871 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008872 }
John McCall38836f02010-01-15 08:34:02 +00008873
8874 // FIXME: to do this check properly, we will need to preserve the
8875 // first-qualifier-in-scope here, just in case we had a dependent
8876 // base (and therefore couldn't do the check) and a
8877 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008878 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
John McCallb268a282010-08-23 23:25:46 +00008880 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008881 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008882 Old->getOperatorLoc(),
8883 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008884 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008885 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008886 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008887 R,
8888 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008889 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008890}
8891
8892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008893ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008894TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008895 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008896 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8897 if (SubExpr.isInvalid())
8898 return ExprError();
8899
8900 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008901 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008902
8903 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8904}
8905
8906template<typename Derived>
8907ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008908TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008909 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8910 if (Pattern.isInvalid())
8911 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008912
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008913 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8914 return SemaRef.Owned(E);
8915
Douglas Gregorb8840002011-01-14 21:20:45 +00008916 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8917 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008918}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008919
8920template<typename Derived>
8921ExprResult
8922TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8923 // If E is not value-dependent, then nothing will change when we transform it.
8924 // Note: This is an instantiation-centric view.
8925 if (!E->isValueDependent())
8926 return SemaRef.Owned(E);
8927
8928 // Note: None of the implementations of TryExpandParameterPacks can ever
8929 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008930 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008931 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8932 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008933 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008934 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008935 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008936 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008937 ShouldExpand, RetainExpansion,
8938 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008939 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008940
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008941 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008942 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008943
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008944 NamedDecl *Pack = E->getPack();
8945 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008946 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008947 Pack));
8948 if (!Pack)
8949 return ExprError();
8950 }
8951
Chad Rosier1dcde962012-08-08 18:46:20 +00008952
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008953 // We now know the length of the parameter pack, so build a new expression
8954 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008955 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8956 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008957 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008958}
8959
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008960template<typename Derived>
8961ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008962TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8963 SubstNonTypeTemplateParmPackExpr *E) {
8964 // Default behavior is to do nothing with this transformation.
8965 return SemaRef.Owned(E);
8966}
8967
8968template<typename Derived>
8969ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008970TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8971 SubstNonTypeTemplateParmExpr *E) {
8972 // Default behavior is to do nothing with this transformation.
8973 return SemaRef.Owned(E);
8974}
8975
8976template<typename Derived>
8977ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008978TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8979 // Default behavior is to do nothing with this transformation.
8980 return SemaRef.Owned(E);
8981}
8982
8983template<typename Derived>
8984ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008985TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8986 MaterializeTemporaryExpr *E) {
8987 return getDerived().TransformExpr(E->GetTemporaryExpr());
8988}
Chad Rosier1dcde962012-08-08 18:46:20 +00008989
Douglas Gregorfe314812011-06-21 17:03:29 +00008990template<typename Derived>
8991ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008992TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8993 CXXStdInitializerListExpr *E) {
8994 return getDerived().TransformExpr(E->getSubExpr());
8995}
8996
8997template<typename Derived>
8998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008999TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009000 return SemaRef.MaybeBindToTemporary(E);
9001}
9002
9003template<typename Derived>
9004ExprResult
9005TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00009006 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00009007}
9008
9009template<typename Derived>
9010ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009011TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9012 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9013 if (SubExpr.isInvalid())
9014 return ExprError();
9015
9016 if (!getDerived().AlwaysRebuild() &&
9017 SubExpr.get() == E->getSubExpr())
9018 return SemaRef.Owned(E);
9019
9020 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009021}
9022
9023template<typename Derived>
9024ExprResult
9025TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9026 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009027 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009028 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009029 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009030 /*IsCall=*/false, Elements, &ArgChanged))
9031 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009032
Ted Kremeneke65b0862012-03-06 20:05:56 +00009033 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9034 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009035
Ted Kremeneke65b0862012-03-06 20:05:56 +00009036 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9037 Elements.data(),
9038 Elements.size());
9039}
9040
9041template<typename Derived>
9042ExprResult
9043TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009044 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009045 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009046 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009047 bool ArgChanged = false;
9048 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9049 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009050
Ted Kremeneke65b0862012-03-06 20:05:56 +00009051 if (OrigElement.isPackExpansion()) {
9052 // This key/value element is a pack expansion.
9053 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9054 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9055 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9056 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9057
9058 // Determine whether the set of unexpanded parameter packs can
9059 // and should be expanded.
9060 bool Expand = true;
9061 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009062 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9063 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009064 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9065 OrigElement.Value->getLocEnd());
9066 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9067 PatternRange,
9068 Unexpanded,
9069 Expand, RetainExpansion,
9070 NumExpansions))
9071 return ExprError();
9072
9073 if (!Expand) {
9074 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009075 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009076 // expansion.
9077 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9078 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9079 if (Key.isInvalid())
9080 return ExprError();
9081
9082 if (Key.get() != OrigElement.Key)
9083 ArgChanged = true;
9084
9085 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9086 if (Value.isInvalid())
9087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009088
Ted Kremeneke65b0862012-03-06 20:05:56 +00009089 if (Value.get() != OrigElement.Value)
9090 ArgChanged = true;
9091
Chad Rosier1dcde962012-08-08 18:46:20 +00009092 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009093 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9094 };
9095 Elements.push_back(Expansion);
9096 continue;
9097 }
9098
9099 // Record right away that the argument was changed. This needs
9100 // to happen even if the array expands to nothing.
9101 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009102
Ted Kremeneke65b0862012-03-06 20:05:56 +00009103 // The transform has determined that we should perform an elementwise
9104 // expansion of the pattern. Do so.
9105 for (unsigned I = 0; I != *NumExpansions; ++I) {
9106 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9107 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9108 if (Key.isInvalid())
9109 return ExprError();
9110
9111 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9112 if (Value.isInvalid())
9113 return ExprError();
9114
Chad Rosier1dcde962012-08-08 18:46:20 +00009115 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009116 Key.get(), Value.get(), SourceLocation(), NumExpansions
9117 };
9118
9119 // If any unexpanded parameter packs remain, we still have a
9120 // pack expansion.
9121 if (Key.get()->containsUnexpandedParameterPack() ||
9122 Value.get()->containsUnexpandedParameterPack())
9123 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
Ted Kremeneke65b0862012-03-06 20:05:56 +00009125 Elements.push_back(Element);
9126 }
9127
9128 // We've finished with this pack expansion.
9129 continue;
9130 }
9131
9132 // Transform and check key.
9133 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9134 if (Key.isInvalid())
9135 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
Ted Kremeneke65b0862012-03-06 20:05:56 +00009137 if (Key.get() != OrigElement.Key)
9138 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009139
Ted Kremeneke65b0862012-03-06 20:05:56 +00009140 // Transform and check value.
9141 ExprResult Value
9142 = getDerived().TransformExpr(OrigElement.Value);
9143 if (Value.isInvalid())
9144 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009145
Ted Kremeneke65b0862012-03-06 20:05:56 +00009146 if (Value.get() != OrigElement.Value)
9147 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009148
9149 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009150 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009151 };
9152 Elements.push_back(Element);
9153 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009154
Ted Kremeneke65b0862012-03-06 20:05:56 +00009155 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9156 return SemaRef.MaybeBindToTemporary(E);
9157
9158 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9159 Elements.data(),
9160 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009161}
9162
Mike Stump11289f42009-09-09 15:08:12 +00009163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009165TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009166 TypeSourceInfo *EncodedTypeInfo
9167 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9168 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009170
Douglas Gregora16548e2009-08-11 05:31:07 +00009171 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009172 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009173 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009174
9175 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009176 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009177 E->getRParenLoc());
9178}
Mike Stump11289f42009-09-09 15:08:12 +00009179
Douglas Gregora16548e2009-08-11 05:31:07 +00009180template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009181ExprResult TreeTransform<Derived>::
9182TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009183 // This is a kind of implicit conversion, and it needs to get dropped
9184 // and recomputed for the same general reasons that ImplicitCastExprs
9185 // do, as well a more specific one: this expression is only valid when
9186 // it appears *immediately* as an argument expression.
9187 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009188}
9189
9190template<typename Derived>
9191ExprResult TreeTransform<Derived>::
9192TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009193 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009194 = getDerived().TransformType(E->getTypeInfoAsWritten());
9195 if (!TSInfo)
9196 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009197
John McCall31168b02011-06-15 23:02:42 +00009198 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009199 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009200 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009201
John McCall31168b02011-06-15 23:02:42 +00009202 if (!getDerived().AlwaysRebuild() &&
9203 TSInfo == E->getTypeInfoAsWritten() &&
9204 Result.get() == E->getSubExpr())
9205 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009206
John McCall31168b02011-06-15 23:02:42 +00009207 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009208 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009209 Result.get());
9210}
9211
9212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009214TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009215 // Transform arguments.
9216 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009217 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009218 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009219 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009220 &ArgChanged))
9221 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009222
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009223 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9224 // Class message: transform the receiver type.
9225 TypeSourceInfo *ReceiverTypeInfo
9226 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9227 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009228 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009229
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009230 // If nothing changed, just retain the existing message send.
9231 if (!getDerived().AlwaysRebuild() &&
9232 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009233 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009234
9235 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009236 SmallVector<SourceLocation, 16> SelLocs;
9237 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009238 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9239 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009240 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009241 E->getMethodDecl(),
9242 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009243 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009244 E->getRightLoc());
9245 }
9246
9247 // Instance message: transform the receiver
9248 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9249 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009250 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009251 = getDerived().TransformExpr(E->getInstanceReceiver());
9252 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009253 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009254
9255 // If nothing changed, just retain the existing message send.
9256 if (!getDerived().AlwaysRebuild() &&
9257 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009258 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009259
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009260 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009261 SmallVector<SourceLocation, 16> SelLocs;
9262 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009263 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009264 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009265 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009266 E->getMethodDecl(),
9267 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009268 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009269 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009270}
9271
Mike Stump11289f42009-09-09 15:08:12 +00009272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009274TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009275 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009276}
9277
Mike Stump11289f42009-09-09 15:08:12 +00009278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009281 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009282}
9283
Mike Stump11289f42009-09-09 15:08:12 +00009284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009286TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009287 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009288 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009289 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009290 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009291
9292 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Douglas Gregord51d90d2010-04-26 20:11:03 +00009294 // If nothing changed, just retain the existing expression.
9295 if (!getDerived().AlwaysRebuild() &&
9296 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009297 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009298
John McCallb268a282010-08-23 23:25:46 +00009299 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009300 E->getLocation(),
9301 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009302}
9303
Mike Stump11289f42009-09-09 15:08:12 +00009304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009306TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009307 // 'super' and types never change. Property never changes. Just
9308 // retain the existing expression.
9309 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009310 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Douglas Gregor9faee212010-04-26 20:47:02 +00009312 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009313 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009314 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
Douglas Gregor9faee212010-04-26 20:47:02 +00009317 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009318
Douglas Gregor9faee212010-04-26 20:47:02 +00009319 // If nothing changed, just retain the existing expression.
9320 if (!getDerived().AlwaysRebuild() &&
9321 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009322 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009323
John McCallb7bd14f2010-12-02 01:19:52 +00009324 if (E->isExplicitProperty())
9325 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9326 E->getExplicitProperty(),
9327 E->getLocation());
9328
9329 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009330 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009331 E->getImplicitPropertyGetter(),
9332 E->getImplicitPropertySetter(),
9333 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009334}
9335
Mike Stump11289f42009-09-09 15:08:12 +00009336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009337ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009338TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9339 // Transform the base expression.
9340 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9341 if (Base.isInvalid())
9342 return ExprError();
9343
9344 // Transform the key expression.
9345 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9346 if (Key.isInvalid())
9347 return ExprError();
9348
9349 // If nothing changed, just retain the existing expression.
9350 if (!getDerived().AlwaysRebuild() &&
9351 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9352 return SemaRef.Owned(E);
9353
Chad Rosier1dcde962012-08-08 18:46:20 +00009354 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009355 Base.get(), Key.get(),
9356 E->getAtIndexMethodDecl(),
9357 E->setAtIndexMethodDecl());
9358}
9359
9360template<typename Derived>
9361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009362TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009363 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009364 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009365 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009366 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009367
Douglas Gregord51d90d2010-04-26 20:11:03 +00009368 // If nothing changed, just retain the existing expression.
9369 if (!getDerived().AlwaysRebuild() &&
9370 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009371 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009372
John McCallb268a282010-08-23 23:25:46 +00009373 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009374 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009375 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009376}
9377
Mike Stump11289f42009-09-09 15:08:12 +00009378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009379ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009380TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009381 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009382 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009383 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009384 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009385 SubExprs, &ArgumentChanged))
9386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009387
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 if (!getDerived().AlwaysRebuild() &&
9389 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009390 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009393 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009394 E->getRParenLoc());
9395}
9396
Mike Stump11289f42009-09-09 15:08:12 +00009397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009398ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009399TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9400 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9401 if (SrcExpr.isInvalid())
9402 return ExprError();
9403
9404 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9405 if (!Type)
9406 return ExprError();
9407
9408 if (!getDerived().AlwaysRebuild() &&
9409 Type == E->getTypeSourceInfo() &&
9410 SrcExpr.get() == E->getSrcExpr())
9411 return SemaRef.Owned(E);
9412
9413 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9414 SrcExpr.get(), Type,
9415 E->getRParenLoc());
9416}
9417
9418template<typename Derived>
9419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009420TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009421 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009422
Craig Topperc3ec1492014-05-26 06:22:03 +00009423 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009424 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9425
9426 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009427 blockScope->TheDecl->setBlockMissingReturnType(
9428 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009429
Chris Lattner01cf8db2011-07-20 06:58:45 +00009430 SmallVector<ParmVarDecl*, 4> params;
9431 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009432
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009433 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009434 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9435 oldBlock->param_begin(),
9436 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009437 nullptr, paramTypes, &params)) {
9438 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009439 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009440 }
John McCall490112f2011-02-04 18:33:18 +00009441
Jordan Rosea0a86be2013-03-08 22:25:36 +00009442 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009443 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009444 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009445
Jordan Rose5c382722013-03-08 21:51:21 +00009446 QualType functionType =
9447 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009448 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009449 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009450
9451 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009452 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009453 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009454
9455 if (!oldBlock->blockMissingReturnType()) {
9456 blockScope->HasImplicitReturnType = false;
9457 blockScope->ReturnType = exprResultType;
9458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009459
John McCall3882ace2011-01-05 12:14:39 +00009460 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009461 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009462 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009463 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009464 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009465 }
John McCall3882ace2011-01-05 12:14:39 +00009466
John McCall490112f2011-02-04 18:33:18 +00009467#ifndef NDEBUG
9468 // In builds with assertions, make sure that we captured everything we
9469 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009470 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009471 for (const auto &I : oldBlock->captures()) {
9472 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009473
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009474 // Ignore parameter packs.
9475 if (isa<ParmVarDecl>(oldCapture) &&
9476 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9477 continue;
John McCall490112f2011-02-04 18:33:18 +00009478
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009479 VarDecl *newCapture =
9480 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9481 oldCapture));
9482 assert(blockScope->CaptureMap.count(newCapture));
9483 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009484 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009485 }
9486#endif
9487
9488 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009489 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009490}
9491
Mike Stump11289f42009-09-09 15:08:12 +00009492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009493ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009494TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009495 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009496}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009497
9498template<typename Derived>
9499ExprResult
9500TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009501 QualType RetTy = getDerived().TransformType(E->getType());
9502 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009503 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009504 SubExprs.reserve(E->getNumSubExprs());
9505 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9506 SubExprs, &ArgumentChanged))
9507 return ExprError();
9508
9509 if (!getDerived().AlwaysRebuild() &&
9510 !ArgumentChanged)
9511 return SemaRef.Owned(E);
9512
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009513 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009514 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009515}
Chad Rosier1dcde962012-08-08 18:46:20 +00009516
Douglas Gregora16548e2009-08-11 05:31:07 +00009517//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518// Type reconstruction
9519//===----------------------------------------------------------------------===//
9520
Mike Stump11289f42009-09-09 15:08:12 +00009521template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009522QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9523 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009524 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 getDerived().getBaseEntity());
9526}
9527
Mike Stump11289f42009-09-09 15:08:12 +00009528template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009529QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9530 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009531 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009532 getDerived().getBaseEntity());
9533}
9534
Mike Stump11289f42009-09-09 15:08:12 +00009535template<typename Derived>
9536QualType
John McCall70dd5f62009-10-30 00:06:24 +00009537TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9538 bool WrittenAsLValue,
9539 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009540 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009541 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009542}
9543
9544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009545QualType
John McCall70dd5f62009-10-30 00:06:24 +00009546TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9547 QualType ClassType,
9548 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009549 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9550 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009551}
9552
9553template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009554QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009555TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9556 ArrayType::ArraySizeModifier SizeMod,
9557 const llvm::APInt *Size,
9558 Expr *SizeExpr,
9559 unsigned IndexTypeQuals,
9560 SourceRange BracketsRange) {
9561 if (SizeExpr || !Size)
9562 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9563 IndexTypeQuals, BracketsRange,
9564 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009565
9566 QualType Types[] = {
9567 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9568 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9569 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009570 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009571 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009572 QualType SizeType;
9573 for (unsigned I = 0; I != NumTypes; ++I)
9574 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9575 SizeType = Types[I];
9576 break;
9577 }
Mike Stump11289f42009-09-09 15:08:12 +00009578
Eli Friedman9562f392012-01-25 23:20:27 +00009579 // Note that we can return a VariableArrayType here in the case where
9580 // the element type was a dependent VariableArrayType.
9581 IntegerLiteral *ArraySize
9582 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9583 /*FIXME*/BracketsRange.getBegin());
9584 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009585 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009586 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009587}
Mike Stump11289f42009-09-09 15:08:12 +00009588
Douglas Gregord6ff3322009-08-04 16:50:30 +00009589template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009590QualType
9591TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009592 ArrayType::ArraySizeModifier SizeMod,
9593 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009594 unsigned IndexTypeQuals,
9595 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009596 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009597 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009598}
9599
9600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009601QualType
Mike Stump11289f42009-09-09 15:08:12 +00009602TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009603 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009604 unsigned IndexTypeQuals,
9605 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009606 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009607 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009608}
Mike Stump11289f42009-09-09 15:08:12 +00009609
Douglas Gregord6ff3322009-08-04 16:50:30 +00009610template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009611QualType
9612TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009613 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009614 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009615 unsigned IndexTypeQuals,
9616 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009617 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009618 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009619 IndexTypeQuals, BracketsRange);
9620}
9621
9622template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009623QualType
9624TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009625 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009626 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009627 unsigned IndexTypeQuals,
9628 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009629 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009630 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009631 IndexTypeQuals, BracketsRange);
9632}
9633
9634template<typename Derived>
9635QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009636 unsigned NumElements,
9637 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009638 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009639 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009640}
Mike Stump11289f42009-09-09 15:08:12 +00009641
Douglas Gregord6ff3322009-08-04 16:50:30 +00009642template<typename Derived>
9643QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9644 unsigned NumElements,
9645 SourceLocation AttributeLoc) {
9646 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9647 NumElements, true);
9648 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009649 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9650 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009651 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009652}
Mike Stump11289f42009-09-09 15:08:12 +00009653
Douglas Gregord6ff3322009-08-04 16:50:30 +00009654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009655QualType
9656TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009657 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009658 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009659 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009660}
Mike Stump11289f42009-09-09 15:08:12 +00009661
Douglas Gregord6ff3322009-08-04 16:50:30 +00009662template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009663QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9664 QualType T,
9665 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009666 const FunctionProtoType::ExtProtoInfo &EPI) {
9667 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009668 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009669 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009670 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009671}
Mike Stump11289f42009-09-09 15:08:12 +00009672
Douglas Gregord6ff3322009-08-04 16:50:30 +00009673template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009674QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9675 return SemaRef.Context.getFunctionNoProtoType(T);
9676}
9677
9678template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009679QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9680 assert(D && "no decl found");
9681 if (D->isInvalidDecl()) return QualType();
9682
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009683 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009684 TypeDecl *Ty;
9685 if (isa<UsingDecl>(D)) {
9686 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009687 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009688 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9689
9690 // A valid resolved using typename decl points to exactly one type decl.
9691 assert(++Using->shadow_begin() == Using->shadow_end());
9692 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009693
John McCallb96ec562009-12-04 22:46:56 +00009694 } else {
9695 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9696 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9697 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9698 }
9699
9700 return SemaRef.Context.getTypeDeclType(Ty);
9701}
9702
9703template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009704QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9705 SourceLocation Loc) {
9706 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009707}
9708
9709template<typename Derived>
9710QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9711 return SemaRef.Context.getTypeOfType(Underlying);
9712}
9713
9714template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009715QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9716 SourceLocation Loc) {
9717 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009718}
9719
9720template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009721QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9722 UnaryTransformType::UTTKind UKind,
9723 SourceLocation Loc) {
9724 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9725}
9726
9727template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009728QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009729 TemplateName Template,
9730 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009731 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009732 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009733}
Mike Stump11289f42009-09-09 15:08:12 +00009734
Douglas Gregor1135c352009-08-06 05:28:30 +00009735template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009736QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9737 SourceLocation KWLoc) {
9738 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9739}
9740
9741template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009742TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009743TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009744 bool TemplateKW,
9745 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009746 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009747 Template);
9748}
9749
9750template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009751TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009752TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9753 const IdentifierInfo &Name,
9754 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009755 QualType ObjectType,
9756 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009757 UnqualifiedId TemplateName;
9758 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009759 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009760 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009761 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009762 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009763 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009764 /*EnteringContext=*/false,
9765 Template);
John McCall31f82722010-11-12 08:19:04 +00009766 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009767}
Mike Stump11289f42009-09-09 15:08:12 +00009768
Douglas Gregora16548e2009-08-11 05:31:07 +00009769template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009770TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009771TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009772 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009773 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009774 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009775 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009776 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009777 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009778 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009779 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009780 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009781 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009782 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009783 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009784 /*EnteringContext=*/false,
9785 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009786 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009787}
Chad Rosier1dcde962012-08-08 18:46:20 +00009788
Douglas Gregor71395fa2009-11-04 00:56:37 +00009789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009790ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009791TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9792 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009793 Expr *OrigCallee,
9794 Expr *First,
9795 Expr *Second) {
9796 Expr *Callee = OrigCallee->IgnoreParenCasts();
9797 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009798
Douglas Gregora16548e2009-08-11 05:31:07 +00009799 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009800 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009801 if (!First->getType()->isOverloadableType() &&
9802 !Second->getType()->isOverloadableType())
9803 return getSema().CreateBuiltinArraySubscriptExpr(First,
9804 Callee->getLocStart(),
9805 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009806 } else if (Op == OO_Arrow) {
9807 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009808 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9809 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009810 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 // The argument is not of overloadable type, so try to create a
9812 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009813 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009814 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009815
John McCallb268a282010-08-23 23:25:46 +00009816 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009817 }
9818 } else {
John McCallb268a282010-08-23 23:25:46 +00009819 if (!First->getType()->isOverloadableType() &&
9820 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009821 // Neither of the arguments is an overloadable type, so try to
9822 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009823 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009824 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009825 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009826 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009828
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009829 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 }
9831 }
Mike Stump11289f42009-09-09 15:08:12 +00009832
9833 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009834 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009835 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009836
John McCallb268a282010-08-23 23:25:46 +00009837 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009838 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009839 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009840 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009841 // If we've resolved this to a particular non-member function, just call
9842 // that function. If we resolved it to a member function,
9843 // CreateOverloaded* will find that function for us.
9844 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9845 if (!isa<CXXMethodDecl>(ND))
9846 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009847 }
Mike Stump11289f42009-09-09 15:08:12 +00009848
Douglas Gregora16548e2009-08-11 05:31:07 +00009849 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009850 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009851 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009852
Douglas Gregora16548e2009-08-11 05:31:07 +00009853 // Create the overloaded operator invocation for unary operators.
9854 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009855 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009856 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009857 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009858 }
Mike Stump11289f42009-09-09 15:08:12 +00009859
Douglas Gregore9d62932011-07-15 16:25:15 +00009860 if (Op == OO_Subscript) {
9861 SourceLocation LBrace;
9862 SourceLocation RBrace;
9863
9864 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9865 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9866 LBrace = SourceLocation::getFromRawEncoding(
9867 NameLoc.CXXOperatorName.BeginOpNameLoc);
9868 RBrace = SourceLocation::getFromRawEncoding(
9869 NameLoc.CXXOperatorName.EndOpNameLoc);
9870 } else {
9871 LBrace = Callee->getLocStart();
9872 RBrace = OpLoc;
9873 }
9874
9875 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9876 First, Second);
9877 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009878
Douglas Gregora16548e2009-08-11 05:31:07 +00009879 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009880 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009881 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009882 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9883 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009885
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009886 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009887}
Mike Stump11289f42009-09-09 15:08:12 +00009888
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009889template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009890ExprResult
John McCallb268a282010-08-23 23:25:46 +00009891TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009892 SourceLocation OperatorLoc,
9893 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009894 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009895 TypeSourceInfo *ScopeType,
9896 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009897 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009898 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009899 QualType BaseType = Base->getType();
9900 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009901 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009902 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009903 !BaseType->getAs<PointerType>()->getPointeeType()
9904 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009905 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009906 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009907 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009908 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009909 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009910 /*FIXME?*/true);
9911 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009912
Douglas Gregor678f90d2010-02-25 01:56:36 +00009913 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009914 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9915 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9916 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9917 NameInfo.setNamedTypeInfo(DestroyedType);
9918
Richard Smith8e4a3862012-05-15 06:15:11 +00009919 // The scope type is now known to be a valid nested name specifier
9920 // component. Tack it on to the end of the nested name specifier.
9921 if (ScopeType)
9922 SS.Extend(SemaRef.Context, SourceLocation(),
9923 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009924
Abramo Bagnara7945c982012-01-27 09:46:47 +00009925 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009926 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009927 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009928 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009929 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009930 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009931 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009932}
9933
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009934template<typename Derived>
9935StmtResult
9936TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009937 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +00009938 CapturedDecl *CD = S->getCapturedDecl();
9939 unsigned NumParams = CD->getNumParams();
9940 unsigned ContextParamPos = CD->getContextParamPosition();
9941 SmallVector<Sema::CapturedParamNameType, 4> Params;
9942 for (unsigned I = 0; I < NumParams; ++I) {
9943 if (I != ContextParamPos) {
9944 Params.push_back(
9945 std::make_pair(
9946 CD->getParam(I)->getName(),
9947 getDerived().TransformType(CD->getParam(I)->getType())));
9948 } else {
9949 Params.push_back(std::make_pair(StringRef(), QualType()));
9950 }
9951 }
Craig Topperc3ec1492014-05-26 06:22:03 +00009952 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +00009953 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +00009954 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9955
9956 if (Body.isInvalid()) {
9957 getSema().ActOnCapturedRegionError();
9958 return StmtError();
9959 }
9960
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009961 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009962}
9963
Douglas Gregord6ff3322009-08-04 16:50:30 +00009964} // end namespace clang
9965
9966#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H