blob: 8e21b56bb788b61c930711e228512377639e3c8b [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.
Richard Smithc6abd962014-07-25 01:12:44 +0000347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000607
Richard Smithdb2630f2012-10-21 03:28:35 +0000608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
611
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
615
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000617
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000620#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000622 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000623#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000625 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000626#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000627#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000628
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000630 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000631 OMPClause *Transform ## Class(Class *S);
632#include "clang/Basic/OpenMPKinds.def"
633
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// \brief Build a new pointer type given its pointee type.
635 ///
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
640 /// \brief Build a new block pointer type given its pointee type.
641 ///
Mike Stump11289f42009-09-09 15:08:12 +0000642 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 ///
John McCall70dd5f62009-10-30 00:06:24 +0000648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 ///
John McCall70dd5f62009-10-30 00:06:24 +0000652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
655 bool LValue,
656 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
660 ///
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
668 /// qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
676 Expr *SizeExpr,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
693 ///
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000696 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000706 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
Mike Stump11289f42009-09-09 15:08:12 +0000712 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// size modifier, size expression, and index type qualifiers.
714 ///
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000717 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000719 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
722
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
725 ///
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000729 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
733 ///
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
739 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// given the element type and number of elements.
741 ///
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000745 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new function type.
749 ///
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000753 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000754 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000755
John McCall550e0c22009-10-21 00:40:46 +0000756 /// \brief Build a new unprototyped function type.
757 QualType RebuildFunctionNoProtoType(QualType ResultType);
758
John McCallb96ec562009-12-04 22:46:56 +0000759 /// \brief Rebuild an unresolved typename type, given the decl that
760 /// the UnresolvedUsingTypenameDecl was transformed to.
761 QualType RebuildUnresolvedUsingType(Decl *D);
762
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000764 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 return SemaRef.Context.getTypeDeclType(Typedef);
766 }
767
768 /// \brief Build a new class/struct/union type.
769 QualType RebuildRecordType(RecordDecl *Record) {
770 return SemaRef.Context.getTypeDeclType(Record);
771 }
772
773 /// \brief Build a new Enum type.
774 QualType RebuildEnumType(EnumDecl *Enum) {
775 return SemaRef.Context.getTypeDeclType(Enum);
776 }
John McCallfcc33b02009-09-05 00:15:47 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, performs semantic analysis when building the typeof type.
781 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000782 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783
Mike Stump11289f42009-09-09 15:08:12 +0000784 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 ///
786 /// By default, builds a new TypeOfType with the given underlying type.
787 QualType RebuildTypeOfType(QualType Underlying);
788
Alexis Hunte852b102011-05-24 22:41:36 +0000789 /// \brief Build a new unary transform type.
790 QualType RebuildUnaryTransformType(QualType BaseType,
791 UnaryTransformType::UTTKind UKind,
792 SourceLocation Loc);
793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 ///
796 /// By default, performs semantic analysis when building the decltype type.
797 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000798 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000799
Richard Smith74aeef52013-04-26 16:15:35 +0000800 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000801 ///
802 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000803 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000804 // Note, IsDependent is always false here: we implicitly convert an 'auto'
805 // which has been deduced to a dependent type into an undeduced 'auto', so
806 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000807 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
808 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000809 }
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new template specialization type.
812 ///
813 /// By default, performs semantic analysis when building the template
814 /// specialization type. Subclasses may override this routine to provide
815 /// different behavior.
816 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000817 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000818 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000820 /// \brief Build a new parenthesized type.
821 ///
822 /// By default, builds a new ParenType type from the inner type.
823 /// Subclasses may override this routine to provide different behavior.
824 QualType RebuildParenType(QualType InnerType) {
825 return SemaRef.Context.getParenType(InnerType);
826 }
827
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 /// \brief Build a new qualified name type.
829 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000830 /// By default, builds a new ElaboratedType type from the keyword,
831 /// the nested-name-specifier and the named type.
832 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000833 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
834 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000835 NestedNameSpecifierLoc QualifierLoc,
836 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000837 return SemaRef.Context.getElaboratedType(Keyword,
838 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000839 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000840 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000841
842 /// \brief Build a new typename type that refers to a template-id.
843 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000844 /// By default, builds a new DependentNameType type from the
845 /// nested-name-specifier and the given type. Subclasses may override
846 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000847 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000848 ElaboratedTypeKeyword Keyword,
849 NestedNameSpecifierLoc QualifierLoc,
850 const IdentifierInfo *Name,
851 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000852 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000853 // Rebuild the template name.
854 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000855 CXXScopeSpec SS;
856 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000857 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000858 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
859 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000860
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 if (InstName.isNull())
862 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // If it's still dependent, make a dependent specialization.
865 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000866 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
867 QualifierLoc.getNestedNameSpecifier(),
868 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000869 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000870
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 // Otherwise, make an elaborated type wrapping a non-dependent
872 // specialization.
873 QualType T =
874 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
875 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000876
Craig Topperc3ec1492014-05-26 06:22:03 +0000877 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000878 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000879
880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000882 T);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new typename type that refers to an identifier.
886 ///
887 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000888 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000891 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000894 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000895 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000897
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000898 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000899 // If the name is still dependent, just build a new dependent name type.
900 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000901 return SemaRef.Context.getDependentNameType(Keyword,
902 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000903 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000904 }
905
Abramo Bagnara6150c882010-05-11 21:36:43 +0000906 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000907 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000908 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000909
910 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
911
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000913 // into a non-dependent elaborated-type-specifier. Find the tag we're
914 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000915 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
917 if (!DC)
918 return QualType();
919
John McCallbf8c5192010-05-27 06:40:31 +0000920 if (SemaRef.RequireCompleteDeclContext(SS, DC))
921 return QualType();
922
Craig Topperc3ec1492014-05-26 06:22:03 +0000923 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 SemaRef.LookupQualifiedName(Result, DC);
925 switch (Result.getResultKind()) {
926 case LookupResult::NotFound:
927 case LookupResult::NotFoundInCurrentInstantiation:
928 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
Douglas Gregore677daf2010-03-31 22:19:08 +0000930 case LookupResult::Found:
931 Tag = Result.getAsSingle<TagDecl>();
932 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregore677daf2010-03-31 22:19:08 +0000934 case LookupResult::FoundOverloaded:
935 case LookupResult::FoundUnresolvedValue:
936 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000937
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 case LookupResult::Ambiguous:
939 // Let the LookupResult structure handle ambiguities.
940 return QualType();
941 }
942
943 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000944 // Check where the name exists but isn't a tag type and use that to emit
945 // better diagnostics.
946 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
947 SemaRef.LookupQualifiedName(Result, DC);
948 switch (Result.getResultKind()) {
949 case LookupResult::Found:
950 case LookupResult::FoundOverloaded:
951 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000952 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000953 unsigned Kind = 0;
954 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000955 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
956 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
958 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
959 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000960 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000962 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000963 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000964 break;
965 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 return QualType();
967 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000968
Richard Trieucaa33d32011-06-10 03:11:26 +0000969 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
970 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000971 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
973 return QualType();
974 }
975
976 // Build the elaborated-type-specifier type.
977 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000978 return SemaRef.Context.getElaboratedType(Keyword,
979 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000980 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregor822d0302011-01-12 17:07:58 +0000983 /// \brief Build a new pack expansion type.
984 ///
985 /// By default, builds a new PackExpansionType type from the given pattern.
986 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000987 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000988 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000989 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000990 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000991 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
992 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000993 }
994
Eli Friedman0dfb8892011-10-06 23:00:33 +0000995 /// \brief Build a new atomic type given its value type.
996 ///
997 /// By default, performs semantic analysis when building the atomic type.
998 /// Subclasses may override this routine to provide different behavior.
999 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1000
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 /// \brief Build a new template name given a nested name specifier, a flag
1002 /// indicating whether the "template" keyword was provided, and the template
1003 /// that the template name refers to.
1004 ///
1005 /// By default, builds the new template name directly. Subclasses may override
1006 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001007 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001008 bool TemplateKW,
1009 TemplateDecl *Template);
1010
Douglas Gregor71dc5092009-08-06 06:41:21 +00001011 /// \brief Build a new template name given a nested name specifier and the
1012 /// name that is referred to as a template.
1013 ///
1014 /// By default, performs semantic analysis to determine whether the name can
1015 /// be resolved to a specific template, then builds the appropriate kind of
1016 /// template name. Subclasses may override this routine to provide different
1017 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001018 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1019 const IdentifierInfo &Name,
1020 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001021 QualType ObjectType,
1022 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregor71395fa2009-11-04 00:56:37 +00001024 /// \brief Build a new template name given a nested name specifier and the
1025 /// overloaded operator name that is referred to as a template.
1026 ///
1027 /// By default, performs semantic analysis to determine whether the name can
1028 /// be resolved to a specific template, then builds the appropriate kind of
1029 /// template name. Subclasses may override this routine to provide different
1030 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001031 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001032 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001033 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001034 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001035
1036 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001037 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001038 ///
1039 /// By default, performs semantic analysis to determine whether the name can
1040 /// be resolved to a specific template, then builds the appropriate kind of
1041 /// template name. Subclasses may override this routine to provide different
1042 /// behavior.
1043 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1044 const TemplateArgument &ArgPack) {
1045 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1046 }
1047
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 /// \brief Build a new compound statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 MultiStmtArg Statements,
1054 SourceLocation RBraceLoc,
1055 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001056 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 IsStmtExpr);
1058 }
1059
1060 /// \brief Build a new case statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001065 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001067 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001069 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 ColonLoc);
1071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Attach the body to a new case statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001078 getSema().ActOnCaseStmtBody(S, Body);
1079 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new default statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001088 Stmt *SubStmt) {
1089 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001090 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 /// \brief Build a new label statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001097 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1098 SourceLocation ColonLoc, Stmt *SubStmt) {
1099 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Richard Smithc202b282012-04-14 00:33:13 +00001102 /// \brief Build a new label statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001106 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1107 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001108 Stmt *SubStmt) {
1109 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1110 }
1111
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 /// \brief Build a new "if" statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001117 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001118 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001119 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 /// \brief Start building a new switch statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001126 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001127 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001128 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001129 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Attach the body to the switch statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001137 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new while statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1146 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001147 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 /// \brief Build a new do-while statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001155 SourceLocation WhileLoc, SourceLocation LParenLoc,
1156 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001157 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1158 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 }
1160
1161 /// \brief Build a new for statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001165 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001166 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001167 VarDecl *CondVar, Sema::FullExprArg Inc,
1168 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001169 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 /// \brief Build a new goto statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1178 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001179 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 }
1181
1182 /// \brief Build a new indirect goto statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 SourceLocation StarLoc,
1188 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Build a new return statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001196 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001197 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new declaration statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001204 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001205 SourceLocation StartLoc, SourceLocation EndLoc) {
1206 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001207 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Anders Carlssonaaeef072010-01-24 05:50:09 +00001210 /// \brief Build a new inline asm statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001214 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1215 bool IsVolatile, unsigned NumOutputs,
1216 unsigned NumInputs, IdentifierInfo **Names,
1217 MultiExprArg Constraints, MultiExprArg Exprs,
1218 Expr *AsmString, MultiExprArg Clobbers,
1219 SourceLocation RParenLoc) {
1220 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1221 NumInputs, Names, Constraints, Exprs,
1222 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001223 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001224
Chad Rosier32503022012-06-11 20:47:18 +00001225 /// \brief Build a new MS style inline asm statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001229 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001230 ArrayRef<Token> AsmToks,
1231 StringRef AsmString,
1232 unsigned NumOutputs, unsigned NumInputs,
1233 ArrayRef<StringRef> Constraints,
1234 ArrayRef<StringRef> Clobbers,
1235 ArrayRef<Expr*> Exprs,
1236 SourceLocation EndLoc) {
1237 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1238 NumOutputs, NumInputs,
1239 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001240 }
1241
James Dennett2a4d13c2012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001247 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001248 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001249 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001250 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001251 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001252 }
1253
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001254 /// \brief Rebuild an Objective-C exception declaration.
1255 ///
1256 /// By default, performs semantic analysis to build the new declaration.
1257 /// Subclasses may override this routine to provide different behavior.
1258 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1259 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001260 return getSema().BuildObjCExceptionDecl(TInfo, T,
1261 ExceptionDecl->getInnerLocStart(),
1262 ExceptionDecl->getLocation(),
1263 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001265
James Dennett2a4d13c2012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001271 SourceLocation RParenLoc,
1272 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001273 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001275 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001277
James Dennett2a4d13c2012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001283 Stmt *Body) {
1284 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001286
James Dennett2a4d13c2012-06-15 07:13:21 +00001287 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001292 Expr *Operand) {
1293 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001295
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001296 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001300 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001301 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001302 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001303 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001304 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001305 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1306 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey Bataev3778b602014-07-17 07:32:53 +00001321 /// \brief Build a new OpenMP 'final' clause.
1322 ///
1323 /// By default, performs semantic analysis to build the new OpenMP clause.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1326 SourceLocation LParenLoc,
1327 SourceLocation EndLoc) {
1328 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1329 EndLoc);
1330 }
1331
Alexey Bataev568a8332014-03-06 06:15:19 +00001332 /// \brief Build a new OpenMP 'num_threads' clause.
1333 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001334 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1341 LParenLoc, EndLoc);
1342 }
1343
Alexey Bataev62c87d22014-03-21 04:51:18 +00001344 /// \brief Build a new OpenMP 'safelen' clause.
1345 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001346 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1352 }
1353
Alexander Musman8bd31e62014-05-27 15:12:19 +00001354 /// \brief Build a new OpenMP 'collapse' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1362 EndLoc);
1363 }
1364
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001365 /// \brief Build a new OpenMP 'default' clause.
1366 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001367 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1370 SourceLocation KindKwLoc,
1371 SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1375 StartLoc, LParenLoc, EndLoc);
1376 }
1377
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001378 /// \brief Build a new OpenMP 'proc_bind' clause.
1379 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001380 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001381 /// Subclasses may override this routine to provide different behavior.
1382 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1383 SourceLocation KindKwLoc,
1384 SourceLocation StartLoc,
1385 SourceLocation LParenLoc,
1386 SourceLocation EndLoc) {
1387 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1388 StartLoc, LParenLoc, EndLoc);
1389 }
1390
Alexey Bataev56dafe82014-06-20 07:16:17 +00001391 /// \brief Build a new OpenMP 'schedule' clause.
1392 ///
1393 /// By default, performs semantic analysis to build the new OpenMP clause.
1394 /// Subclasses may override this routine to provide different behavior.
1395 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1396 Expr *ChunkSize,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation KindLoc,
1400 SourceLocation CommaLoc,
1401 SourceLocation EndLoc) {
1402 return getSema().ActOnOpenMPScheduleClause(
1403 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1404 }
1405
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001406 /// \brief Build a new OpenMP 'private' clause.
1407 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001408 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1415 EndLoc);
1416 }
1417
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001418 /// \brief Build a new OpenMP 'firstprivate' clause.
1419 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001420 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1423 SourceLocation StartLoc,
1424 SourceLocation LParenLoc,
1425 SourceLocation EndLoc) {
1426 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1427 EndLoc);
1428 }
1429
Alexander Musman1bb328c2014-06-04 13:06:39 +00001430 /// \brief Build a new OpenMP 'lastprivate' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1439 EndLoc);
1440 }
1441
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001442 /// \brief Build a new OpenMP 'shared' clause.
1443 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001444 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001445 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001446 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1447 SourceLocation StartLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1451 EndLoc);
1452 }
1453
Alexey Bataevc5e02582014-06-16 07:08:35 +00001454 /// \brief Build a new OpenMP 'reduction' clause.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation ColonLoc,
1462 SourceLocation EndLoc,
1463 CXXScopeSpec &ReductionIdScopeSpec,
1464 const DeclarationNameInfo &ReductionId) {
1465 return getSema().ActOnOpenMPReductionClause(
1466 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1467 ReductionId);
1468 }
1469
Alexander Musman8dba6642014-04-22 13:09:42 +00001470 /// \brief Build a new OpenMP 'linear' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation ColonLoc,
1478 SourceLocation EndLoc) {
1479 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1480 ColonLoc, EndLoc);
1481 }
1482
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001483 /// \brief Build a new OpenMP 'aligned' clause.
1484 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001485 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001486 /// Subclasses may override this routine to provide different behavior.
1487 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1488 SourceLocation StartLoc,
1489 SourceLocation LParenLoc,
1490 SourceLocation ColonLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1493 LParenLoc, ColonLoc, EndLoc);
1494 }
1495
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001496 /// \brief Build a new OpenMP 'copyin' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataevbae9a792014-06-27 10:37:06 +00001508 /// \brief Build a new OpenMP 'copyprivate' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1517 EndLoc);
1518 }
1519
Alexey Bataev6125da92014-07-21 11:26:11 +00001520 /// \brief Build a new OpenMP 'flush' pseudo clause.
1521 ///
1522 /// By default, performs semantic analysis to build the new OpenMP clause.
1523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1525 SourceLocation StartLoc,
1526 SourceLocation LParenLoc,
1527 SourceLocation EndLoc) {
1528 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1529 EndLoc);
1530 }
1531
James Dennett2a4d13c2012-06-15 07:13:21 +00001532 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1536 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1537 Expr *object) {
1538 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1539 }
1540
James Dennett2a4d13c2012-06-15 07:13:21 +00001541 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001542 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001543 /// By default, performs semantic analysis to build the new statement.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001546 Expr *Object, Stmt *Body) {
1547 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001548 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001549
James Dennett2a4d13c2012-06-15 07:13:21 +00001550 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1555 Stmt *Body) {
1556 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1557 }
John McCall53848232011-07-27 01:07:15 +00001558
Douglas Gregorf68a5082010-04-22 23:10:45 +00001559 /// \brief Build a new Objective-C fast enumeration statement.
1560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001564 Stmt *Element,
1565 Expr *Collection,
1566 SourceLocation RParenLoc,
1567 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001568 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001569 Element,
John McCallb268a282010-08-23 23:25:46 +00001570 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001571 RParenLoc);
1572 if (ForEachStmt.isInvalid())
1573 return StmtError();
1574
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001575 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001577
Douglas Gregorebe10102009-08-20 07:17:43 +00001578 /// \brief Build a new C++ exception declaration.
1579 ///
1580 /// By default, performs semantic analysis to build the new decaration.
1581 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001582 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001583 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001584 SourceLocation StartLoc,
1585 SourceLocation IdLoc,
1586 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001587 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001588 StartLoc, IdLoc, Id);
1589 if (Var)
1590 getSema().CurContext->addDecl(Var);
1591 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001592 }
1593
1594 /// \brief Build a new C++ catch statement.
1595 ///
1596 /// By default, performs semantic analysis to build the new statement.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 VarDecl *ExceptionDecl,
1600 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001601 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1602 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregorebe10102009-08-20 07:17:43 +00001605 /// \brief Build a new C++ try statement.
1606 ///
1607 /// By default, performs semantic analysis to build the new statement.
1608 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001609 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1610 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001611 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001612 }
Mike Stump11289f42009-09-09 15:08:12 +00001613
Richard Smith02e85f32011-04-14 22:09:26 +00001614 /// \brief Build a new C++0x range-based for statement.
1615 ///
1616 /// By default, performs semantic analysis to build the new statement.
1617 /// Subclasses may override this routine to provide different behavior.
1618 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1619 SourceLocation ColonLoc,
1620 Stmt *Range, Stmt *BeginEnd,
1621 Expr *Cond, Expr *Inc,
1622 Stmt *LoopVar,
1623 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001624 // If we've just learned that the range is actually an Objective-C
1625 // collection, treat this as an Objective-C fast enumeration loop.
1626 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1627 if (RangeStmt->isSingleDecl()) {
1628 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001629 if (RangeVar->isInvalidDecl())
1630 return StmtError();
1631
Douglas Gregorf7106af2013-04-08 18:40:13 +00001632 Expr *RangeExpr = RangeVar->getInit();
1633 if (!RangeExpr->isTypeDependent() &&
1634 RangeExpr->getType()->isObjCObjectPointerType())
1635 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1636 RParenLoc);
1637 }
1638 }
1639 }
1640
Richard Smith02e85f32011-04-14 22:09:26 +00001641 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001642 Cond, Inc, LoopVar, RParenLoc,
1643 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001644 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001645
1646 /// \brief Build a new C++0x range-based for statement.
1647 ///
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001650 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001651 bool IsIfExists,
1652 NestedNameSpecifierLoc QualifierLoc,
1653 DeclarationNameInfo NameInfo,
1654 Stmt *Nested) {
1655 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1656 QualifierLoc, NameInfo, Nested);
1657 }
1658
Richard Smith02e85f32011-04-14 22:09:26 +00001659 /// \brief Attach body to a C++0x range-based for statement.
1660 ///
1661 /// By default, performs semantic analysis to finish the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1664 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001666
David Majnemerfad8f482013-10-15 09:33:02 +00001667 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntb530bc02014-07-19 00:45:07 +00001668 Stmt *TryBlock, Stmt *Handler, int HandlerIndex,
1669 int HandlerParentIndex) {
1670 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler,
1671 HandlerIndex, HandlerParentIndex);
John Wiegley1c0675e2011-04-28 01:08:34 +00001672 }
1673
David Majnemerfad8f482013-10-15 09:33:02 +00001674 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001675 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001676 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001677 }
1678
David Majnemerfad8f482013-10-15 09:33:02 +00001679 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1680 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001681 }
1682
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// \brief Build a new expression that references a declaration.
1684 ///
1685 /// 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 RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001688 LookupResult &R,
1689 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001690 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1691 }
1692
1693
1694 /// \brief Build a new expression that references a declaration.
1695 ///
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001698 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001699 ValueDecl *VD,
1700 const DeclarationNameInfo &NameInfo,
1701 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001702 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001703 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001704
1705 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001706
1707 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 }
Mike Stump11289f42009-09-09 15:08:12 +00001709
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001711 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001714 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001716 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 }
1718
Douglas Gregorad8a3362009-09-04 17:36:40 +00001719 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001720 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001723 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001724 SourceLocation OperatorLoc,
1725 bool isArrow,
1726 CXXScopeSpec &SS,
1727 TypeSourceInfo *ScopeType,
1728 SourceLocation CCLoc,
1729 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001730 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001733 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001737 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001738 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001739 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 }
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregor882211c2010-04-28 22:16:22 +00001742 /// \brief Build a new builtin offsetof expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001746 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001747 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001748 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001749 unsigned NumComponents,
1750 SourceLocation RParenLoc) {
1751 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1752 NumComponents, RParenLoc);
1753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001754
1755 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001756 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001757 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001760 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1761 SourceLocation OpLoc,
1762 UnaryExprOrTypeTrait ExprKind,
1763 SourceRange R) {
1764 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 }
1766
Peter Collingbournee190dee2011-03-11 19:24:49 +00001767 /// \brief Build a new sizeof, alignof or vec step expression with an
1768 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001769 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 /// By default, performs semantic analysis to build the new expression.
1771 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001772 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1773 UnaryExprOrTypeTrait ExprKind,
1774 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001776 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001779
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001780 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 }
Mike Stump11289f42009-09-09 15:08:12 +00001782
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001784 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001787 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001789 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001791 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001792 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 RBracketLoc);
1794 }
1795
1796 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001797 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001800 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001802 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001803 Expr *ExecConfig = nullptr) {
1804 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001805 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 }
1807
1808 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001809 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// By default, performs semantic analysis to build the new expression.
1811 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001812 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001813 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001814 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001815 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001816 const DeclarationNameInfo &MemberNameInfo,
1817 ValueDecl *Member,
1818 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001819 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001820 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001821 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1822 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001823 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001824 // We have a reference to an unnamed field. This is always the
1825 // base of an anonymous struct/union member access, i.e. the
1826 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001827 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001828 assert(Member->getType()->isRecordType() &&
1829 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001830
Richard Smithcab9a7d2011-10-26 19:06:56 +00001831 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001832 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001833 QualifierLoc.getNestedNameSpecifier(),
1834 FoundDecl, Member);
1835 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001836 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001837 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001838 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001839 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001840 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001841 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001842 cast<FieldDecl>(Member)->getType(),
1843 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001844 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001845 }
Mike Stump11289f42009-09-09 15:08:12 +00001846
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001847 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001848 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001849
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001850 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001851 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001852
John McCall16df1e52010-03-30 21:47:33 +00001853 // FIXME: this involves duplicating earlier analysis in a lot of
1854 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001855 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001856 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001857 R.resolveKind();
1858
John McCallb268a282010-08-23 23:25:46 +00001859 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001860 SS, TemplateKWLoc,
1861 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001862 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 }
Mike Stump11289f42009-09-09 15:08:12 +00001864
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001866 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001870 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001871 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001872 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 }
1874
1875 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001876 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001880 SourceLocation QuestionLoc,
1881 Expr *LHS,
1882 SourceLocation ColonLoc,
1883 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001884 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1885 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
1887
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001889 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001893 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001896 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001897 SubExpr);
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 compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001901 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001904 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001905 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001907 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001908 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001909 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 }
Mike Stump11289f42009-09-09 15:08:12 +00001911
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001916 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 SourceLocation OpLoc,
1918 SourceLocation AccessorLoc,
1919 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001920
John McCall10eae182009-11-30 22:42:35 +00001921 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001922 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001923 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001924 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001925 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001926 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001927 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001928 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 }
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001932 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001935 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001936 MultiExprArg Inits,
1937 SourceLocation RBraceLoc,
1938 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001940 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001941 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001942 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001943
Douglas Gregord3d93062009-11-09 17:16:50 +00001944 // Patch in the result type we were given, which may have been computed
1945 // when the initial InitListExpr was built.
1946 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1947 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001948 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 }
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001952 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001955 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 MultiExprArg ArrayExprs,
1957 SourceLocation EqualOrColonLoc,
1958 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001959 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001960 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001962 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001965
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001966 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 }
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001970 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// By default, builds the implicit value initialization without performing
1972 /// any semantic analysis. Subclasses may override this routine to provide
1973 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001975 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001984 SourceLocation RParenLoc) {
1985 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001986 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001987 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 }
1989
1990 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001991 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001994 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001995 MultiExprArg SubExprs,
1996 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001997 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002001 ///
2002 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 /// rather than attempting to map the label statement itself.
2004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002005 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002006 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002007 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002017 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// \brief Build a new __builtin_choose_expr expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002024 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 SourceLocation RParenLoc) {
2027 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002028 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 RParenLoc);
2030 }
Mike Stump11289f42009-09-09 15:08:12 +00002031
Peter Collingbourne91147592011-04-15 00:35:48 +00002032 /// \brief Build a new generic selection expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
2036 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2037 SourceLocation DefaultLoc,
2038 SourceLocation RParenLoc,
2039 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002040 ArrayRef<TypeSourceInfo *> Types,
2041 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002042 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002043 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002044 }
2045
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 /// \brief Build a new overloaded operator call expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// The semantic analysis provides the behavior of template instantiation,
2050 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002051 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// argument-dependent lookup, etc. Subclasses may override this routine to
2053 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002056 Expr *Callee,
2057 Expr *First,
2058 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002059
2060 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// reinterpret_cast.
2062 ///
2063 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002064 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002066 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 Stmt::StmtClass Class,
2068 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002069 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation RAngleLoc,
2071 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002072 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 SourceLocation RParenLoc) {
2074 switch (Class) {
2075 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002076 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002077 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002078 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002079
2080 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002081 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002082 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002083 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002084
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002086 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002087 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002088 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002090
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002092 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002093 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002094 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002097 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 }
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// \brief Build a new C++ static_cast expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002107 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 SourceLocation RAngleLoc,
2109 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002112 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002113 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002114 SourceRange(LAngleLoc, RAngleLoc),
2115 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 }
2117
2118 /// \brief Build a new C++ dynamic_cast expression.
2119 ///
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002122 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002124 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 SourceLocation RAngleLoc,
2126 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002127 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002129 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002130 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002131 SourceRange(LAngleLoc, RAngleLoc),
2132 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 }
2134
2135 /// \brief Build a new C++ reinterpret_cast expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002139 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002141 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 SourceLocation RAngleLoc,
2143 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002144 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002146 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002147 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002148 SourceRange(LAngleLoc, RAngleLoc),
2149 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
2151
2152 /// \brief Build a new C++ const_cast expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002158 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RAngleLoc,
2160 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002161 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002163 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002164 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002165 SourceRange(LAngleLoc, RAngleLoc),
2166 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 /// \brief Build a new C++ functional-style cast expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002173 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2174 SourceLocation LParenLoc,
2175 Expr *Sub,
2176 SourceLocation RParenLoc) {
2177 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002178 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 RParenLoc);
2180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// \brief Build a new C++ typeid(type) expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002186 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002187 SourceLocation TypeidLoc,
2188 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002190 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002191 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 }
Mike Stump11289f42009-09-09 15:08:12 +00002193
Francois Pichet9f4f2072010-09-08 12:20:18 +00002194
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 /// \brief Build a new C++ typeid(expr) expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002200 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002201 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002203 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002204 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002205 }
2206
Francois Pichet9f4f2072010-09-08 12:20:18 +00002207 /// \brief Build a new C++ __uuidof(type) expression.
2208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
2211 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2212 SourceLocation TypeidLoc,
2213 TypeSourceInfo *Operand,
2214 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002215 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002216 RParenLoc);
2217 }
2218
2219 /// \brief Build a new C++ __uuidof(expr) expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
2223 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2224 SourceLocation TypeidLoc,
2225 Expr *Operand,
2226 SourceLocation RParenLoc) {
2227 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2228 RParenLoc);
2229 }
2230
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 /// \brief Build a new C++ "this" expression.
2232 ///
2233 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002234 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002236 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002237 QualType ThisType,
2238 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002239 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002240 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 }
2242
2243 /// \brief Build a new C++ throw expression.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002247 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2248 bool IsThrownVariableInScope) {
2249 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
2251
2252 /// \brief Build a new C++ default-argument expression.
2253 ///
2254 /// By default, builds a new default-argument expression, which does not
2255 /// require any semantic analysis. Subclasses may override this routine to
2256 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002257 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002258 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002259 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 }
2261
Richard Smith852c9db2013-04-20 22:23:05 +00002262 /// \brief Build a new C++11 default-initialization expression.
2263 ///
2264 /// By default, builds a new default field initialization expression, which
2265 /// does not require any semantic analysis. Subclasses may override this
2266 /// routine to provide different behavior.
2267 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2268 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002269 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002270 }
2271
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// \brief Build a new C++ zero-initialization expression.
2273 ///
2274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002276 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2277 SourceLocation LParenLoc,
2278 SourceLocation RParenLoc) {
2279 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002280 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 }
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// \brief Build a new C++ "new" expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002288 bool UseGlobal,
2289 SourceLocation PlacementLParen,
2290 MultiExprArg PlacementArgs,
2291 SourceLocation PlacementRParen,
2292 SourceRange TypeIdParens,
2293 QualType AllocatedType,
2294 TypeSourceInfo *AllocatedTypeInfo,
2295 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002296 SourceRange DirectInitRange,
2297 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002298 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002300 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002302 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002303 AllocatedType,
2304 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002305 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002306 DirectInitRange,
2307 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new C++ "delete" expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 bool IsGlobalDelete,
2316 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002317 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002319 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 }
Mike Stump11289f42009-09-09 15:08:12 +00002321
Douglas Gregor29c42f22012-02-24 07:38:34 +00002322 /// \brief Build a new type trait expression.
2323 ///
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
2326 ExprResult RebuildTypeTrait(TypeTrait Trait,
2327 SourceLocation StartLoc,
2328 ArrayRef<TypeSourceInfo *> Args,
2329 SourceLocation RParenLoc) {
2330 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002332
John Wiegley6242b6a2011-04-28 00:16:57 +00002333 /// \brief Build a new array type trait expression.
2334 ///
2335 /// By default, performs semantic analysis to build the new expression.
2336 /// Subclasses may override this routine to provide different behavior.
2337 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2338 SourceLocation StartLoc,
2339 TypeSourceInfo *TSInfo,
2340 Expr *DimExpr,
2341 SourceLocation RParenLoc) {
2342 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2343 }
2344
John Wiegleyf9f65842011-04-25 06:54:41 +00002345 /// \brief Build a new expression trait expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
2349 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2350 SourceLocation StartLoc,
2351 Expr *Queried,
2352 SourceLocation RParenLoc) {
2353 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2354 }
2355
Mike Stump11289f42009-09-09 15:08:12 +00002356 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 /// expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002361 ExprResult RebuildDependentScopeDeclRefExpr(
2362 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002363 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002364 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002365 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002366 bool IsAddressOfOperand,
2367 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002369 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002370
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002371 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002372 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2373 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002374
Reid Kleckner32506ed2014-06-12 23:03:48 +00002375 return getSema().BuildQualifiedDeclarationNameExpr(
2376 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 }
2378
2379 /// \brief Build a new template-id expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002383 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002384 SourceLocation TemplateKWLoc,
2385 LookupResult &R,
2386 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002387 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002388 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2389 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
2391
2392 /// \brief Build a new object-construction expression.
2393 ///
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002396 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002397 SourceLocation Loc,
2398 CXXConstructorDecl *Constructor,
2399 bool IsElidable,
2400 MultiExprArg Args,
2401 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002402 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002403 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002404 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002405 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002406 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002407 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002408 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002409 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002410 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002411
Douglas Gregordb121ba2009-12-14 16:27:04 +00002412 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002413 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002414 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002415 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002416 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002417 RequiresZeroInit, ConstructKind,
2418 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 }
2420
2421 /// \brief Build a new object-construction expression.
2422 ///
2423 /// By default, performs semantic analysis to build the new expression.
2424 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002425 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2426 SourceLocation LParenLoc,
2427 MultiExprArg Args,
2428 SourceLocation RParenLoc) {
2429 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002431 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 RParenLoc);
2433 }
2434
2435 /// \brief Build a new object-construction expression.
2436 ///
2437 /// By default, performs semantic analysis to build the new expression.
2438 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002439 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2440 SourceLocation LParenLoc,
2441 MultiExprArg Args,
2442 SourceLocation RParenLoc) {
2443 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002445 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 RParenLoc);
2447 }
Mike Stump11289f42009-09-09 15:08:12 +00002448
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 /// \brief Build a new member reference expression.
2450 ///
2451 /// By default, performs semantic analysis to build the new expression.
2452 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002453 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002454 QualType BaseType,
2455 bool IsArrow,
2456 SourceLocation OperatorLoc,
2457 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002458 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002459 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002460 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002461 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002462 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002463 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002464
John McCallb268a282010-08-23 23:25:46 +00002465 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002466 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002467 SS, TemplateKWLoc,
2468 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002469 MemberNameInfo,
2470 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 }
2472
John McCall10eae182009-11-30 22:42:35 +00002473 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002474 ///
2475 /// By default, performs semantic analysis to build the new expression.
2476 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002477 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2478 SourceLocation OperatorLoc,
2479 bool IsArrow,
2480 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002481 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002482 NamedDecl *FirstQualifierInScope,
2483 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002484 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002485 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002486 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002487
John McCallb268a282010-08-23 23:25:46 +00002488 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002489 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002490 SS, TemplateKWLoc,
2491 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002492 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002493 }
Mike Stump11289f42009-09-09 15:08:12 +00002494
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002495 /// \brief Build a new noexcept expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
2499 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2500 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2501 }
2502
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002503 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002504 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2505 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002506 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002507 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002508 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002509 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2510 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002511 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002512
2513 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2514 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002515 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002516 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002517
Patrick Beard0caa3942012-04-19 00:25:12 +00002518 /// \brief Build a new Objective-C boxed expression.
2519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
2522 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2523 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002525
Ted Kremeneke65b0862012-03-06 20:05:56 +00002526 /// \brief Build a new Objective-C array literal.
2527 ///
2528 /// By default, performs semantic analysis to build the new expression.
2529 /// Subclasses may override this routine to provide different behavior.
2530 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2531 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002532 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002533 MultiExprArg(Elements, NumElements));
2534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002535
2536 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002537 Expr *Base, Expr *Key,
2538 ObjCMethodDecl *getterMethod,
2539 ObjCMethodDecl *setterMethod) {
2540 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2541 getterMethod, setterMethod);
2542 }
2543
2544 /// \brief Build a new Objective-C dictionary literal.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2549 ObjCDictionaryElement *Elements,
2550 unsigned NumElements) {
2551 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002553
James Dennett2a4d13c2012-06-15 07:13:21 +00002554 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 ///
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002558 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002559 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002560 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002561 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002562 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002563
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002564 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002565 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002566 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002567 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002568 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002569 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002570 MultiExprArg Args,
2571 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002572 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2573 ReceiverTypeInfo->getType(),
2574 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002575 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002576 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002577 }
2578
2579 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002580 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002581 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002582 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002583 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002584 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002585 MultiExprArg Args,
2586 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002587 return SemaRef.BuildInstanceMessage(Receiver,
2588 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002589 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002590 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002591 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002592 }
2593
Douglas Gregord51d90d2010-04-26 20:11:03 +00002594 /// \brief Build a new Objective-C ivar reference expression.
2595 ///
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002598 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002599 SourceLocation IvarLoc,
2600 bool IsArrow, bool IsFreeIvar) {
2601 // FIXME: We lose track of the IsFreeIvar bit.
2602 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002603 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2604 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002605 /*FIXME:*/IvarLoc, IsArrow,
2606 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002607 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002608 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002609 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002610 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002611
2612 /// \brief Build a new Objective-C property reference expression.
2613 ///
2614 /// By default, performs semantic analysis to build the new expression.
2615 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002616 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002617 ObjCPropertyDecl *Property,
2618 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002619 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002620 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2621 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2622 /*FIXME:*/PropertyLoc,
2623 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002624 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002625 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002626 NameInfo,
2627 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002629
John McCallb7bd14f2010-12-02 01:19:52 +00002630 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002631 ///
2632 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002633 /// Subclasses may override this routine to provide different behavior.
2634 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2635 ObjCMethodDecl *Getter,
2636 ObjCMethodDecl *Setter,
2637 SourceLocation PropertyLoc) {
2638 // Since these expressions can only be value-dependent, we do not
2639 // need to perform semantic analysis again.
2640 return Owned(
2641 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2642 VK_LValue, OK_ObjCProperty,
2643 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002644 }
2645
Douglas Gregord51d90d2010-04-26 20:11:03 +00002646 /// \brief Build a new Objective-C "isa" expression.
2647 ///
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002650 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002651 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002652 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002653 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2654 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002655 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002656 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002657 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002658 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002659 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002661
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 /// \brief Build a new shuffle vector expression.
2663 ///
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002666 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002667 MultiExprArg SubExprs,
2668 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002670 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2672 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2673 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002674 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002675
Douglas Gregora16548e2009-08-11 05:31:07 +00002676 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002677 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002678 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2679 SemaRef.Context.BuiltinFnTy,
2680 VK_RValue, BuiltinLoc);
2681 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2682 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002683 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002684
2685 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002686 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002687 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002688 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002689
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002691 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002692 }
John McCall31f82722010-11-12 08:19:04 +00002693
Hal Finkelc4d7c822013-09-18 03:29:45 +00002694 /// \brief Build a new convert vector expression.
2695 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2696 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2697 SourceLocation RParenLoc) {
2698 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2699 BuiltinLoc, RParenLoc);
2700 }
2701
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002702 /// \brief Build a new template argument pack expansion.
2703 ///
2704 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002705 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002706 /// different behavior.
2707 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002708 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002709 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002710 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002711 case TemplateArgument::Expression: {
2712 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002713 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2714 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002715 if (Result.isInvalid())
2716 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002717
Douglas Gregor98318c22011-01-03 21:37:45 +00002718 return TemplateArgumentLoc(Result.get(), Result.get());
2719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002720
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002721 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002722 return TemplateArgumentLoc(TemplateArgument(
2723 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002724 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002725 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002726 Pattern.getTemplateNameLoc(),
2727 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002728
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002729 case TemplateArgument::Null:
2730 case TemplateArgument::Integral:
2731 case TemplateArgument::Declaration:
2732 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002733 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002734 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002735 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002736
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002737 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002738 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002739 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002740 EllipsisLoc,
2741 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002742 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2743 Expansion);
2744 break;
2745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002746
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002747 return TemplateArgumentLoc();
2748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002749
Douglas Gregor968f23a2011-01-03 19:31:53 +00002750 /// \brief Build a new expression pack expansion.
2751 ///
2752 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002753 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002754 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002755 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002756 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002757 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002758 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002759
2760 /// \brief Build a new atomic operation expression.
2761 ///
2762 /// By default, performs semantic analysis to build the new expression.
2763 /// Subclasses may override this routine to provide different behavior.
2764 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2765 MultiExprArg SubExprs,
2766 QualType RetTy,
2767 AtomicExpr::AtomicOp Op,
2768 SourceLocation RParenLoc) {
2769 // Just create the expression; there is not any interesting semantic
2770 // analysis here because we can't actually build an AtomicExpr until
2771 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002772 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002773 RParenLoc);
2774 }
2775
John McCall31f82722010-11-12 08:19:04 +00002776private:
Douglas Gregor14454802011-02-25 02:25:35 +00002777 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2778 QualType ObjectType,
2779 NamedDecl *FirstQualifierInScope,
2780 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002781
2782 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2783 QualType ObjectType,
2784 NamedDecl *FirstQualifierInScope,
2785 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002786
2787 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2788 NamedDecl *FirstQualifierInScope,
2789 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002790};
Douglas Gregora16548e2009-08-11 05:31:07 +00002791
Douglas Gregorebe10102009-08-20 07:17:43 +00002792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002793StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002794 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002795 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002796
Douglas Gregorebe10102009-08-20 07:17:43 +00002797 switch (S->getStmtClass()) {
2798 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002799
Douglas Gregorebe10102009-08-20 07:17:43 +00002800 // Transform individual statement nodes
2801#define STMT(Node, Parent) \
2802 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002803#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002804#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002805#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002806
Douglas Gregorebe10102009-08-20 07:17:43 +00002807 // Transform expressions by calling TransformExpr.
2808#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002809#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002810#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002811#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002812 {
John McCalldadc5752010-08-24 06:29:42 +00002813 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002814 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002815 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002816
Richard Smith945f8d32013-01-14 22:39:08 +00002817 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002818 }
Mike Stump11289f42009-09-09 15:08:12 +00002819 }
2820
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002821 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002822}
Mike Stump11289f42009-09-09 15:08:12 +00002823
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002824template<typename Derived>
2825OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2826 if (!S)
2827 return S;
2828
2829 switch (S->getClauseKind()) {
2830 default: break;
2831 // Transform individual clause nodes
2832#define OPENMP_CLAUSE(Name, Class) \
2833 case OMPC_ ## Name : \
2834 return getDerived().Transform ## Class(cast<Class>(S));
2835#include "clang/Basic/OpenMPKinds.def"
2836 }
2837
2838 return S;
2839}
2840
Mike Stump11289f42009-09-09 15:08:12 +00002841
Douglas Gregore922c772009-08-04 22:27:00 +00002842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002843ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002844 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002845 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002846
2847 switch (E->getStmtClass()) {
2848 case Stmt::NoStmtClass: break;
2849#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002850#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002851#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002852 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002853#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002854 }
2855
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002856 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002857}
2858
2859template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002860ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002861 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002862 // Initializers are instantiated like expressions, except that various outer
2863 // layers are stripped.
2864 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002865 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002866
2867 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2868 Init = ExprTemp->getSubExpr();
2869
Richard Smithe6ca4752013-05-30 22:40:16 +00002870 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2871 Init = MTE->GetTemporaryExpr();
2872
Richard Smithd59b8322012-12-19 01:39:02 +00002873 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2874 Init = Binder->getSubExpr();
2875
2876 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2877 Init = ICE->getSubExprAsWritten();
2878
Richard Smithcc1b96d2013-06-12 22:31:48 +00002879 if (CXXStdInitializerListExpr *ILE =
2880 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002881 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002882
Richard Smithc6abd962014-07-25 01:12:44 +00002883 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002884 // InitListExprs. Other forms of copy-initialization will be a no-op if
2885 // the initializer is already the right type.
2886 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002887 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002888 return getDerived().TransformExpr(Init);
2889
2890 // Revert value-initialization back to empty parens.
2891 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2892 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002893 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002894 Parens.getEnd());
2895 }
2896
2897 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2898 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002899 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002900 SourceLocation());
2901
2902 // Revert initialization by constructor back to a parenthesized or braced list
2903 // of expressions. Any other form of initializer can just be reused directly.
2904 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002905 return getDerived().TransformExpr(Init);
2906
Richard Smithf8adcdc2014-07-17 05:12:35 +00002907 // If the initialization implicitly converted an initializer list to a
2908 // std::initializer_list object, unwrap the std::initializer_list too.
2909 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002910 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002911
Richard Smithd59b8322012-12-19 01:39:02 +00002912 SmallVector<Expr*, 8> NewArgs;
2913 bool ArgChanged = false;
2914 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002915 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002916 return ExprError();
2917
2918 // If this was list initialization, revert to list form.
2919 if (Construct->isListInitialization())
2920 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2921 Construct->getLocEnd(),
2922 Construct->getType());
2923
Richard Smithd59b8322012-12-19 01:39:02 +00002924 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002925 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002926 if (Parens.isInvalid()) {
2927 // This was a variable declaration's initialization for which no initializer
2928 // was specified.
2929 assert(NewArgs.empty() &&
2930 "no parens or braces but have direct init with arguments?");
2931 return ExprEmpty();
2932 }
Richard Smithd59b8322012-12-19 01:39:02 +00002933 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2934 Parens.getEnd());
2935}
2936
2937template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002938bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2939 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002940 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002941 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002942 bool *ArgChanged) {
2943 for (unsigned I = 0; I != NumInputs; ++I) {
2944 // If requested, drop call arguments that need to be dropped.
2945 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2946 if (ArgChanged)
2947 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregora3efea12011-01-03 19:04:46 +00002949 break;
2950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002951
Douglas Gregor968f23a2011-01-03 19:31:53 +00002952 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2953 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Chris Lattner01cf8db2011-07-20 06:58:45 +00002955 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002956 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2957 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregor968f23a2011-01-03 19:31:53 +00002959 // Determine whether the set of unexpanded parameter packs can and should
2960 // be expanded.
2961 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002962 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002963 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2964 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002965 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2966 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002967 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002968 Expand, RetainExpansion,
2969 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002970 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor968f23a2011-01-03 19:31:53 +00002972 if (!Expand) {
2973 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002974 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002975 // expansion.
2976 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2977 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2978 if (OutPattern.isInvalid())
2979 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002980
2981 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002982 Expansion->getEllipsisLoc(),
2983 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002984 if (Out.isInvalid())
2985 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002986
Douglas Gregor968f23a2011-01-03 19:31:53 +00002987 if (ArgChanged)
2988 *ArgChanged = true;
2989 Outputs.push_back(Out.get());
2990 continue;
2991 }
John McCall542e7c62011-07-06 07:30:07 +00002992
2993 // Record right away that the argument was changed. This needs
2994 // to happen even if the array expands to nothing.
2995 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002996
Douglas Gregor968f23a2011-01-03 19:31:53 +00002997 // The transform has determined that we should perform an elementwise
2998 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002999 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003000 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3001 ExprResult Out = getDerived().TransformExpr(Pattern);
3002 if (Out.isInvalid())
3003 return true;
3004
Richard Smith9467be42014-06-06 17:33:35 +00003005 // FIXME: Can this happen? We should not try to expand the pack
3006 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003007 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003008 Out = getDerived().RebuildPackExpansion(
3009 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003010 if (Out.isInvalid())
3011 return true;
3012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor968f23a2011-01-03 19:31:53 +00003014 Outputs.push_back(Out.get());
3015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003016
Richard Smith9467be42014-06-06 17:33:35 +00003017 // If we're supposed to retain a pack expansion, do so by temporarily
3018 // forgetting the partially-substituted parameter pack.
3019 if (RetainExpansion) {
3020 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3021
3022 ExprResult Out = getDerived().TransformExpr(Pattern);
3023 if (Out.isInvalid())
3024 return true;
3025
3026 Out = getDerived().RebuildPackExpansion(
3027 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3028 if (Out.isInvalid())
3029 return true;
3030
3031 Outputs.push_back(Out.get());
3032 }
3033
Douglas Gregor968f23a2011-01-03 19:31:53 +00003034 continue;
3035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003036
Richard Smithd59b8322012-12-19 01:39:02 +00003037 ExprResult Result =
3038 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3039 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003040 if (Result.isInvalid())
3041 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Douglas Gregora3efea12011-01-03 19:04:46 +00003043 if (Result.get() != Inputs[I] && ArgChanged)
3044 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
3046 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregora3efea12011-01-03 19:04:46 +00003049 return false;
3050}
3051
3052template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003053NestedNameSpecifierLoc
3054TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3055 NestedNameSpecifierLoc NNS,
3056 QualType ObjectType,
3057 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003058 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003059 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003060 Qualifier = Qualifier.getPrefix())
3061 Qualifiers.push_back(Qualifier);
3062
3063 CXXScopeSpec SS;
3064 while (!Qualifiers.empty()) {
3065 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3066 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
Douglas Gregor14454802011-02-25 02:25:35 +00003068 switch (QNNS->getKind()) {
3069 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003070 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003071 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003072 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003073 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003074 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003075 FirstQualifierInScope, false))
3076 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor14454802011-02-25 02:25:35 +00003078 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003079
Douglas Gregor14454802011-02-25 02:25:35 +00003080 case NestedNameSpecifier::Namespace: {
3081 NamespaceDecl *NS
3082 = cast_or_null<NamespaceDecl>(
3083 getDerived().TransformDecl(
3084 Q.getLocalBeginLoc(),
3085 QNNS->getAsNamespace()));
3086 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3087 break;
3088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003089
Douglas Gregor14454802011-02-25 02:25:35 +00003090 case NestedNameSpecifier::NamespaceAlias: {
3091 NamespaceAliasDecl *Alias
3092 = cast_or_null<NamespaceAliasDecl>(
3093 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3094 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003095 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003096 Q.getLocalEndLoc());
3097 break;
3098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003099
Douglas Gregor14454802011-02-25 02:25:35 +00003100 case NestedNameSpecifier::Global:
3101 // There is no meaningful transformation that one could perform on the
3102 // global scope.
3103 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3104 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor14454802011-02-25 02:25:35 +00003106 case NestedNameSpecifier::TypeSpecWithTemplate:
3107 case NestedNameSpecifier::TypeSpec: {
3108 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3109 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Douglas Gregor14454802011-02-25 02:25:35 +00003111 if (!TL)
3112 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003113
Douglas Gregor14454802011-02-25 02:25:35 +00003114 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003115 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003116 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003117 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003118 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003119 if (TL.getType()->isEnumeralType())
3120 SemaRef.Diag(TL.getBeginLoc(),
3121 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003122 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3123 Q.getLocalEndLoc());
3124 break;
3125 }
Richard Trieude756fb2011-05-07 01:36:37 +00003126 // If the nested-name-specifier is an invalid type def, don't emit an
3127 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003128 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3129 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003130 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003131 << TL.getType() << SS.getRange();
3132 }
Douglas Gregor14454802011-02-25 02:25:35 +00003133 return NestedNameSpecifierLoc();
3134 }
Douglas Gregore16af532011-02-28 18:50:33 +00003135 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregore16af532011-02-28 18:50:33 +00003137 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003138 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003139 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003140 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003141
Douglas Gregor14454802011-02-25 02:25:35 +00003142 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003143 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003144 !getDerived().AlwaysRebuild())
3145 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
3147 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003148 // nested-name-specifier, do so.
3149 if (SS.location_size() == NNS.getDataLength() &&
3150 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3151 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3152
3153 // Allocate new nested-name-specifier location information.
3154 return SS.getWithLocInContext(SemaRef.Context);
3155}
3156
3157template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003158DeclarationNameInfo
3159TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003160::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003161 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003162 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003163 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003164
3165 switch (Name.getNameKind()) {
3166 case DeclarationName::Identifier:
3167 case DeclarationName::ObjCZeroArgSelector:
3168 case DeclarationName::ObjCOneArgSelector:
3169 case DeclarationName::ObjCMultiArgSelector:
3170 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003171 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003172 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003173 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003174
Douglas Gregorf816bd72009-09-03 22:13:48 +00003175 case DeclarationName::CXXConstructorName:
3176 case DeclarationName::CXXDestructorName:
3177 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003178 TypeSourceInfo *NewTInfo;
3179 CanQualType NewCanTy;
3180 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003181 NewTInfo = getDerived().TransformType(OldTInfo);
3182 if (!NewTInfo)
3183 return DeclarationNameInfo();
3184 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003185 }
3186 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003187 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003188 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003189 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003190 if (NewT.isNull())
3191 return DeclarationNameInfo();
3192 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3193 }
Mike Stump11289f42009-09-09 15:08:12 +00003194
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003195 DeclarationName NewName
3196 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3197 NewCanTy);
3198 DeclarationNameInfo NewNameInfo(NameInfo);
3199 NewNameInfo.setName(NewName);
3200 NewNameInfo.setNamedTypeInfo(NewTInfo);
3201 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003202 }
Mike Stump11289f42009-09-09 15:08:12 +00003203 }
3204
David Blaikie83d382b2011-09-23 05:06:16 +00003205 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003206}
3207
3208template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003209TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003210TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3211 TemplateName Name,
3212 SourceLocation NameLoc,
3213 QualType ObjectType,
3214 NamedDecl *FirstQualifierInScope) {
3215 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3216 TemplateDecl *Template = QTN->getTemplateDecl();
3217 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003218
Douglas Gregor9db53502011-03-02 18:07:45 +00003219 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003220 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003221 Template));
3222 if (!TransTemplate)
3223 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003224
Douglas Gregor9db53502011-03-02 18:07:45 +00003225 if (!getDerived().AlwaysRebuild() &&
3226 SS.getScopeRep() == QTN->getQualifier() &&
3227 TransTemplate == Template)
3228 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor9db53502011-03-02 18:07:45 +00003230 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3231 TransTemplate);
3232 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003233
Douglas Gregor9db53502011-03-02 18:07:45 +00003234 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3235 if (SS.getScopeRep()) {
3236 // These apply to the scope specifier, not the template.
3237 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003238 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003239 }
3240
Douglas Gregor9db53502011-03-02 18:07:45 +00003241 if (!getDerived().AlwaysRebuild() &&
3242 SS.getScopeRep() == DTN->getQualifier() &&
3243 ObjectType.isNull())
3244 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003245
Douglas Gregor9db53502011-03-02 18:07:45 +00003246 if (DTN->isIdentifier()) {
3247 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003248 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003249 NameLoc,
3250 ObjectType,
3251 FirstQualifierInScope);
3252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregor9db53502011-03-02 18:07:45 +00003254 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3255 ObjectType);
3256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003257
Douglas Gregor9db53502011-03-02 18:07:45 +00003258 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3259 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003260 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003261 Template));
3262 if (!TransTemplate)
3263 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregor9db53502011-03-02 18:07:45 +00003265 if (!getDerived().AlwaysRebuild() &&
3266 TransTemplate == Template)
3267 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregor9db53502011-03-02 18:07:45 +00003269 return TemplateName(TransTemplate);
3270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregor9db53502011-03-02 18:07:45 +00003272 if (SubstTemplateTemplateParmPackStorage *SubstPack
3273 = Name.getAsSubstTemplateTemplateParmPack()) {
3274 TemplateTemplateParmDecl *TransParam
3275 = cast_or_null<TemplateTemplateParmDecl>(
3276 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3277 if (!TransParam)
3278 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregor9db53502011-03-02 18:07:45 +00003280 if (!getDerived().AlwaysRebuild() &&
3281 TransParam == SubstPack->getParameterPack())
3282 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
3284 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003285 SubstPack->getArgumentPack());
3286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003287
Douglas Gregor9db53502011-03-02 18:07:45 +00003288 // These should be getting filtered out before they reach the AST.
3289 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003290}
3291
3292template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003293void TreeTransform<Derived>::InventTemplateArgumentLoc(
3294 const TemplateArgument &Arg,
3295 TemplateArgumentLoc &Output) {
3296 SourceLocation Loc = getDerived().getBaseLocation();
3297 switch (Arg.getKind()) {
3298 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003299 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003300 break;
3301
3302 case TemplateArgument::Type:
3303 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003304 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
John McCall0ad16662009-10-29 08:12:44 +00003306 break;
3307
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003308 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003309 case TemplateArgument::TemplateExpansion: {
3310 NestedNameSpecifierLocBuilder Builder;
3311 TemplateName Template = Arg.getAsTemplate();
3312 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3313 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3314 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3315 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregor9d802122011-03-02 17:09:35 +00003317 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003318 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003319 Builder.getWithLocInContext(SemaRef.Context),
3320 Loc);
3321 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003322 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003323 Builder.getWithLocInContext(SemaRef.Context),
3324 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003325
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003326 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003327 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003328
John McCall0ad16662009-10-29 08:12:44 +00003329 case TemplateArgument::Expression:
3330 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3331 break;
3332
3333 case TemplateArgument::Declaration:
3334 case TemplateArgument::Integral:
3335 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003336 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003337 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003338 break;
3339 }
3340}
3341
3342template<typename Derived>
3343bool TreeTransform<Derived>::TransformTemplateArgument(
3344 const TemplateArgumentLoc &Input,
3345 TemplateArgumentLoc &Output) {
3346 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003347 switch (Arg.getKind()) {
3348 case TemplateArgument::Null:
3349 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003350 case TemplateArgument::Pack:
3351 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003352 case TemplateArgument::NullPtr:
3353 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003354
Douglas Gregore922c772009-08-04 22:27:00 +00003355 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003356 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003357 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003358 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003359
3360 DI = getDerived().TransformType(DI);
3361 if (!DI) return true;
3362
3363 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3364 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003365 }
Mike Stump11289f42009-09-09 15:08:12 +00003366
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003367 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003368 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3369 if (QualifierLoc) {
3370 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3371 if (!QualifierLoc)
3372 return true;
3373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregordf846d12011-03-02 18:46:51 +00003375 CXXScopeSpec SS;
3376 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003377 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003378 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3379 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003380 if (Template.isNull())
3381 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregor9d802122011-03-02 17:09:35 +00003383 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003384 Input.getTemplateNameLoc());
3385 return false;
3386 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003387
3388 case TemplateArgument::TemplateExpansion:
3389 llvm_unreachable("Caller should expand pack expansions");
3390
Douglas Gregore922c772009-08-04 22:27:00 +00003391 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003392 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003393 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003394 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003395
John McCall0ad16662009-10-29 08:12:44 +00003396 Expr *InputExpr = Input.getSourceExpression();
3397 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3398
Chris Lattnercdb591a2011-04-25 20:37:58 +00003399 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003400 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003401 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003402 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003403 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003404 }
Douglas Gregore922c772009-08-04 22:27:00 +00003405 }
Mike Stump11289f42009-09-09 15:08:12 +00003406
Douglas Gregore922c772009-08-04 22:27:00 +00003407 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003408 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003409}
3410
Douglas Gregorfe921a72010-12-20 23:36:19 +00003411/// \brief Iterator adaptor that invents template argument location information
3412/// for each of the template arguments in its underlying iterator.
3413template<typename Derived, typename InputIterator>
3414class TemplateArgumentLocInventIterator {
3415 TreeTransform<Derived> &Self;
3416 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregorfe921a72010-12-20 23:36:19 +00003418public:
3419 typedef TemplateArgumentLoc value_type;
3420 typedef TemplateArgumentLoc reference;
3421 typedef typename std::iterator_traits<InputIterator>::difference_type
3422 difference_type;
3423 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregorfe921a72010-12-20 23:36:19 +00003425 class pointer {
3426 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregorfe921a72010-12-20 23:36:19 +00003428 public:
3429 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregorfe921a72010-12-20 23:36:19 +00003431 const TemplateArgumentLoc *operator->() const { return &Arg; }
3432 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregorfe921a72010-12-20 23:36:19 +00003434 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
Douglas Gregorfe921a72010-12-20 23:36:19 +00003436 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3437 InputIterator Iter)
3438 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregorfe921a72010-12-20 23:36:19 +00003440 TemplateArgumentLocInventIterator &operator++() {
3441 ++Iter;
3442 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003443 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 TemplateArgumentLocInventIterator operator++(int) {
3446 TemplateArgumentLocInventIterator Old(*this);
3447 ++(*this);
3448 return Old;
3449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregorfe921a72010-12-20 23:36:19 +00003451 reference operator*() const {
3452 TemplateArgumentLoc Result;
3453 Self.InventTemplateArgumentLoc(*Iter, Result);
3454 return Result;
3455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregorfe921a72010-12-20 23:36:19 +00003457 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003458
Douglas Gregorfe921a72010-12-20 23:36:19 +00003459 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3460 const TemplateArgumentLocInventIterator &Y) {
3461 return X.Iter == Y.Iter;
3462 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003463
Douglas Gregorfe921a72010-12-20 23:36:19 +00003464 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3465 const TemplateArgumentLocInventIterator &Y) {
3466 return X.Iter != Y.Iter;
3467 }
3468};
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor42cafa82010-12-20 17:42:22 +00003470template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003471template<typename InputIterator>
3472bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3473 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003474 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003475 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003476 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003477 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003478
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003479 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3480 // Unpack argument packs, which we translate them into separate
3481 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003482 // FIXME: We could do much better if we could guarantee that the
3483 // TemplateArgumentLocInfo for the pack expansion would be usable for
3484 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003485 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003486 TemplateArgument::pack_iterator>
3487 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003488 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003489 In.getArgument().pack_begin()),
3490 PackLocIterator(*this,
3491 In.getArgument().pack_end()),
3492 Outputs))
3493 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003495 continue;
3496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003498 if (In.getArgument().isPackExpansion()) {
3499 // We have a pack expansion, for which we will be substituting into
3500 // the pattern.
3501 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003502 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003503 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003504 = getSema().getTemplateArgumentPackExpansionPattern(
3505 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Chris Lattner01cf8db2011-07-20 06:58:45 +00003507 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003508 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3509 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003511 // Determine whether the set of unexpanded parameter packs can and should
3512 // be expanded.
3513 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003514 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003515 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003516 if (getDerived().TryExpandParameterPacks(Ellipsis,
3517 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003518 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003519 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003520 RetainExpansion,
3521 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003522 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003523
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003524 if (!Expand) {
3525 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003526 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003527 // expansion.
3528 TemplateArgumentLoc OutPattern;
3529 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3530 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3531 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003533 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3534 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003535 if (Out.getArgument().isNull())
3536 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003538 Outputs.addArgument(Out);
3539 continue;
3540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003541
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003542 // The transform has determined that we should perform an elementwise
3543 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003544 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3546
3547 if (getDerived().TransformTemplateArgument(Pattern, Out))
3548 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003550 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003551 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3552 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003553 if (Out.getArgument().isNull())
3554 return true;
3555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003556
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003557 Outputs.addArgument(Out);
3558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor48d24112011-01-10 20:53:55 +00003560 // If we're supposed to retain a pack expansion, do so by temporarily
3561 // forgetting the partially-substituted parameter pack.
3562 if (RetainExpansion) {
3563 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor48d24112011-01-10 20:53:55 +00003565 if (getDerived().TransformTemplateArgument(Pattern, Out))
3566 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003568 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3569 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003570 if (Out.getArgument().isNull())
3571 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor48d24112011-01-10 20:53:55 +00003573 Outputs.addArgument(Out);
3574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003576 continue;
3577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
3579 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003580 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003581 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003582
Douglas Gregor42cafa82010-12-20 17:42:22 +00003583 Outputs.addArgument(Out);
3584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregor42cafa82010-12-20 17:42:22 +00003586 return false;
3587
3588}
3589
Douglas Gregord6ff3322009-08-04 16:50:30 +00003590//===----------------------------------------------------------------------===//
3591// Type transformation
3592//===----------------------------------------------------------------------===//
3593
3594template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003595QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003596 if (getDerived().AlreadyTransformed(T))
3597 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003598
John McCall550e0c22009-10-21 00:40:46 +00003599 // Temporary workaround. All of these transformations should
3600 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003601 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3602 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
John McCall31f82722010-11-12 08:19:04 +00003604 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003605
John McCall550e0c22009-10-21 00:40:46 +00003606 if (!NewDI)
3607 return QualType();
3608
3609 return NewDI->getType();
3610}
3611
3612template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003613TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003614 // Refine the base location to the type's location.
3615 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3616 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003617 if (getDerived().AlreadyTransformed(DI->getType()))
3618 return DI;
3619
3620 TypeLocBuilder TLB;
3621
3622 TypeLoc TL = DI->getTypeLoc();
3623 TLB.reserve(TL.getFullDataSize());
3624
John McCall31f82722010-11-12 08:19:04 +00003625 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003626 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003627 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003628
John McCallbcd03502009-12-07 02:54:59 +00003629 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003630}
3631
3632template<typename Derived>
3633QualType
John McCall31f82722010-11-12 08:19:04 +00003634TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003635 switch (T.getTypeLocClass()) {
3636#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003637#define TYPELOC(CLASS, PARENT) \
3638 case TypeLoc::CLASS: \
3639 return getDerived().Transform##CLASS##Type(TLB, \
3640 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003641#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642 }
Mike Stump11289f42009-09-09 15:08:12 +00003643
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003644 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003645}
3646
3647/// FIXME: By default, this routine adds type qualifiers only to types
3648/// that can have qualifiers, and silently suppresses those qualifiers
3649/// that are not permitted (e.g., qualifiers on reference or function
3650/// types). This is the right thing for template instantiation, but
3651/// probably not for other clients.
3652template<typename Derived>
3653QualType
3654TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003655 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003656 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003657
John McCall31f82722010-11-12 08:19:04 +00003658 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003659 if (Result.isNull())
3660 return QualType();
3661
3662 // Silently suppress qualifiers if the result type can't be qualified.
3663 // FIXME: this is the right thing for template instantiation, but
3664 // probably not for other clients.
3665 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003666 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003667
John McCall31168b02011-06-15 23:02:42 +00003668 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003669 // resulting type.
3670 if (Quals.hasObjCLifetime()) {
3671 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3672 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003673 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003674 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003675 // A lifetime qualifier applied to a substituted template parameter
3676 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003677 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003678 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003679 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3680 QualType Replacement = SubstTypeParam->getReplacementType();
3681 Qualifiers Qs = Replacement.getQualifiers();
3682 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003683 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003684 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3685 Qs);
3686 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003687 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003688 Replacement);
3689 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003690 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3691 // 'auto' types behave the same way as template parameters.
3692 QualType Deduced = AutoTy->getDeducedType();
3693 Qualifiers Qs = Deduced.getQualifiers();
3694 Qs.removeObjCLifetime();
3695 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3696 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003697 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3698 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003699 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003700 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003701 // Otherwise, complain about the addition of a qualifier to an
3702 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003703 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003704 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003705 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
Douglas Gregore46db902011-06-17 22:11:49 +00003707 Quals.removeObjCLifetime();
3708 }
3709 }
3710 }
John McCallcb0f89a2010-06-05 06:41:15 +00003711 if (!Quals.empty()) {
3712 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003713 // BuildQualifiedType might not add qualifiers if they are invalid.
3714 if (Result.hasLocalQualifiers())
3715 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003716 // No location information to preserve.
3717 }
John McCall550e0c22009-10-21 00:40:46 +00003718
3719 return Result;
3720}
3721
Douglas Gregor14454802011-02-25 02:25:35 +00003722template<typename Derived>
3723TypeLoc
3724TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3725 QualType ObjectType,
3726 NamedDecl *UnqualLookup,
3727 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003728 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003729 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003731 TypeSourceInfo *TSI =
3732 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3733 if (TSI)
3734 return TSI->getTypeLoc();
3735 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003736}
3737
Douglas Gregor579c15f2011-03-02 18:32:08 +00003738template<typename Derived>
3739TypeSourceInfo *
3740TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3741 QualType ObjectType,
3742 NamedDecl *UnqualLookup,
3743 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003744 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003745 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003747 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3748 UnqualLookup, SS);
3749}
3750
3751template <typename Derived>
3752TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3753 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3754 CXXScopeSpec &SS) {
3755 QualType T = TL.getType();
3756 assert(!getDerived().AlreadyTransformed(T));
3757
Douglas Gregor579c15f2011-03-02 18:32:08 +00003758 TypeLocBuilder TLB;
3759 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Douglas Gregor579c15f2011-03-02 18:32:08 +00003761 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003762 TemplateSpecializationTypeLoc SpecTL =
3763 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor579c15f2011-03-02 18:32:08 +00003765 TemplateName Template
3766 = getDerived().TransformTemplateName(SS,
3767 SpecTL.getTypePtr()->getTemplateName(),
3768 SpecTL.getTemplateNameLoc(),
3769 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003770 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003771 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
3773 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003774 Template);
3775 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003776 DependentTemplateSpecializationTypeLoc SpecTL =
3777 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
Douglas Gregor579c15f2011-03-02 18:32:08 +00003779 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003780 = getDerived().RebuildTemplateName(SS,
3781 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003782 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003783 ObjectType, UnqualLookup);
3784 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003785 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
3787 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003788 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003789 Template,
3790 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003791 } else {
3792 // Nothing special needs to be done for these.
3793 Result = getDerived().TransformType(TLB, TL);
3794 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003795
3796 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003797 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregor579c15f2011-03-02 18:32:08 +00003799 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3800}
3801
John McCall550e0c22009-10-21 00:40:46 +00003802template <class TyLoc> static inline
3803QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3804 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3805 NewT.setNameLoc(T.getNameLoc());
3806 return T.getType();
3807}
3808
John McCall550e0c22009-10-21 00:40:46 +00003809template<typename Derived>
3810QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003811 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003812 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3813 NewT.setBuiltinLoc(T.getBuiltinLoc());
3814 if (T.needsExtraLocalData())
3815 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3816 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003817}
Mike Stump11289f42009-09-09 15:08:12 +00003818
Douglas Gregord6ff3322009-08-04 16:50:30 +00003819template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003820QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003821 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003822 // FIXME: recurse?
3823 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003824}
Mike Stump11289f42009-09-09 15:08:12 +00003825
Reid Kleckner0503a872013-12-05 01:23:43 +00003826template <typename Derived>
3827QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3828 AdjustedTypeLoc TL) {
3829 // Adjustments applied during transformation are handled elsewhere.
3830 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3831}
3832
Douglas Gregord6ff3322009-08-04 16:50:30 +00003833template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003834QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3835 DecayedTypeLoc TL) {
3836 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3837 if (OriginalType.isNull())
3838 return QualType();
3839
3840 QualType Result = TL.getType();
3841 if (getDerived().AlwaysRebuild() ||
3842 OriginalType != TL.getOriginalLoc().getType())
3843 Result = SemaRef.Context.getDecayedType(OriginalType);
3844 TLB.push<DecayedTypeLoc>(Result);
3845 // Nothing to set for DecayedTypeLoc.
3846 return Result;
3847}
3848
3849template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003850QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003851 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003852 QualType PointeeType
3853 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003854 if (PointeeType.isNull())
3855 return QualType();
3856
3857 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003858 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003859 // A dependent pointer type 'T *' has is being transformed such
3860 // that an Objective-C class type is being replaced for 'T'. The
3861 // resulting pointer type is an ObjCObjectPointerType, not a
3862 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003863 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
John McCall8b07ec22010-05-15 11:32:37 +00003865 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3866 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003867 return Result;
3868 }
John McCall31f82722010-11-12 08:19:04 +00003869
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003870 if (getDerived().AlwaysRebuild() ||
3871 PointeeType != TL.getPointeeLoc().getType()) {
3872 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3873 if (Result.isNull())
3874 return QualType();
3875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
John McCall31168b02011-06-15 23:02:42 +00003877 // Objective-C ARC can add lifetime qualifiers to the type that we're
3878 // pointing to.
3879 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003881 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3882 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003883 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003884}
Mike Stump11289f42009-09-09 15:08:12 +00003885
3886template<typename Derived>
3887QualType
John McCall550e0c22009-10-21 00:40:46 +00003888TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003889 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003890 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003891 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3892 if (PointeeType.isNull())
3893 return QualType();
3894
3895 QualType Result = TL.getType();
3896 if (getDerived().AlwaysRebuild() ||
3897 PointeeType != TL.getPointeeLoc().getType()) {
3898 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003899 TL.getSigilLoc());
3900 if (Result.isNull())
3901 return QualType();
3902 }
3903
Douglas Gregor049211a2010-04-22 16:50:51 +00003904 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003905 NewT.setSigilLoc(TL.getSigilLoc());
3906 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003907}
3908
John McCall70dd5f62009-10-30 00:06:24 +00003909/// Transforms a reference type. Note that somewhat paradoxically we
3910/// don't care whether the type itself is an l-value type or an r-value
3911/// type; we only care if the type was *written* as an l-value type
3912/// or an r-value type.
3913template<typename Derived>
3914QualType
3915TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003917 const ReferenceType *T = TL.getTypePtr();
3918
3919 // Note that this works with the pointee-as-written.
3920 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3921 if (PointeeType.isNull())
3922 return QualType();
3923
3924 QualType Result = TL.getType();
3925 if (getDerived().AlwaysRebuild() ||
3926 PointeeType != T->getPointeeTypeAsWritten()) {
3927 Result = getDerived().RebuildReferenceType(PointeeType,
3928 T->isSpelledAsLValue(),
3929 TL.getSigilLoc());
3930 if (Result.isNull())
3931 return QualType();
3932 }
3933
John McCall31168b02011-06-15 23:02:42 +00003934 // Objective-C ARC can add lifetime qualifiers to the type that we're
3935 // referring to.
3936 TLB.TypeWasModifiedSafely(
3937 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3938
John McCall70dd5f62009-10-30 00:06:24 +00003939 // r-value references can be rebuilt as l-value references.
3940 ReferenceTypeLoc NewTL;
3941 if (isa<LValueReferenceType>(Result))
3942 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3943 else
3944 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3945 NewTL.setSigilLoc(TL.getSigilLoc());
3946
3947 return Result;
3948}
3949
Mike Stump11289f42009-09-09 15:08:12 +00003950template<typename Derived>
3951QualType
John McCall550e0c22009-10-21 00:40:46 +00003952TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003953 LValueReferenceTypeLoc TL) {
3954 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955}
3956
Mike Stump11289f42009-09-09 15:08:12 +00003957template<typename Derived>
3958QualType
John McCall550e0c22009-10-21 00:40:46 +00003959TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003960 RValueReferenceTypeLoc TL) {
3961 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962}
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregord6ff3322009-08-04 16:50:30 +00003964template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003965QualType
John McCall550e0c22009-10-21 00:40:46 +00003966TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003967 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003968 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003969 if (PointeeType.isNull())
3970 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003971
Abramo Bagnara509357842011-03-05 14:42:21 +00003972 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003973 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003974 if (OldClsTInfo) {
3975 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3976 if (!NewClsTInfo)
3977 return QualType();
3978 }
3979
3980 const MemberPointerType *T = TL.getTypePtr();
3981 QualType OldClsType = QualType(T->getClass(), 0);
3982 QualType NewClsType;
3983 if (NewClsTInfo)
3984 NewClsType = NewClsTInfo->getType();
3985 else {
3986 NewClsType = getDerived().TransformType(OldClsType);
3987 if (NewClsType.isNull())
3988 return QualType();
3989 }
Mike Stump11289f42009-09-09 15:08:12 +00003990
John McCall550e0c22009-10-21 00:40:46 +00003991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003994 NewClsType != OldClsType) {
3995 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003996 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003997 if (Result.isNull())
3998 return QualType();
3999 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000
Reid Kleckner0503a872013-12-05 01:23:43 +00004001 // If we had to adjust the pointee type when building a member pointer, make
4002 // sure to push TypeLoc info for it.
4003 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4004 if (MPT && PointeeType != MPT->getPointeeType()) {
4005 assert(isa<AdjustedType>(MPT->getPointeeType()));
4006 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4007 }
4008
John McCall550e0c22009-10-21 00:40:46 +00004009 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4010 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004011 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004012
4013 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014}
4015
Mike Stump11289f42009-09-09 15:08:12 +00004016template<typename Derived>
4017QualType
John McCall550e0c22009-10-21 00:40:46 +00004018TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004019 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004020 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004021 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022 if (ElementType.isNull())
4023 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004024
John McCall550e0c22009-10-21 00:40:46 +00004025 QualType Result = TL.getType();
4026 if (getDerived().AlwaysRebuild() ||
4027 ElementType != T->getElementType()) {
4028 Result = getDerived().RebuildConstantArrayType(ElementType,
4029 T->getSizeModifier(),
4030 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004031 T->getIndexTypeCVRQualifiers(),
4032 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004033 if (Result.isNull())
4034 return QualType();
4035 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004036
4037 // We might have either a ConstantArrayType or a VariableArrayType now:
4038 // a ConstantArrayType is allowed to have an element type which is a
4039 // VariableArrayType if the type is dependent. Fortunately, all array
4040 // types have the same location layout.
4041 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004042 NewTL.setLBracketLoc(TL.getLBracketLoc());
4043 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004044
John McCall550e0c22009-10-21 00:40:46 +00004045 Expr *Size = TL.getSizeExpr();
4046 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004047 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4048 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004049 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4050 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004051 }
4052 NewTL.setSizeExpr(Size);
4053
4054 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055}
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004058QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004059 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004060 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004061 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004062 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063 if (ElementType.isNull())
4064 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004065
John McCall550e0c22009-10-21 00:40:46 +00004066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ElementType != T->getElementType()) {
4069 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004071 T->getIndexTypeCVRQualifiers(),
4072 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004073 if (Result.isNull())
4074 return QualType();
4075 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4078 NewTL.setLBracketLoc(TL.getLBracketLoc());
4079 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004080 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004081
4082 return Result;
4083}
4084
4085template<typename Derived>
4086QualType
4087TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004088 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004089 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004090 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4091 if (ElementType.isNull())
4092 return QualType();
4093
John McCalldadc5752010-08-24 06:29:42 +00004094 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004095 = getDerived().TransformExpr(T->getSizeExpr());
4096 if (SizeResult.isInvalid())
4097 return QualType();
4098
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004099 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004100
4101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
4103 ElementType != T->getElementType() ||
4104 Size != T->getSizeExpr()) {
4105 Result = getDerived().RebuildVariableArrayType(ElementType,
4106 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004107 Size,
John McCall550e0c22009-10-21 00:40:46 +00004108 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004109 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004110 if (Result.isNull())
4111 return QualType();
4112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Serge Pavlov774c6d02014-02-06 03:49:11 +00004114 // We might have constant size array now, but fortunately it has the same
4115 // location layout.
4116 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004117 NewTL.setLBracketLoc(TL.getLBracketLoc());
4118 NewTL.setRBracketLoc(TL.getRBracketLoc());
4119 NewTL.setSizeExpr(Size);
4120
4121 return Result;
4122}
4123
4124template<typename Derived>
4125QualType
4126TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004127 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004128 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4130 if (ElementType.isNull())
4131 return QualType();
4132
Richard Smith764d2fe2011-12-20 02:08:33 +00004133 // Array bounds are constant expressions.
4134 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4135 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004136
John McCall33ddac02011-01-19 10:06:00 +00004137 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4138 Expr *origSize = TL.getSizeExpr();
4139 if (!origSize) origSize = T->getSizeExpr();
4140
4141 ExprResult sizeResult
4142 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004143 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004144 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004145 return QualType();
4146
John McCall33ddac02011-01-19 10:06:00 +00004147 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004148
4149 QualType Result = TL.getType();
4150 if (getDerived().AlwaysRebuild() ||
4151 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004152 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004153 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4154 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004155 size,
John McCall550e0c22009-10-21 00:40:46 +00004156 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004157 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004158 if (Result.isNull())
4159 return QualType();
4160 }
John McCall550e0c22009-10-21 00:40:46 +00004161
4162 // We might have any sort of array type now, but fortunately they
4163 // all have the same location layout.
4164 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4165 NewTL.setLBracketLoc(TL.getLBracketLoc());
4166 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004167 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004168
4169 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004170}
Mike Stump11289f42009-09-09 15:08:12 +00004171
4172template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004174 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004175 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004176 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004177
4178 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179 QualType ElementType = getDerived().TransformType(T->getElementType());
4180 if (ElementType.isNull())
4181 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004182
Richard Smith764d2fe2011-12-20 02:08:33 +00004183 // Vector sizes are constant expressions.
4184 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4185 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004186
John McCalldadc5752010-08-24 06:29:42 +00004187 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004188 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189 if (Size.isInvalid())
4190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004191
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004194 ElementType != T->getElementType() ||
4195 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004196 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004197 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004199 if (Result.isNull())
4200 return QualType();
4201 }
John McCall550e0c22009-10-21 00:40:46 +00004202
4203 // Result might be dependent or not.
4204 if (isa<DependentSizedExtVectorType>(Result)) {
4205 DependentSizedExtVectorTypeLoc NewTL
4206 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4208 } else {
4209 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4211 }
4212
4213 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
4216template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004217QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004218 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004219 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004220 QualType ElementType = getDerived().TransformType(T->getElementType());
4221 if (ElementType.isNull())
4222 return QualType();
4223
John McCall550e0c22009-10-21 00:40:46 +00004224 QualType Result = TL.getType();
4225 if (getDerived().AlwaysRebuild() ||
4226 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004227 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004228 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004229 if (Result.isNull())
4230 return QualType();
4231 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004232
John McCall550e0c22009-10-21 00:40:46 +00004233 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4234 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004235
John McCall550e0c22009-10-21 00:40:46 +00004236 return Result;
4237}
4238
4239template<typename Derived>
4240QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004242 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004243 QualType ElementType = getDerived().TransformType(T->getElementType());
4244 if (ElementType.isNull())
4245 return QualType();
4246
4247 QualType Result = TL.getType();
4248 if (getDerived().AlwaysRebuild() ||
4249 ElementType != T->getElementType()) {
4250 Result = getDerived().RebuildExtVectorType(ElementType,
4251 T->getNumElements(),
4252 /*FIXME*/ SourceLocation());
4253 if (Result.isNull())
4254 return QualType();
4255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004256
John McCall550e0c22009-10-21 00:40:46 +00004257 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4259
4260 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
David Blaikie05785d12013-02-20 22:23:23 +00004263template <typename Derived>
4264ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4265 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4266 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004267 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004268 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004269
Douglas Gregor715e4612011-01-14 22:40:04 +00004270 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004271 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004272 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004273 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004274 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004275
Douglas Gregor715e4612011-01-14 22:40:04 +00004276 TypeLocBuilder TLB;
4277 TypeLoc NewTL = OldDI->getTypeLoc();
4278 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004279
4280 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004281 OldExpansionTL.getPatternLoc());
4282 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004283 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004284
4285 Result = RebuildPackExpansionType(Result,
4286 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004287 OldExpansionTL.getEllipsisLoc(),
4288 NumExpansions);
4289 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004290 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004291
Douglas Gregor715e4612011-01-14 22:40:04 +00004292 PackExpansionTypeLoc NewExpansionTL
4293 = TLB.push<PackExpansionTypeLoc>(Result);
4294 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4295 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4296 } else
4297 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004298 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004299 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004300
John McCall8fb0d9d2011-05-01 22:35:37 +00004301 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004302 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004303
4304 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4305 OldParm->getDeclContext(),
4306 OldParm->getInnerLocStart(),
4307 OldParm->getLocation(),
4308 OldParm->getIdentifier(),
4309 NewDI->getType(),
4310 NewDI,
4311 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004312 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004313 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4314 OldParm->getFunctionScopeIndex() + indexAdjustment);
4315 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004316}
4317
4318template<typename Derived>
4319bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004320 TransformFunctionTypeParams(SourceLocation Loc,
4321 ParmVarDecl **Params, unsigned NumParams,
4322 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004323 SmallVectorImpl<QualType> &OutParamTypes,
4324 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004325 int indexAdjustment = 0;
4326
Douglas Gregordd472162011-01-07 00:20:55 +00004327 for (unsigned i = 0; i != NumParams; ++i) {
4328 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004329 assert(OldParm->getFunctionScopeIndex() == i);
4330
David Blaikie05785d12013-02-20 22:23:23 +00004331 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004332 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 if (OldParm->isParameterPack()) {
4334 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004336
Douglas Gregor5499af42011-01-05 23:12:31 +00004337 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004338 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004339 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004340 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4341 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004342 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4343
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;
David Blaikie05785d12013-02-20 22:23:23 +00004347 Optional<unsigned> OrigNumExpansions =
4348 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004349 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004350 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4351 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004352 Unexpanded,
4353 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004354 RetainExpansion,
4355 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004356 return true;
4357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004358
Douglas Gregor5499af42011-01-05 23:12:31 +00004359 if (ShouldExpand) {
4360 // Expand the function parameter pack into multiple, separate
4361 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004362 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004363 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004365 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004366 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004367 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004368 OrigNumExpansions,
4369 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004370 if (!NewParm)
4371 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregordd472162011-01-07 00:20:55 +00004373 OutParamTypes.push_back(NewParm->getType());
4374 if (PVars)
4375 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004376 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004377
4378 // If we're supposed to retain a pack expansion, do so by temporarily
4379 // forgetting the partially-substituted parameter pack.
4380 if (RetainExpansion) {
4381 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004382 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004383 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004384 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004385 OrigNumExpansions,
4386 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004387 if (!NewParm)
4388 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004389
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004390 OutParamTypes.push_back(NewParm->getType());
4391 if (PVars)
4392 PVars->push_back(NewParm);
4393 }
4394
John McCall8fb0d9d2011-05-01 22:35:37 +00004395 // The next parameter should have the same adjustment as the
4396 // last thing we pushed, but we post-incremented indexAdjustment
4397 // on every push. Also, if we push nothing, the adjustment should
4398 // go down by one.
4399 indexAdjustment--;
4400
Douglas Gregor5499af42011-01-05 23:12:31 +00004401 // We're done with the pack expansion.
4402 continue;
4403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004404
4405 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004406 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004407 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4408 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004409 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004410 NumExpansions,
4411 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004412 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004413 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004414 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004415 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004416
John McCall58f10c32010-03-11 09:03:00 +00004417 if (!NewParm)
4418 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004419
Douglas Gregordd472162011-01-07 00:20:55 +00004420 OutParamTypes.push_back(NewParm->getType());
4421 if (PVars)
4422 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004423 continue;
4424 }
John McCall58f10c32010-03-11 09:03:00 +00004425
4426 // Deal with the possibility that we don't have a parameter
4427 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004428 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004429 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004430 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004431 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004432 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004433 = dyn_cast<PackExpansionType>(OldType)) {
4434 // We have a function parameter pack that may need to be expanded.
4435 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004436 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004438
Douglas Gregor5499af42011-01-05 23:12:31 +00004439 // Determine whether we should expand the parameter packs.
4440 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004441 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004442 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004443 Unexpanded,
4444 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004445 RetainExpansion,
4446 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004447 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004449
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004451 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004452 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004453 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004454 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4455 QualType NewType = getDerived().TransformType(Pattern);
4456 if (NewType.isNull())
4457 return true;
John McCall58f10c32010-03-11 09:03:00 +00004458
Douglas Gregordd472162011-01-07 00:20:55 +00004459 OutParamTypes.push_back(NewType);
4460 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004461 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004463
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 // We're done with the pack expansion.
4465 continue;
4466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004467
Douglas Gregor48d24112011-01-10 20:53:55 +00004468 // If we're supposed to retain a pack expansion, do so by temporarily
4469 // forgetting the partially-substituted parameter pack.
4470 if (RetainExpansion) {
4471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4472 QualType NewType = getDerived().TransformType(Pattern);
4473 if (NewType.isNull())
4474 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004475
Douglas Gregor48d24112011-01-10 20:53:55 +00004476 OutParamTypes.push_back(NewType);
4477 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004478 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004479 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004480
Chad Rosier1dcde962012-08-08 18:46:20 +00004481 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004482 // expansion.
4483 OldType = Expansion->getPattern();
4484 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004485 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4486 NewType = getDerived().TransformType(OldType);
4487 } else {
4488 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004490
Douglas Gregor5499af42011-01-05 23:12:31 +00004491 if (NewType.isNull())
4492 return true;
4493
4494 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004495 NewType = getSema().Context.getPackExpansionType(NewType,
4496 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004497
Douglas Gregordd472162011-01-07 00:20:55 +00004498 OutParamTypes.push_back(NewType);
4499 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004500 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004501 }
4502
John McCall8fb0d9d2011-05-01 22:35:37 +00004503#ifndef NDEBUG
4504 if (PVars) {
4505 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4506 if (ParmVarDecl *parm = (*PVars)[i])
4507 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004508 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004509#endif
4510
4511 return false;
4512}
John McCall58f10c32010-03-11 09:03:00 +00004513
4514template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004515QualType
John McCall550e0c22009-10-21 00:40:46 +00004516TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004517 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004518 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004519}
4520
4521template<typename Derived>
4522QualType
4523TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4524 FunctionProtoTypeLoc TL,
4525 CXXRecordDecl *ThisContext,
4526 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004527 // Transform the parameters and return type.
4528 //
Richard Smithf623c962012-04-17 00:58:00 +00004529 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004530 // When the function has a trailing return type, we instantiate the
4531 // parameters before the return type, since the return type can then refer
4532 // to the parameters themselves (via decltype, sizeof, etc.).
4533 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004534 SmallVector<QualType, 4> ParamTypes;
4535 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004536 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004537
Douglas Gregor7fb25412010-10-01 18:44:50 +00004538 QualType ResultType;
4539
Richard Smith1226c602012-08-14 22:51:13 +00004540 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004541 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004542 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004543 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004544 return QualType();
4545
Douglas Gregor3024f072012-04-16 07:05:22 +00004546 {
4547 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004548 // If a declaration declares a member function or member function
4549 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004550 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004551 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004552 // declarator.
4553 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004554
Alp Toker42a16a62014-01-25 23:51:36 +00004555 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004556 if (ResultType.isNull())
4557 return QualType();
4558 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004559 }
4560 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004561 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004562 if (ResultType.isNull())
4563 return QualType();
4564
Alp Toker9cacbab2014-01-20 20:26:09 +00004565 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004566 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004567 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004568 return QualType();
4569 }
4570
Richard Smithf623c962012-04-17 00:58:00 +00004571 // FIXME: Need to transform the exception-specification too.
4572
John McCall550e0c22009-10-21 00:40:46 +00004573 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004574 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004575 T->getNumParams() != ParamTypes.size() ||
4576 !std::equal(T->param_type_begin(), T->param_type_end(),
4577 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004578 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004579 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004580 if (Result.isNull())
4581 return QualType();
4582 }
Mike Stump11289f42009-09-09 15:08:12 +00004583
John McCall550e0c22009-10-21 00:40:46 +00004584 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004585 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004586 NewTL.setLParenLoc(TL.getLParenLoc());
4587 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004588 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004589 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4590 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004591
4592 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregord6ff3322009-08-04 16:50:30 +00004595template<typename Derived>
4596QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004597 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004599 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004600 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004601 if (ResultType.isNull())
4602 return QualType();
4603
4604 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004605 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004606 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4607
4608 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004609 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004610 NewTL.setLParenLoc(TL.getLParenLoc());
4611 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004612 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004613
4614 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004615}
Mike Stump11289f42009-09-09 15:08:12 +00004616
John McCallb96ec562009-12-04 22:46:56 +00004617template<typename Derived> QualType
4618TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004619 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004620 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004621 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004622 if (!D)
4623 return QualType();
4624
4625 QualType Result = TL.getType();
4626 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4627 Result = getDerived().RebuildUnresolvedUsingType(D);
4628 if (Result.isNull())
4629 return QualType();
4630 }
4631
4632 // We might get an arbitrary type spec type back. We should at
4633 // least always get a type spec type, though.
4634 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4635 NewTL.setNameLoc(TL.getNameLoc());
4636
4637 return Result;
4638}
4639
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004641QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004642 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004643 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004644 TypedefNameDecl *Typedef
4645 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4646 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004647 if (!Typedef)
4648 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004649
John McCall550e0c22009-10-21 00:40:46 +00004650 QualType Result = TL.getType();
4651 if (getDerived().AlwaysRebuild() ||
4652 Typedef != T->getDecl()) {
4653 Result = getDerived().RebuildTypedefType(Typedef);
4654 if (Result.isNull())
4655 return QualType();
4656 }
Mike Stump11289f42009-09-09 15:08:12 +00004657
John McCall550e0c22009-10-21 00:40:46 +00004658 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4659 NewTL.setNameLoc(TL.getNameLoc());
4660
4661 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662}
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregord6ff3322009-08-04 16:50:30 +00004664template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004665QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004666 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004667 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004668 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4669 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004670
John McCalldadc5752010-08-24 06:29:42 +00004671 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004672 if (E.isInvalid())
4673 return QualType();
4674
Eli Friedmane4f22df2012-02-29 04:03:55 +00004675 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4676 if (E.isInvalid())
4677 return QualType();
4678
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType Result = TL.getType();
4680 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004681 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004682 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004683 if (Result.isNull())
4684 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004685 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004686 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004687
John McCall550e0c22009-10-21 00:40:46 +00004688 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004689 NewTL.setTypeofLoc(TL.getTypeofLoc());
4690 NewTL.setLParenLoc(TL.getLParenLoc());
4691 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004692
4693 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004694}
Mike Stump11289f42009-09-09 15:08:12 +00004695
4696template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004697QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004698 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004699 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4700 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4701 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004702 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004703
John McCall550e0c22009-10-21 00:40:46 +00004704 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004705 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4706 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004707 if (Result.isNull())
4708 return QualType();
4709 }
Mike Stump11289f42009-09-09 15:08:12 +00004710
John McCall550e0c22009-10-21 00:40:46 +00004711 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004712 NewTL.setTypeofLoc(TL.getTypeofLoc());
4713 NewTL.setLParenLoc(TL.getLParenLoc());
4714 NewTL.setRParenLoc(TL.getRParenLoc());
4715 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004716
4717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718}
Mike Stump11289f42009-09-09 15:08:12 +00004719
4720template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004721QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004722 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004723 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004724
Douglas Gregore922c772009-08-04 22:27:00 +00004725 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004726 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4727 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004728
John McCalldadc5752010-08-24 06:29:42 +00004729 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004730 if (E.isInvalid())
4731 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004732
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004733 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004734 if (E.isInvalid())
4735 return QualType();
4736
John McCall550e0c22009-10-21 00:40:46 +00004737 QualType Result = TL.getType();
4738 if (getDerived().AlwaysRebuild() ||
4739 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004740 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004741 if (Result.isNull())
4742 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004743 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004744 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004745
John McCall550e0c22009-10-21 00:40:46 +00004746 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4747 NewTL.setNameLoc(TL.getNameLoc());
4748
4749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004750}
4751
4752template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004753QualType TreeTransform<Derived>::TransformUnaryTransformType(
4754 TypeLocBuilder &TLB,
4755 UnaryTransformTypeLoc TL) {
4756 QualType Result = TL.getType();
4757 if (Result->isDependentType()) {
4758 const UnaryTransformType *T = TL.getTypePtr();
4759 QualType NewBase =
4760 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4761 Result = getDerived().RebuildUnaryTransformType(NewBase,
4762 T->getUTTKind(),
4763 TL.getKWLoc());
4764 if (Result.isNull())
4765 return QualType();
4766 }
4767
4768 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4769 NewTL.setKWLoc(TL.getKWLoc());
4770 NewTL.setParensRange(TL.getParensRange());
4771 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4772 return Result;
4773}
4774
4775template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004776QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4777 AutoTypeLoc TL) {
4778 const AutoType *T = TL.getTypePtr();
4779 QualType OldDeduced = T->getDeducedType();
4780 QualType NewDeduced;
4781 if (!OldDeduced.isNull()) {
4782 NewDeduced = getDerived().TransformType(OldDeduced);
4783 if (NewDeduced.isNull())
4784 return QualType();
4785 }
4786
4787 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004788 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4789 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004790 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004791 if (Result.isNull())
4792 return QualType();
4793 }
4794
4795 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4796 NewTL.setNameLoc(TL.getNameLoc());
4797
4798 return Result;
4799}
4800
4801template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004802QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004803 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004804 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004805 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004806 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4807 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004808 if (!Record)
4809 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004810
John McCall550e0c22009-10-21 00:40:46 +00004811 QualType Result = TL.getType();
4812 if (getDerived().AlwaysRebuild() ||
4813 Record != T->getDecl()) {
4814 Result = getDerived().RebuildRecordType(Record);
4815 if (Result.isNull())
4816 return QualType();
4817 }
Mike Stump11289f42009-09-09 15:08:12 +00004818
John McCall550e0c22009-10-21 00:40:46 +00004819 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4820 NewTL.setNameLoc(TL.getNameLoc());
4821
4822 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004823}
Mike Stump11289f42009-09-09 15:08:12 +00004824
4825template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004826QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004827 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004828 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004829 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004830 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4831 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004832 if (!Enum)
4833 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004834
John McCall550e0c22009-10-21 00:40:46 +00004835 QualType Result = TL.getType();
4836 if (getDerived().AlwaysRebuild() ||
4837 Enum != T->getDecl()) {
4838 Result = getDerived().RebuildEnumType(Enum);
4839 if (Result.isNull())
4840 return QualType();
4841 }
Mike Stump11289f42009-09-09 15:08:12 +00004842
John McCall550e0c22009-10-21 00:40:46 +00004843 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4844 NewTL.setNameLoc(TL.getNameLoc());
4845
4846 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004847}
John McCallfcc33b02009-09-05 00:15:47 +00004848
John McCalle78aac42010-03-10 03:28:59 +00004849template<typename Derived>
4850QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4851 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004852 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004853 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4854 TL.getTypePtr()->getDecl());
4855 if (!D) return QualType();
4856
4857 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4858 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4859 return T;
4860}
4861
Douglas Gregord6ff3322009-08-04 16:50:30 +00004862template<typename Derived>
4863QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004864 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004865 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004866 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004867}
4868
Mike Stump11289f42009-09-09 15:08:12 +00004869template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004870QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004871 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004872 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004873 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004875 // Substitute into the replacement type, which itself might involve something
4876 // that needs to be transformed. This only tends to occur with default
4877 // template arguments of template template parameters.
4878 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4879 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4880 if (Replacement.isNull())
4881 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004882
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004883 // Always canonicalize the replacement type.
4884 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4885 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004886 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004887 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004889 // Propagate type-source information.
4890 SubstTemplateTypeParmTypeLoc NewTL
4891 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4892 NewTL.setNameLoc(TL.getNameLoc());
4893 return Result;
4894
John McCallcebee162009-10-18 09:09:24 +00004895}
4896
4897template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004898QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4899 TypeLocBuilder &TLB,
4900 SubstTemplateTypeParmPackTypeLoc TL) {
4901 return TransformTypeSpecType(TLB, TL);
4902}
4903
4904template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004905QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004906 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004907 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004908 const TemplateSpecializationType *T = TL.getTypePtr();
4909
Douglas Gregordf846d12011-03-02 18:46:51 +00004910 // The nested-name-specifier never matters in a TemplateSpecializationType,
4911 // because we can't have a dependent nested-name-specifier anyway.
4912 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004913 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004914 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4915 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004916 if (Template.isNull())
4917 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004918
John McCall31f82722010-11-12 08:19:04 +00004919 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4920}
4921
Eli Friedman0dfb8892011-10-06 23:00:33 +00004922template<typename Derived>
4923QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4924 AtomicTypeLoc TL) {
4925 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4926 if (ValueType.isNull())
4927 return QualType();
4928
4929 QualType Result = TL.getType();
4930 if (getDerived().AlwaysRebuild() ||
4931 ValueType != TL.getValueLoc().getType()) {
4932 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4933 if (Result.isNull())
4934 return QualType();
4935 }
4936
4937 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4938 NewTL.setKWLoc(TL.getKWLoc());
4939 NewTL.setLParenLoc(TL.getLParenLoc());
4940 NewTL.setRParenLoc(TL.getRParenLoc());
4941
4942 return Result;
4943}
4944
Chad Rosier1dcde962012-08-08 18:46:20 +00004945 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004946 /// container that provides a \c getArgLoc() member function.
4947 ///
4948 /// This iterator is intended to be used with the iterator form of
4949 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4950 template<typename ArgLocContainer>
4951 class TemplateArgumentLocContainerIterator {
4952 ArgLocContainer *Container;
4953 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004954
Douglas Gregorfe921a72010-12-20 23:36:19 +00004955 public:
4956 typedef TemplateArgumentLoc value_type;
4957 typedef TemplateArgumentLoc reference;
4958 typedef int difference_type;
4959 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004960
Douglas Gregorfe921a72010-12-20 23:36:19 +00004961 class pointer {
4962 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004963
Douglas Gregorfe921a72010-12-20 23:36:19 +00004964 public:
4965 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
Douglas Gregorfe921a72010-12-20 23:36:19 +00004967 const TemplateArgumentLoc *operator->() const {
4968 return &Arg;
4969 }
4970 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
4972
Douglas Gregorfe921a72010-12-20 23:36:19 +00004973 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004974
Douglas Gregorfe921a72010-12-20 23:36:19 +00004975 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4976 unsigned Index)
4977 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004978
Douglas Gregorfe921a72010-12-20 23:36:19 +00004979 TemplateArgumentLocContainerIterator &operator++() {
4980 ++Index;
4981 return *this;
4982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
Douglas Gregorfe921a72010-12-20 23:36:19 +00004984 TemplateArgumentLocContainerIterator operator++(int) {
4985 TemplateArgumentLocContainerIterator Old(*this);
4986 ++(*this);
4987 return Old;
4988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregorfe921a72010-12-20 23:36:19 +00004990 TemplateArgumentLoc operator*() const {
4991 return Container->getArgLoc(Index);
4992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004993
Douglas Gregorfe921a72010-12-20 23:36:19 +00004994 pointer operator->() const {
4995 return pointer(Container->getArgLoc(Index));
4996 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004997
Douglas Gregorfe921a72010-12-20 23:36:19 +00004998 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004999 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005000 return X.Container == Y.Container && X.Index == Y.Index;
5001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
Douglas Gregorfe921a72010-12-20 23:36:19 +00005003 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005004 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005005 return !(X == Y);
5006 }
5007 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005008
5009
John McCall31f82722010-11-12 08:19:04 +00005010template <typename Derived>
5011QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5012 TypeLocBuilder &TLB,
5013 TemplateSpecializationTypeLoc TL,
5014 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005015 TemplateArgumentListInfo NewTemplateArgs;
5016 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5017 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005018 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5019 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005020 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005021 ArgIterator(TL, TL.getNumArgs()),
5022 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005023 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005024
John McCall0ad16662009-10-29 08:12:44 +00005025 // FIXME: maybe don't rebuild if all the template arguments are the same.
5026
5027 QualType Result =
5028 getDerived().RebuildTemplateSpecializationType(Template,
5029 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005030 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005031
5032 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005033 // Specializations of template template parameters are represented as
5034 // TemplateSpecializationTypes, and substitution of type alias templates
5035 // within a dependent context can transform them into
5036 // DependentTemplateSpecializationTypes.
5037 if (isa<DependentTemplateSpecializationType>(Result)) {
5038 DependentTemplateSpecializationTypeLoc NewTL
5039 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005040 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005041 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005042 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005043 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005044 NewTL.setLAngleLoc(TL.getLAngleLoc());
5045 NewTL.setRAngleLoc(TL.getRAngleLoc());
5046 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5047 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5048 return Result;
5049 }
5050
John McCall0ad16662009-10-29 08:12:44 +00005051 TemplateSpecializationTypeLoc NewTL
5052 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005053 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005054 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5055 NewTL.setLAngleLoc(TL.getLAngleLoc());
5056 NewTL.setRAngleLoc(TL.getRAngleLoc());
5057 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5058 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005059 }
Mike Stump11289f42009-09-09 15:08:12 +00005060
John McCall0ad16662009-10-29 08:12:44 +00005061 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005062}
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregor5a064722011-02-28 17:23:35 +00005064template <typename Derived>
5065QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5066 TypeLocBuilder &TLB,
5067 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005068 TemplateName Template,
5069 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005070 TemplateArgumentListInfo NewTemplateArgs;
5071 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5072 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5073 typedef TemplateArgumentLocContainerIterator<
5074 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005075 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005076 ArgIterator(TL, TL.getNumArgs()),
5077 NewTemplateArgs))
5078 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005079
Douglas Gregor5a064722011-02-28 17:23:35 +00005080 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005081
Douglas Gregor5a064722011-02-28 17:23:35 +00005082 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5083 QualType Result
5084 = getSema().Context.getDependentTemplateSpecializationType(
5085 TL.getTypePtr()->getKeyword(),
5086 DTN->getQualifier(),
5087 DTN->getIdentifier(),
5088 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005089
Douglas Gregor5a064722011-02-28 17:23:35 +00005090 DependentTemplateSpecializationTypeLoc NewTL
5091 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005092 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005093 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005094 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005095 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005096 NewTL.setLAngleLoc(TL.getLAngleLoc());
5097 NewTL.setRAngleLoc(TL.getRAngleLoc());
5098 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5099 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5100 return Result;
5101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005102
5103 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005104 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005105 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005106 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005107
Douglas Gregor5a064722011-02-28 17:23:35 +00005108 if (!Result.isNull()) {
5109 /// FIXME: Wrap this in an elaborated-type-specifier?
5110 TemplateSpecializationTypeLoc NewTL
5111 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005112 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005113 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005114 NewTL.setLAngleLoc(TL.getLAngleLoc());
5115 NewTL.setRAngleLoc(TL.getRAngleLoc());
5116 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5117 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5118 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005119
Douglas Gregor5a064722011-02-28 17:23:35 +00005120 return Result;
5121}
5122
Mike Stump11289f42009-09-09 15:08:12 +00005123template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005124QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005125TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005126 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005127 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005128
Douglas Gregor844cb502011-03-01 18:12:44 +00005129 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005130 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005131 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005132 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005133 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5134 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005135 return QualType();
5136 }
Mike Stump11289f42009-09-09 15:08:12 +00005137
John McCall31f82722010-11-12 08:19:04 +00005138 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5139 if (NamedT.isNull())
5140 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005141
Richard Smith3f1b5d02011-05-05 21:57:07 +00005142 // C++0x [dcl.type.elab]p2:
5143 // If the identifier resolves to a typedef-name or the simple-template-id
5144 // resolves to an alias template specialization, the
5145 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005146 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5147 if (const TemplateSpecializationType *TST =
5148 NamedT->getAs<TemplateSpecializationType>()) {
5149 TemplateName Template = TST->getTemplateName();
5150 if (TypeAliasTemplateDecl *TAT =
5151 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5152 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5153 diag::err_tag_reference_non_tag) << 4;
5154 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5155 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005156 }
5157 }
5158
John McCall550e0c22009-10-21 00:40:46 +00005159 QualType Result = TL.getType();
5160 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005161 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005162 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005163 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005164 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005165 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005166 if (Result.isNull())
5167 return QualType();
5168 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169
Abramo Bagnara6150c882010-05-11 21:36:43 +00005170 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005171 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005172 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005173 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005174}
Mike Stump11289f42009-09-09 15:08:12 +00005175
5176template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005177QualType TreeTransform<Derived>::TransformAttributedType(
5178 TypeLocBuilder &TLB,
5179 AttributedTypeLoc TL) {
5180 const AttributedType *oldType = TL.getTypePtr();
5181 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5182 if (modifiedType.isNull())
5183 return QualType();
5184
5185 QualType result = TL.getType();
5186
5187 // FIXME: dependent operand expressions?
5188 if (getDerived().AlwaysRebuild() ||
5189 modifiedType != oldType->getModifiedType()) {
5190 // TODO: this is really lame; we should really be rebuilding the
5191 // equivalent type from first principles.
5192 QualType equivalentType
5193 = getDerived().TransformType(oldType->getEquivalentType());
5194 if (equivalentType.isNull())
5195 return QualType();
5196 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5197 modifiedType,
5198 equivalentType);
5199 }
5200
5201 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5202 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5203 if (TL.hasAttrOperand())
5204 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5205 if (TL.hasAttrExprOperand())
5206 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5207 else if (TL.hasAttrEnumOperand())
5208 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5209
5210 return result;
5211}
5212
5213template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005214QualType
5215TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5216 ParenTypeLoc TL) {
5217 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5218 if (Inner.isNull())
5219 return QualType();
5220
5221 QualType Result = TL.getType();
5222 if (getDerived().AlwaysRebuild() ||
5223 Inner != TL.getInnerLoc().getType()) {
5224 Result = getDerived().RebuildParenType(Inner);
5225 if (Result.isNull())
5226 return QualType();
5227 }
5228
5229 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5230 NewTL.setLParenLoc(TL.getLParenLoc());
5231 NewTL.setRParenLoc(TL.getRParenLoc());
5232 return Result;
5233}
5234
5235template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005236QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005237 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005238 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005239
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005240 NestedNameSpecifierLoc QualifierLoc
5241 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5242 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005243 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCallc392f372010-06-11 00:33:02 +00005245 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005246 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005247 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005248 QualifierLoc,
5249 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005250 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005251 if (Result.isNull())
5252 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253
Abramo Bagnarad7548482010-05-19 21:37:53 +00005254 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5255 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005256 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5257
Abramo Bagnarad7548482010-05-19 21:37:53 +00005258 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005259 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005260 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005261 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005262 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005263 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005264 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005265 NewTL.setNameLoc(TL.getNameLoc());
5266 }
John McCall550e0c22009-10-21 00:40:46 +00005267 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268}
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregord6ff3322009-08-04 16:50:30 +00005270template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005271QualType TreeTransform<Derived>::
5272 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005273 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005274 NestedNameSpecifierLoc QualifierLoc;
5275 if (TL.getQualifierLoc()) {
5276 QualifierLoc
5277 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5278 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005279 return QualType();
5280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005281
John McCall31f82722010-11-12 08:19:04 +00005282 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005283 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005284}
5285
5286template<typename Derived>
5287QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005288TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5289 DependentTemplateSpecializationTypeLoc TL,
5290 NestedNameSpecifierLoc QualifierLoc) {
5291 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005292
Douglas Gregora7a795b2011-03-01 20:11:18 +00005293 TemplateArgumentListInfo NewTemplateArgs;
5294 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5295 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005296
Douglas Gregora7a795b2011-03-01 20:11:18 +00005297 typedef TemplateArgumentLocContainerIterator<
5298 DependentTemplateSpecializationTypeLoc> ArgIterator;
5299 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5300 ArgIterator(TL, TL.getNumArgs()),
5301 NewTemplateArgs))
5302 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005303
Douglas Gregora7a795b2011-03-01 20:11:18 +00005304 QualType Result
5305 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5306 QualifierLoc,
5307 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005308 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005309 NewTemplateArgs);
5310 if (Result.isNull())
5311 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregora7a795b2011-03-01 20:11:18 +00005313 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5314 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005315
Douglas Gregora7a795b2011-03-01 20:11:18 +00005316 // Copy information relevant to the template specialization.
5317 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005318 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005319 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005321 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5322 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005323 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005324 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005325
Douglas Gregora7a795b2011-03-01 20:11:18 +00005326 // Copy information relevant to the elaborated type.
5327 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005328 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005329 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005330 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5331 DependentTemplateSpecializationTypeLoc SpecTL
5332 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005333 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005334 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005335 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005336 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005337 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5338 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005339 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005340 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005341 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005342 TemplateSpecializationTypeLoc SpecTL
5343 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005344 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005345 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005346 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5347 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005348 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005349 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005350 }
5351 return Result;
5352}
5353
5354template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005355QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5356 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005357 QualType Pattern
5358 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005359 if (Pattern.isNull())
5360 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005361
5362 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005363 if (getDerived().AlwaysRebuild() ||
5364 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005365 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005366 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005367 TL.getEllipsisLoc(),
5368 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005369 if (Result.isNull())
5370 return QualType();
5371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005372
Douglas Gregor822d0302011-01-12 17:07:58 +00005373 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5374 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5375 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005376}
5377
5378template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005379QualType
5380TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005381 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005382 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005383 TLB.pushFullCopy(TL);
5384 return TL.getType();
5385}
5386
5387template<typename Derived>
5388QualType
5389TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005390 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005391 // ObjCObjectType is never dependent.
5392 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005393 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
5396template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005397QualType
5398TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005399 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005400 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005401 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005402 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005403}
5404
Douglas Gregord6ff3322009-08-04 16:50:30 +00005405//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005406// Statement transformation
5407//===----------------------------------------------------------------------===//
5408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005410TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005411 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005412}
5413
5414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005415StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005416TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5417 return getDerived().TransformCompoundStmt(S, false);
5418}
5419
5420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005421StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005422TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005423 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005424 Sema::CompoundScopeRAII CompoundScope(getSema());
5425
John McCall1ababa62010-08-27 19:56:05 +00005426 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005427 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005428 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005429 for (auto *B : S->body()) {
5430 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005431 if (Result.isInvalid()) {
5432 // Immediately fail if this was a DeclStmt, since it's very
5433 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005434 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005435 return StmtError();
5436
5437 // Otherwise, just keep processing substatements and fail later.
5438 SubStmtInvalid = true;
5439 continue;
5440 }
Mike Stump11289f42009-09-09 15:08:12 +00005441
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005442 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005443 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005444 }
Mike Stump11289f42009-09-09 15:08:12 +00005445
John McCall1ababa62010-08-27 19:56:05 +00005446 if (SubStmtInvalid)
5447 return StmtError();
5448
Douglas Gregorebe10102009-08-20 07:17:43 +00005449 if (!getDerived().AlwaysRebuild() &&
5450 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005451 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005452
5453 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005454 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 S->getRBracLoc(),
5456 IsStmtExpr);
5457}
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregorebe10102009-08-20 07:17:43 +00005459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005460StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005461TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005462 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005463 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005464 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5465 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005466
Eli Friedman06577382009-11-19 03:14:00 +00005467 // Transform the left-hand case value.
5468 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005469 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005470 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005472
Eli Friedman06577382009-11-19 03:14:00 +00005473 // Transform the right-hand case value (for the GNU case-range extension).
5474 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005475 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005476 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005478 }
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregorebe10102009-08-20 07:17:43 +00005480 // Build the case statement.
5481 // Case statements are always rebuilt so that they will attached to their
5482 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005483 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005484 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005486 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 S->getColonLoc());
5488 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005489 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005492 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregorebe10102009-08-20 07:17:43 +00005496 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005497 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005498}
5499
5500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005501StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005504 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005505 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 // Default statements are always rebuilt
5509 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005510 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005511}
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregorebe10102009-08-20 07:17:43 +00005513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005514StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005515TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005516 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005519
Chris Lattnercab02a62011-02-17 20:34:02 +00005520 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5521 S->getDecl());
5522 if (!LD)
5523 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005524
5525
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005527 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005528 cast<LabelDecl>(LD), SourceLocation(),
5529 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005530}
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregorebe10102009-08-20 07:17:43 +00005532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005533StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005534TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5535 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5536 if (SubStmt.isInvalid())
5537 return StmtError();
5538
5539 // TODO: transform attributes
5540 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5541 return S;
5542
5543 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5544 S->getAttrs(),
5545 SubStmt.get());
5546}
5547
5548template<typename Derived>
5549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005550TreeTransform<Derived>::TransformIfStmt(IfStmt *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 Gregor633caca2009-11-23 23:44:04 +00005554 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005555 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005556 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005557 getDerived().TransformDefinition(
5558 S->getConditionVariable()->getLocation(),
5559 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005560 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005562 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +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();
Chad Rosier1dcde962012-08-08 18:46:20 +00005567
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005568 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005569 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005570 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005571 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005572 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005573 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005574
John McCallb268a282010-08-23 23:25:46 +00005575 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005576 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005577 }
Chad Rosier1dcde962012-08-08 18:46:20 +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();
Chad Rosier1dcde962012-08-08 18:46:20 +00005582
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005584 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 if (Then.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 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005589 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005594 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005595 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 Then.get() == S->getThen() &&
5597 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005598 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005600 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005601 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005602 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005603}
5604
5605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005606StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005607TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005608 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005609 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005610 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005611 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005612 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005613 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005614 getDerived().TransformDefinition(
5615 S->getConditionVariable()->getLocation(),
5616 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005617 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005619 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005620 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005621
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005622 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005624 }
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregorebe10102009-08-20 07:17:43 +00005626 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005627 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005628 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005629 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005630 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005631 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregorebe10102009-08-20 07:17:43 +00005633 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005634 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005636 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregorebe10102009-08-20 07:17:43 +00005638 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005639 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5640 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005641}
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregorebe10102009-08-20 07:17:43 +00005643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005644StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005645TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005647 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005648 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005649 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005650 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005651 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005652 getDerived().TransformDefinition(
5653 S->getConditionVariable()->getLocation(),
5654 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005655 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005657 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005658 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005659
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005660 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005662
5663 if (S->getCond()) {
5664 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005665 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5666 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005667 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005668 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005670 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005671 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005672 }
Mike Stump11289f42009-09-09 15:08:12 +00005673
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005674 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005675 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005676 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005677
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005679 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005684 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005685 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005687 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005689 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005690 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691}
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregorebe10102009-08-20 07:17:43 +00005693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005695TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005697 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005701 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005702 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005703 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706 if (!getDerived().AlwaysRebuild() &&
5707 Cond.get() == S->getCond() &&
5708 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005709 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005710
John McCallb268a282010-08-23 23:25:46 +00005711 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5712 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005713 S->getRParenLoc());
5714}
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregorebe10102009-08-20 07:17:43 +00005716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005718TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005720 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005721 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregorebe10102009-08-20 07:17:43 +00005724 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005725 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005726 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005727 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005728 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005729 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005730 getDerived().TransformDefinition(
5731 S->getConditionVariable()->getLocation(),
5732 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005733 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005734 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005735 } else {
5736 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005737
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005738 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005740
5741 if (S->getCond()) {
5742 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005743 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5744 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005745 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005746 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005748
John McCallb268a282010-08-23 23:25:46 +00005749 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005750 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005751 }
Mike Stump11289f42009-09-09 15:08:12 +00005752
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005753 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005754 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005755 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005756
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005758 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005759 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005761
Richard Smith945f8d32013-01-14 22:39:08 +00005762 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005763 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005764 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005765
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005767 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005770
Douglas Gregorebe10102009-08-20 07:17:43 +00005771 if (!getDerived().AlwaysRebuild() &&
5772 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005773 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005774 Inc.get() == S->getInc() &&
5775 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005776 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregorebe10102009-08-20 07:17:43 +00005778 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005779 Init.get(), FullCond, ConditionVar,
5780 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005781}
5782
5783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005784StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005785TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005786 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5787 S->getLabel());
5788 if (!LD)
5789 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
Douglas Gregorebe10102009-08-20 07:17:43 +00005791 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005792 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005793 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005794}
5795
5796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005798TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005799 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005800 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005801 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005802 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregorebe10102009-08-20 07:17:43 +00005804 if (!getDerived().AlwaysRebuild() &&
5805 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005806 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005807
5808 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005809 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005810}
5811
5812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005813StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005814TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005815 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005816}
Mike Stump11289f42009-09-09 15:08:12 +00005817
Douglas Gregorebe10102009-08-20 07:17:43 +00005818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005819StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005820TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005821 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005822}
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregorebe10102009-08-20 07:17:43 +00005824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005825StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005826TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005827 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005828 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005829 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005830
Mike Stump11289f42009-09-09 15:08:12 +00005831 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005832 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005833 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005834}
Mike Stump11289f42009-09-09 15:08:12 +00005835
Douglas Gregorebe10102009-08-20 07:17:43 +00005836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005837StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005838TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005839 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005840 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005841 for (auto *D : S->decls()) {
5842 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005843 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005845
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005846 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005848
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 Decls.push_back(Transformed);
5850 }
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregorebe10102009-08-20 07:17:43 +00005852 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005853 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005854
Rafael Espindolaab417692013-07-09 12:05:01 +00005855 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005856}
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregorebe10102009-08-20 07:17:43 +00005858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005859StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005860TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005861
Benjamin Kramerf0623432012-08-23 22:51:59 +00005862 SmallVector<Expr*, 8> Constraints;
5863 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005864 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005865
John McCalldadc5752010-08-24 06:29:42 +00005866 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005867 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005868
5869 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Anders Carlssonaaeef072010-01-24 05:50:09 +00005871 // Go through the outputs.
5872 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005873 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Anders Carlssonaaeef072010-01-24 05:50:09 +00005875 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005876 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005877
Anders Carlssonaaeef072010-01-24 05:50:09 +00005878 // Transform the output expr.
5879 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005880 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005881 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
Anders Carlssonaaeef072010-01-24 05:50:09 +00005884 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005885
John McCallb268a282010-08-23 23:25:46 +00005886 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005888
Anders Carlssonaaeef072010-01-24 05:50:09 +00005889 // Go through the inputs.
5890 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005891 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005894 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005895
Anders Carlssonaaeef072010-01-24 05:50:09 +00005896 // Transform the input expr.
5897 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005898 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005899 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005900 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
Anders Carlssonaaeef072010-01-24 05:50:09 +00005902 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005903
John McCallb268a282010-08-23 23:25:46 +00005904 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005906
Anders Carlssonaaeef072010-01-24 05:50:09 +00005907 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005908 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005909
5910 // Go through the clobbers.
5911 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005912 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005913
5914 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005915 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005916 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5917 S->isVolatile(), S->getNumOutputs(),
5918 S->getNumInputs(), Names.data(),
5919 Constraints, Exprs, AsmString.get(),
5920 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005921}
5922
Chad Rosier32503022012-06-11 20:47:18 +00005923template<typename Derived>
5924StmtResult
5925TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005926 ArrayRef<Token> AsmToks =
5927 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005928
John McCallf413f5e2013-05-03 00:10:13 +00005929 bool HadError = false, HadChange = false;
5930
5931 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5932 SmallVector<Expr*, 8> TransformedExprs;
5933 TransformedExprs.reserve(SrcExprs.size());
5934 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5935 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5936 if (!Result.isUsable()) {
5937 HadError = true;
5938 } else {
5939 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005940 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005941 }
5942 }
5943
5944 if (HadError) return StmtError();
5945 if (!HadChange && !getDerived().AlwaysRebuild())
5946 return Owned(S);
5947
Chad Rosierb6f46c12012-08-15 16:53:30 +00005948 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005949 AsmToks, S->getAsmString(),
5950 S->getNumOutputs(), S->getNumInputs(),
5951 S->getAllConstraints(), S->getClobbers(),
5952 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005953}
Douglas Gregorebe10102009-08-20 07:17:43 +00005954
5955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005956StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005957TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005958 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005959 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005960 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005961 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005962
Douglas Gregor96c79492010-04-23 22:50:49 +00005963 // Transform the @catch statements (if present).
5964 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005965 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005966 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005967 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005968 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005970 if (Catch.get() != S->getCatchStmt(I))
5971 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005972 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005974
Douglas Gregor306de2f2010-04-22 23:59:56 +00005975 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005976 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005977 if (S->getFinallyStmt()) {
5978 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5979 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005981 }
5982
5983 // If nothing changed, just retain this statement.
5984 if (!getDerived().AlwaysRebuild() &&
5985 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005986 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005987 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005988 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregor306de2f2010-04-22 23:59:56 +00005990 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005991 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005992 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005993}
Mike Stump11289f42009-09-09 15:08:12 +00005994
Douglas Gregorebe10102009-08-20 07:17:43 +00005995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005996StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005997TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005998 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005999 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006000 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006001 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006002 if (FromVar->getTypeSourceInfo()) {
6003 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6004 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006008 QualType T;
6009 if (TSInfo)
6010 T = TSInfo->getType();
6011 else {
6012 T = getDerived().TransformType(FromVar->getType());
6013 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006014 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006016
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006017 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6018 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006019 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006020 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006021
John McCalldadc5752010-08-24 06:29:42 +00006022 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006023 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006025
6026 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006027 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006028 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006029}
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregorebe10102009-08-20 07:17:43 +00006031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006032StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006033TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006034 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006035 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006036 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006038
Douglas Gregor306de2f2010-04-22 23:59:56 +00006039 // If nothing changed, just retain this statement.
6040 if (!getDerived().AlwaysRebuild() &&
6041 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006042 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006043
6044 // Build a new statement.
6045 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006046 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006047}
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregorebe10102009-08-20 07:17:43 +00006049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006050StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006051TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006052 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006053 if (S->getThrowExpr()) {
6054 Operand = getDerived().TransformExpr(S->getThrowExpr());
6055 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006057 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006058
Douglas Gregor2900c162010-04-22 21:44:01 +00006059 if (!getDerived().AlwaysRebuild() &&
6060 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006061 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006062
John McCallb268a282010-08-23 23:25:46 +00006063 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006064}
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregorebe10102009-08-20 07:17:43 +00006066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006067StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006068TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006069 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006070 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006071 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006072 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006074 Object =
6075 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6076 Object.get());
6077 if (Object.isInvalid())
6078 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
Douglas Gregor6148de72010-04-22 22:01:21 +00006080 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006081 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006082 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006083 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006084
Douglas Gregor6148de72010-04-22 22:01:21 +00006085 // If nothing change, just retain the current statement.
6086 if (!getDerived().AlwaysRebuild() &&
6087 Object.get() == S->getSynchExpr() &&
6088 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006089 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006090
6091 // Build a new statement.
6092 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006093 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006094}
6095
6096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006097StmtResult
John McCall31168b02011-06-15 23:02:42 +00006098TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6099 ObjCAutoreleasePoolStmt *S) {
6100 // Transform the body.
6101 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6102 if (Body.isInvalid())
6103 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006104
John McCall31168b02011-06-15 23:02:42 +00006105 // If nothing changed, just retain this statement.
6106 if (!getDerived().AlwaysRebuild() &&
6107 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006108 return S;
John McCall31168b02011-06-15 23:02:42 +00006109
6110 // Build a new statement.
6111 return getDerived().RebuildObjCAutoreleasePoolStmt(
6112 S->getAtLoc(), Body.get());
6113}
6114
6115template<typename Derived>
6116StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006117TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006118 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006119 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006120 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006121 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006123
Douglas Gregorf68a5082010-04-22 23:10:45 +00006124 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006125 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006126 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006128
Douglas Gregorf68a5082010-04-22 23:10:45 +00006129 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006130 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006131 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006133
Douglas Gregorf68a5082010-04-22 23:10:45 +00006134 // If nothing changed, just retain this statement.
6135 if (!getDerived().AlwaysRebuild() &&
6136 Element.get() == S->getElement() &&
6137 Collection.get() == S->getCollection() &&
6138 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006139 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006140
Douglas Gregorf68a5082010-04-22 23:10:45 +00006141 // Build a new statement.
6142 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006143 Element.get(),
6144 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006145 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006146 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006147}
6148
David Majnemer5f7efef2013-10-15 09:50:08 +00006149template <typename Derived>
6150StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006151 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006152 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006153 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6154 TypeSourceInfo *T =
6155 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006156 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006157 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006158
David Majnemer5f7efef2013-10-15 09:50:08 +00006159 Var = getDerived().RebuildExceptionDecl(
6160 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6161 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006162 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006163 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006164 }
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006167 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006168 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006170
David Majnemer5f7efef2013-10-15 09:50:08 +00006171 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006173 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006174
David Majnemer5f7efef2013-10-15 09:50:08 +00006175 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006176}
Mike Stump11289f42009-09-09 15:08:12 +00006177
David Majnemer5f7efef2013-10-15 09:50:08 +00006178template <typename Derived>
6179StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006180 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006181 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006182 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 // Transform the handlers.
6186 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006187 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006189 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregorebe10102009-08-20 07:17:43 +00006193 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006194 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 }
Mike Stump11289f42009-09-09 15:08:12 +00006196
David Majnemer5f7efef2013-10-15 09:50:08 +00006197 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006199 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006200
John McCallb268a282010-08-23 23:25:46 +00006201 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006202 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006203}
Mike Stump11289f42009-09-09 15:08:12 +00006204
Richard Smith02e85f32011-04-14 22:09:26 +00006205template<typename Derived>
6206StmtResult
6207TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6208 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6209 if (Range.isInvalid())
6210 return StmtError();
6211
6212 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6213 if (BeginEnd.isInvalid())
6214 return StmtError();
6215
6216 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6217 if (Cond.isInvalid())
6218 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006219 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006220 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006221 if (Cond.isInvalid())
6222 return StmtError();
6223 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006224 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006225
6226 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6227 if (Inc.isInvalid())
6228 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006229 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006230 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006231
6232 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6233 if (LoopVar.isInvalid())
6234 return StmtError();
6235
6236 StmtResult NewStmt = S;
6237 if (getDerived().AlwaysRebuild() ||
6238 Range.get() != S->getRangeStmt() ||
6239 BeginEnd.get() != S->getBeginEndStmt() ||
6240 Cond.get() != S->getCond() ||
6241 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006242 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006243 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6244 S->getColonLoc(), Range.get(),
6245 BeginEnd.get(), Cond.get(),
6246 Inc.get(), LoopVar.get(),
6247 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006248 if (NewStmt.isInvalid())
6249 return StmtError();
6250 }
Richard Smith02e85f32011-04-14 22:09:26 +00006251
6252 StmtResult Body = getDerived().TransformStmt(S->getBody());
6253 if (Body.isInvalid())
6254 return StmtError();
6255
6256 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6257 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006258 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006259 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6260 S->getColonLoc(), Range.get(),
6261 BeginEnd.get(), Cond.get(),
6262 Inc.get(), LoopVar.get(),
6263 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006264 if (NewStmt.isInvalid())
6265 return StmtError();
6266 }
Richard Smith02e85f32011-04-14 22:09:26 +00006267
6268 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006269 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006270
6271 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6272}
6273
John Wiegley1c0675e2011-04-28 01:08:34 +00006274template<typename Derived>
6275StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006276TreeTransform<Derived>::TransformMSDependentExistsStmt(
6277 MSDependentExistsStmt *S) {
6278 // Transform the nested-name-specifier, if any.
6279 NestedNameSpecifierLoc QualifierLoc;
6280 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006281 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006282 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6283 if (!QualifierLoc)
6284 return StmtError();
6285 }
6286
6287 // Transform the declaration name.
6288 DeclarationNameInfo NameInfo = S->getNameInfo();
6289 if (NameInfo.getName()) {
6290 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6291 if (!NameInfo.getName())
6292 return StmtError();
6293 }
6294
6295 // Check whether anything changed.
6296 if (!getDerived().AlwaysRebuild() &&
6297 QualifierLoc == S->getQualifierLoc() &&
6298 NameInfo.getName() == S->getNameInfo().getName())
6299 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006300
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006301 // Determine whether this name exists, if we can.
6302 CXXScopeSpec SS;
6303 SS.Adopt(QualifierLoc);
6304 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006305 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006306 case Sema::IER_Exists:
6307 if (S->isIfExists())
6308 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006309
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006310 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6311
6312 case Sema::IER_DoesNotExist:
6313 if (S->isIfNotExists())
6314 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006316 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006317
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006318 case Sema::IER_Dependent:
6319 Dependent = true;
6320 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006322 case Sema::IER_Error:
6323 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006325
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006326 // We need to continue with the instantiation, so do so now.
6327 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6328 if (SubStmt.isInvalid())
6329 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006330
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006331 // If we have resolved the name, just transform to the substatement.
6332 if (!Dependent)
6333 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006334
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006335 // The name is still dependent, so build a dependent expression again.
6336 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6337 S->isIfExists(),
6338 QualifierLoc,
6339 NameInfo,
6340 SubStmt.get());
6341}
6342
6343template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006344ExprResult
6345TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6346 NestedNameSpecifierLoc QualifierLoc;
6347 if (E->getQualifierLoc()) {
6348 QualifierLoc
6349 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6350 if (!QualifierLoc)
6351 return ExprError();
6352 }
6353
6354 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6355 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6356 if (!PD)
6357 return ExprError();
6358
6359 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6360 if (Base.isInvalid())
6361 return ExprError();
6362
6363 return new (SemaRef.getASTContext())
6364 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6365 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6366 QualifierLoc, E->getMemberLoc());
6367}
6368
David Majnemerfad8f482013-10-15 09:33:02 +00006369template <typename Derived>
6370StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006371 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006372 if (TryBlock.isInvalid())
6373 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006374
6375 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006376 if (Handler.isInvalid())
6377 return StmtError();
6378
David Majnemerfad8f482013-10-15 09:33:02 +00006379 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6380 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006381 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006382
Warren Huntb530bc02014-07-19 00:45:07 +00006383 return getDerived().RebuildSEHTryStmt(
6384 S->getIsCXXTry(), S->getTryLoc(), TryBlock.get(), Handler.get(),
6385 S->getHandlerIndex(), S->getHandlerParentIndex());
John Wiegley1c0675e2011-04-28 01:08:34 +00006386}
6387
David Majnemerfad8f482013-10-15 09:33:02 +00006388template <typename Derived>
6389StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006390 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006391 if (Block.isInvalid())
6392 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006393
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006394 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006395}
6396
David Majnemerfad8f482013-10-15 09:33:02 +00006397template <typename Derived>
6398StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006399 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006400 if (FilterExpr.isInvalid())
6401 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006402
David Majnemer7e755502013-10-15 09:30:14 +00006403 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006404 if (Block.isInvalid())
6405 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006406
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006407 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6408 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006409}
6410
David Majnemerfad8f482013-10-15 09:33:02 +00006411template <typename Derived>
6412StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6413 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006414 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6415 else
6416 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6417}
6418
Nico Weber9b982072014-07-07 00:12:30 +00006419template<typename Derived>
6420StmtResult
6421TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6422 return S;
6423}
6424
Alexander Musman64d33f12014-06-04 07:53:32 +00006425//===----------------------------------------------------------------------===//
6426// OpenMP directive transformation
6427//===----------------------------------------------------------------------===//
6428template <typename Derived>
6429StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6430 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006431
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006432 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006433 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006434 ArrayRef<OMPClause *> Clauses = D->clauses();
6435 TClauses.reserve(Clauses.size());
6436 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6437 I != E; ++I) {
6438 if (*I) {
6439 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006440 if (Clause)
6441 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006442 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006443 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006444 }
6445 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006446 StmtResult AssociatedStmt;
6447 if (D->hasAssociatedStmt()) {
6448 if (!D->getAssociatedStmt()) {
6449 return StmtError();
6450 }
6451 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6452 if (AssociatedStmt.isInvalid()) {
6453 return StmtError();
6454 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006455 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006456 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006457 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006458 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006459
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006460 // Transform directive name for 'omp critical' directive.
6461 DeclarationNameInfo DirName;
6462 if (D->getDirectiveKind() == OMPD_critical) {
6463 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6464 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6465 }
6466
Alexander Musman64d33f12014-06-04 07:53:32 +00006467 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006468 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6469 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006470}
6471
Alexander Musman64d33f12014-06-04 07:53:32 +00006472template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006473StmtResult
6474TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6475 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006476 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6477 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006478 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6479 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6480 return Res;
6481}
6482
Alexander Musman64d33f12014-06-04 07:53:32 +00006483template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006484StmtResult
6485TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6486 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006487 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6488 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006489 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6490 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006491 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006492}
6493
Alexey Bataevf29276e2014-06-18 04:14:57 +00006494template <typename Derived>
6495StmtResult
6496TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6497 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006498 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6499 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006500 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6501 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6502 return Res;
6503}
6504
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006505template <typename Derived>
6506StmtResult
6507TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6508 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006509 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6510 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006511 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6512 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6513 return Res;
6514}
6515
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006516template <typename Derived>
6517StmtResult
6518TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6519 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006520 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6521 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006522 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6523 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6524 return Res;
6525}
6526
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006527template <typename Derived>
6528StmtResult
6529TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6530 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006531 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6532 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006533 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6534 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6535 return Res;
6536}
6537
Alexey Bataev4acb8592014-07-07 13:01:15 +00006538template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006539StmtResult
6540TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6541 DeclarationNameInfo DirName;
6542 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6543 D->getLocStart());
6544 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6545 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6546 return Res;
6547}
6548
6549template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006550StmtResult
6551TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6552 getDerived().getSema().StartOpenMPDSABlock(
6553 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6555 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6556 return Res;
6557}
6558
6559template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006560StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6561 OMPParallelForDirective *D) {
6562 DeclarationNameInfo DirName;
6563 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6564 nullptr, D->getLocStart());
6565 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6566 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6567 return Res;
6568}
6569
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006570template <typename Derived>
6571StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6572 OMPParallelSectionsDirective *D) {
6573 DeclarationNameInfo DirName;
6574 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6575 nullptr, D->getLocStart());
6576 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6577 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6578 return Res;
6579}
6580
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006581template <typename Derived>
6582StmtResult
6583TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6584 DeclarationNameInfo DirName;
6585 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6586 D->getLocStart());
6587 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6588 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6589 return Res;
6590}
6591
Alexey Bataev68446b72014-07-18 07:47:19 +00006592template <typename Derived>
6593StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6594 OMPTaskyieldDirective *D) {
6595 DeclarationNameInfo DirName;
6596 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6597 D->getLocStart());
6598 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6599 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6600 return Res;
6601}
6602
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006603template <typename Derived>
6604StmtResult
6605TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6606 DeclarationNameInfo DirName;
6607 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6608 D->getLocStart());
6609 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6610 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6611 return Res;
6612}
6613
Alexey Bataev2df347a2014-07-18 10:17:07 +00006614template <typename Derived>
6615StmtResult
6616TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6617 DeclarationNameInfo DirName;
6618 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6619 D->getLocStart());
6620 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6621 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6622 return Res;
6623}
6624
Alexey Bataev6125da92014-07-21 11:26:11 +00006625template <typename Derived>
6626StmtResult
6627TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6628 DeclarationNameInfo DirName;
6629 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6630 D->getLocStart());
6631 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6632 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6633 return Res;
6634}
6635
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006636template <typename Derived>
6637StmtResult
6638TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6639 DeclarationNameInfo DirName;
6640 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6641 D->getLocStart());
6642 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6643 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6644 return Res;
6645}
6646
Alexey Bataev0162e452014-07-22 10:10:35 +00006647template <typename Derived>
6648StmtResult
6649TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6650 DeclarationNameInfo DirName;
6651 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6652 D->getLocStart());
6653 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6654 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6655 return Res;
6656}
6657
Alexander Musman64d33f12014-06-04 07:53:32 +00006658//===----------------------------------------------------------------------===//
6659// OpenMP clause transformation
6660//===----------------------------------------------------------------------===//
6661template <typename Derived>
6662OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006663 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6664 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006665 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006666 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006667 C->getLParenLoc(), C->getLocEnd());
6668}
6669
Alexander Musman64d33f12014-06-04 07:53:32 +00006670template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006671OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6672 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6673 if (Cond.isInvalid())
6674 return nullptr;
6675 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6676 C->getLParenLoc(), C->getLocEnd());
6677}
6678
6679template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006680OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006681TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6682 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6683 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006684 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006685 return getDerived().RebuildOMPNumThreadsClause(
6686 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006687}
6688
Alexey Bataev62c87d22014-03-21 04:51:18 +00006689template <typename Derived>
6690OMPClause *
6691TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6692 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6693 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006694 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006695 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006696 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006697}
6698
Alexander Musman8bd31e62014-05-27 15:12:19 +00006699template <typename Derived>
6700OMPClause *
6701TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6702 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6703 if (E.isInvalid())
6704 return 0;
6705 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006706 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006707}
6708
Alexander Musman64d33f12014-06-04 07:53:32 +00006709template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006710OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006711TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006712 return getDerived().RebuildOMPDefaultClause(
6713 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6714 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006715}
6716
Alexander Musman64d33f12014-06-04 07:53:32 +00006717template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006718OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006719TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006720 return getDerived().RebuildOMPProcBindClause(
6721 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6722 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006723}
6724
Alexander Musman64d33f12014-06-04 07:53:32 +00006725template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006726OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006727TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6728 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6729 if (E.isInvalid())
6730 return nullptr;
6731 return getDerived().RebuildOMPScheduleClause(
6732 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6733 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6734}
6735
6736template <typename Derived>
6737OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006738TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6739 // No need to rebuild this clause, no template-dependent parameters.
6740 return C;
6741}
6742
6743template <typename Derived>
6744OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006745TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6746 // No need to rebuild this clause, no template-dependent parameters.
6747 return C;
6748}
6749
6750template <typename Derived>
6751OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006752TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6753 // No need to rebuild this clause, no template-dependent parameters.
6754 return C;
6755}
6756
6757template <typename Derived>
6758OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006759TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6760 // No need to rebuild this clause, no template-dependent parameters.
6761 return C;
6762}
6763
6764template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006765OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6766 // No need to rebuild this clause, no template-dependent parameters.
6767 return C;
6768}
6769
6770template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006771OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6772 // No need to rebuild this clause, no template-dependent parameters.
6773 return C;
6774}
6775
6776template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006777OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006778TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6779 // No need to rebuild this clause, no template-dependent parameters.
6780 return C;
6781}
6782
6783template <typename Derived>
6784OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006785TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6786 // No need to rebuild this clause, no template-dependent parameters.
6787 return C;
6788}
6789
6790template <typename Derived>
6791OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006792TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6793 // No need to rebuild this clause, no template-dependent parameters.
6794 return C;
6795}
6796
6797template <typename Derived>
6798OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006799TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006800 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006801 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006802 for (auto *VE : C->varlists()) {
6803 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006804 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006805 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006806 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006807 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006808 return getDerived().RebuildOMPPrivateClause(
6809 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006810}
6811
Alexander Musman64d33f12014-06-04 07:53:32 +00006812template <typename Derived>
6813OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6814 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006815 llvm::SmallVector<Expr *, 16> Vars;
6816 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006817 for (auto *VE : C->varlists()) {
6818 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006819 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006820 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006821 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006822 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006823 return getDerived().RebuildOMPFirstprivateClause(
6824 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006825}
6826
Alexander Musman64d33f12014-06-04 07:53:32 +00006827template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006828OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006829TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6830 llvm::SmallVector<Expr *, 16> Vars;
6831 Vars.reserve(C->varlist_size());
6832 for (auto *VE : C->varlists()) {
6833 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6834 if (EVar.isInvalid())
6835 return nullptr;
6836 Vars.push_back(EVar.get());
6837 }
6838 return getDerived().RebuildOMPLastprivateClause(
6839 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6840}
6841
6842template <typename Derived>
6843OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006844TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6845 llvm::SmallVector<Expr *, 16> Vars;
6846 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006847 for (auto *VE : C->varlists()) {
6848 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006849 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006850 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006851 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006852 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006853 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6854 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006855}
6856
Alexander Musman64d33f12014-06-04 07:53:32 +00006857template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006858OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006859TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6860 llvm::SmallVector<Expr *, 16> Vars;
6861 Vars.reserve(C->varlist_size());
6862 for (auto *VE : C->varlists()) {
6863 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6864 if (EVar.isInvalid())
6865 return nullptr;
6866 Vars.push_back(EVar.get());
6867 }
6868 CXXScopeSpec ReductionIdScopeSpec;
6869 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6870
6871 DeclarationNameInfo NameInfo = C->getNameInfo();
6872 if (NameInfo.getName()) {
6873 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6874 if (!NameInfo.getName())
6875 return nullptr;
6876 }
6877 return getDerived().RebuildOMPReductionClause(
6878 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6879 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6880}
6881
6882template <typename Derived>
6883OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006884TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6885 llvm::SmallVector<Expr *, 16> Vars;
6886 Vars.reserve(C->varlist_size());
6887 for (auto *VE : C->varlists()) {
6888 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6889 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006890 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006891 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006892 }
6893 ExprResult Step = getDerived().TransformExpr(C->getStep());
6894 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006895 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006896 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6897 C->getLParenLoc(),
6898 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006899}
6900
Alexander Musman64d33f12014-06-04 07:53:32 +00006901template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006902OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006903TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6904 llvm::SmallVector<Expr *, 16> Vars;
6905 Vars.reserve(C->varlist_size());
6906 for (auto *VE : C->varlists()) {
6907 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6908 if (EVar.isInvalid())
6909 return nullptr;
6910 Vars.push_back(EVar.get());
6911 }
6912 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6913 if (Alignment.isInvalid())
6914 return nullptr;
6915 return getDerived().RebuildOMPAlignedClause(
6916 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6917 C->getColonLoc(), C->getLocEnd());
6918}
6919
Alexander Musman64d33f12014-06-04 07:53:32 +00006920template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006921OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006922TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6923 llvm::SmallVector<Expr *, 16> Vars;
6924 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006925 for (auto *VE : C->varlists()) {
6926 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006927 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006928 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006929 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006930 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006931 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6932 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006933}
6934
Alexey Bataevbae9a792014-06-27 10:37:06 +00006935template <typename Derived>
6936OMPClause *
6937TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6938 llvm::SmallVector<Expr *, 16> Vars;
6939 Vars.reserve(C->varlist_size());
6940 for (auto *VE : C->varlists()) {
6941 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6942 if (EVar.isInvalid())
6943 return nullptr;
6944 Vars.push_back(EVar.get());
6945 }
6946 return getDerived().RebuildOMPCopyprivateClause(
6947 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6948}
6949
Alexey Bataev6125da92014-07-21 11:26:11 +00006950template <typename Derived>
6951OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6952 llvm::SmallVector<Expr *, 16> Vars;
6953 Vars.reserve(C->varlist_size());
6954 for (auto *VE : C->varlists()) {
6955 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6956 if (EVar.isInvalid())
6957 return nullptr;
6958 Vars.push_back(EVar.get());
6959 }
6960 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6961 C->getLParenLoc(), C->getLocEnd());
6962}
6963
Douglas Gregorebe10102009-08-20 07:17:43 +00006964//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006965// Expression transformation
6966//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006969TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006970 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006971}
Mike Stump11289f42009-09-09 15:08:12 +00006972
6973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006975TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006976 NestedNameSpecifierLoc QualifierLoc;
6977 if (E->getQualifierLoc()) {
6978 QualifierLoc
6979 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6980 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006981 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006982 }
John McCallce546572009-12-08 09:08:17 +00006983
6984 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006985 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6986 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006987 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006989
John McCall815039a2010-08-17 21:27:17 +00006990 DeclarationNameInfo NameInfo = E->getNameInfo();
6991 if (NameInfo.getName()) {
6992 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6993 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006994 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006995 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006996
6997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006998 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006999 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007000 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007001 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007002
7003 // Mark it referenced in the new context regardless.
7004 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007005 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007006
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007007 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007008 }
John McCallce546572009-12-08 09:08:17 +00007009
Craig Topperc3ec1492014-05-26 06:22:03 +00007010 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007011 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007012 TemplateArgs = &TransArgs;
7013 TransArgs.setLAngleLoc(E->getLAngleLoc());
7014 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007015 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7016 E->getNumTemplateArgs(),
7017 TransArgs))
7018 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007019 }
7020
Chad Rosier1dcde962012-08-08 18:46:20 +00007021 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007022 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007023}
Mike Stump11289f42009-09-09 15:08:12 +00007024
Douglas Gregora16548e2009-08-11 05:31:07 +00007025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007028 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007029}
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregora16548e2009-08-11 05:31:07 +00007031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007033TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007034 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007035}
Mike Stump11289f42009-09-09 15:08:12 +00007036
Douglas Gregora16548e2009-08-11 05:31:07 +00007037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007039TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007040 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007041}
Mike Stump11289f42009-09-09 15:08:12 +00007042
Douglas Gregora16548e2009-08-11 05:31:07 +00007043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007045TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007046 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007047}
Mike Stump11289f42009-09-09 15:08:12 +00007048
Douglas Gregora16548e2009-08-11 05:31:07 +00007049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007051TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007052 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007053}
7054
7055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007056ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007057TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007058 if (FunctionDecl *FD = E->getDirectCallee())
7059 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007060 return SemaRef.MaybeBindToTemporary(E);
7061}
7062
7063template<typename Derived>
7064ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007065TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7066 ExprResult ControllingExpr =
7067 getDerived().TransformExpr(E->getControllingExpr());
7068 if (ControllingExpr.isInvalid())
7069 return ExprError();
7070
Chris Lattner01cf8db2011-07-20 06:58:45 +00007071 SmallVector<Expr *, 4> AssocExprs;
7072 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007073 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7074 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7075 if (TS) {
7076 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7077 if (!AssocType)
7078 return ExprError();
7079 AssocTypes.push_back(AssocType);
7080 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007081 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007082 }
7083
7084 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7085 if (AssocExpr.isInvalid())
7086 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007087 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007088 }
7089
7090 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7091 E->getDefaultLoc(),
7092 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007093 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007094 AssocTypes,
7095 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007096}
7097
7098template<typename Derived>
7099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007100TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007102 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007106 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007107
John McCallb268a282010-08-23 23:25:46 +00007108 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 E->getRParen());
7110}
7111
Richard Smithdb2630f2012-10-21 03:28:35 +00007112/// \brief The operand of a unary address-of operator has special rules: it's
7113/// allowed to refer to a non-static member of a class even if there's no 'this'
7114/// object available.
7115template<typename Derived>
7116ExprResult
7117TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7118 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007119 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007120 else
7121 return getDerived().TransformExpr(E);
7122}
7123
Mike Stump11289f42009-09-09 15:08:12 +00007124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007126TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007127 ExprResult SubExpr;
7128 if (E->getOpcode() == UO_AddrOf)
7129 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7130 else
7131 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007136 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7139 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007140 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007141}
Mike Stump11289f42009-09-09 15:08:12 +00007142
Douglas Gregora16548e2009-08-11 05:31:07 +00007143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007144ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007145TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7146 // Transform the type.
7147 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7148 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007150
Douglas Gregor882211c2010-04-28 22:16:22 +00007151 // Transform all of the components into components similar to what the
7152 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007153 // FIXME: It would be slightly more efficient in the non-dependent case to
7154 // just map FieldDecls, rather than requiring the rebuilder to look for
7155 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007156 // template code that we don't care.
7157 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007158 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007159 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007160 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007161 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7162 const Node &ON = E->getComponent(I);
7163 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007164 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007165 Comp.LocStart = ON.getSourceRange().getBegin();
7166 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007167 switch (ON.getKind()) {
7168 case Node::Array: {
7169 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007170 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007171 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007173
Douglas Gregor882211c2010-04-28 22:16:22 +00007174 ExprChanged = ExprChanged || Index.get() != FromIndex;
7175 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007176 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007177 break;
7178 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007179
Douglas Gregor882211c2010-04-28 22:16:22 +00007180 case Node::Field:
7181 case Node::Identifier:
7182 Comp.isBrackets = false;
7183 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007184 if (!Comp.U.IdentInfo)
7185 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007186
Douglas Gregor882211c2010-04-28 22:16:22 +00007187 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007188
Douglas Gregord1702062010-04-29 00:18:15 +00007189 case Node::Base:
7190 // Will be recomputed during the rebuild.
7191 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007192 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007193
Douglas Gregor882211c2010-04-28 22:16:22 +00007194 Components.push_back(Comp);
7195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007196
Douglas Gregor882211c2010-04-28 22:16:22 +00007197 // If nothing changed, retain the existing expression.
7198 if (!getDerived().AlwaysRebuild() &&
7199 Type == E->getTypeSourceInfo() &&
7200 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007201 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007202
Douglas Gregor882211c2010-04-28 22:16:22 +00007203 // Build a new offsetof expression.
7204 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7205 Components.data(), Components.size(),
7206 E->getRParenLoc());
7207}
7208
7209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007210ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007211TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7212 assert(getDerived().AlreadyTransformed(E->getType()) &&
7213 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007214 return E;
John McCall8d69a212010-11-15 23:31:06 +00007215}
7216
7217template<typename Derived>
7218ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007219TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007220 // Rebuild the syntactic form. The original syntactic form has
7221 // opaque-value expressions in it, so strip those away and rebuild
7222 // the result. This is a really awful way of doing this, but the
7223 // better solution (rebuilding the semantic expressions and
7224 // rebinding OVEs as necessary) doesn't work; we'd need
7225 // TreeTransform to not strip away implicit conversions.
7226 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7227 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007228 if (result.isInvalid()) return ExprError();
7229
7230 // If that gives us a pseudo-object result back, the pseudo-object
7231 // expression must have been an lvalue-to-rvalue conversion which we
7232 // should reapply.
7233 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007234 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007235
7236 return result;
7237}
7238
7239template<typename Derived>
7240ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007241TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7242 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007243 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007244 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007245
John McCallbcd03502009-12-07 02:54:59 +00007246 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007247 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007249
John McCall4c98fd82009-11-04 07:28:41 +00007250 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007251 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007252
Peter Collingbournee190dee2011-03-11 19:24:49 +00007253 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7254 E->getKind(),
7255 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007256 }
Mike Stump11289f42009-09-09 15:08:12 +00007257
Eli Friedmane4f22df2012-02-29 04:03:55 +00007258 // C++0x [expr.sizeof]p1:
7259 // The operand is either an expression, which is an unevaluated operand
7260 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007261 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7262 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007263
Reid Kleckner32506ed2014-06-12 23:03:48 +00007264 // Try to recover if we have something like sizeof(T::X) where X is a type.
7265 // Notably, there must be *exactly* one set of parens if X is a type.
7266 TypeSourceInfo *RecoveryTSI = nullptr;
7267 ExprResult SubExpr;
7268 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7269 if (auto *DRE =
7270 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7271 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7272 PE, DRE, false, &RecoveryTSI);
7273 else
7274 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7275
7276 if (RecoveryTSI) {
7277 return getDerived().RebuildUnaryExprOrTypeTrait(
7278 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7279 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007281
Eli Friedmane4f22df2012-02-29 04:03:55 +00007282 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007283 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007284
Peter Collingbournee190dee2011-03-11 19:24:49 +00007285 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7286 E->getOperatorLoc(),
7287 E->getKind(),
7288 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007289}
Mike Stump11289f42009-09-09 15:08:12 +00007290
Douglas Gregora16548e2009-08-11 05:31:07 +00007291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007297
John McCalldadc5752010-08-24 06:29:42 +00007298 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007301
7302
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
7304 LHS.get() == E->getLHS() &&
7305 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007306 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007307
John McCallb268a282010-08-23 23:25:46 +00007308 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007309 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007310 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007311 E->getRBracketLoc());
7312}
Mike Stump11289f42009-09-09 15:08:12 +00007313
7314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007318 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007319 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007321
7322 // Transform arguments.
7323 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007324 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007325 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007326 &ArgChanged))
7327 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007328
Douglas Gregora16548e2009-08-11 05:31:07 +00007329 if (!getDerived().AlwaysRebuild() &&
7330 Callee.get() == E->getCallee() &&
7331 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007332 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007335 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007337 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007338 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007339 E->getRParenLoc());
7340}
Mike Stump11289f42009-09-09 15:08:12 +00007341
7342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007344TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007345 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007346 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007348
Douglas Gregorea972d32011-02-28 21:54:11 +00007349 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007350 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007351 QualifierLoc
7352 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007353
Douglas Gregorea972d32011-02-28 21:54:11 +00007354 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007355 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007356 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007357 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007358
Eli Friedman2cfcef62009-12-04 06:40:45 +00007359 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007360 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7361 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007364
John McCall16df1e52010-03-30 21:47:33 +00007365 NamedDecl *FoundDecl = E->getFoundDecl();
7366 if (FoundDecl == E->getMemberDecl()) {
7367 FoundDecl = Member;
7368 } else {
7369 FoundDecl = cast_or_null<NamedDecl>(
7370 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7371 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007372 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007373 }
7374
Douglas Gregora16548e2009-08-11 05:31:07 +00007375 if (!getDerived().AlwaysRebuild() &&
7376 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007377 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007378 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007379 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007380 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007381
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007382 // Mark it referenced in the new context regardless.
7383 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007384 SemaRef.MarkMemberReferenced(E);
7385
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007386 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007387 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007388
John McCall6b51f282009-11-23 01:53:49 +00007389 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007390 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007391 TransArgs.setLAngleLoc(E->getLAngleLoc());
7392 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007393 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7394 E->getNumTemplateArgs(),
7395 TransArgs))
7396 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007398
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007400 SourceLocation FakeOperatorLoc =
7401 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007402
John McCall38836f02010-01-15 08:34:02 +00007403 // FIXME: to do this check properly, we will need to preserve the
7404 // first-qualifier-in-scope here, just in case we had a dependent
7405 // base (and therefore couldn't do the check) and a
7406 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007407 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007408
John McCallb268a282010-08-23 23:25:46 +00007409 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007410 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007411 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007412 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007413 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007414 Member,
John McCall16df1e52010-03-30 21:47:33 +00007415 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007416 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007417 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007418 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007419}
Mike Stump11289f42009-09-09 15:08:12 +00007420
Douglas Gregora16548e2009-08-11 05:31:07 +00007421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007423TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007424 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
John McCalldadc5752010-08-24 06:29:42 +00007428 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 if (!getDerived().AlwaysRebuild() &&
7433 LHS.get() == E->getLHS() &&
7434 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007435 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007436
Lang Hames5de91cc2012-10-02 04:45:10 +00007437 Sema::FPContractStateRAII FPContractState(getSema());
7438 getSema().FPFeatures.fp_contract = E->isFPContractable();
7439
Douglas Gregora16548e2009-08-11 05:31:07 +00007440 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007441 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007442}
7443
Mike Stump11289f42009-09-09 15:08:12 +00007444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007445ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007446TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007447 CompoundAssignOperator *E) {
7448 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007449}
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007452ExprResult TreeTransform<Derived>::
7453TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7454 // Just rebuild the common and RHS expressions and see whether we
7455 // get any changes.
7456
7457 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7458 if (commonExpr.isInvalid())
7459 return ExprError();
7460
7461 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7462 if (rhs.isInvalid())
7463 return ExprError();
7464
7465 if (!getDerived().AlwaysRebuild() &&
7466 commonExpr.get() == e->getCommon() &&
7467 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007468 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007469
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007470 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007471 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007472 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007473 e->getColonLoc(),
7474 rhs.get());
7475}
7476
7477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007478ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007479TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007480 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007481 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007483
John McCalldadc5752010-08-24 06:29:42 +00007484 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007485 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007487
John McCalldadc5752010-08-24 06:29:42 +00007488 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007489 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007491
Douglas Gregora16548e2009-08-11 05:31:07 +00007492 if (!getDerived().AlwaysRebuild() &&
7493 Cond.get() == E->getCond() &&
7494 LHS.get() == E->getLHS() &&
7495 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007496 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007497
John McCallb268a282010-08-23 23:25:46 +00007498 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007499 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007500 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007501 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007502 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007503}
Mike Stump11289f42009-09-09 15:08:12 +00007504
7505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007506ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007507TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007508 // Implicit casts are eliminated during transformation, since they
7509 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007510 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007511}
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregora16548e2009-08-11 05:31:07 +00007513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007515TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007516 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7517 if (!Type)
7518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007519
John McCalldadc5752010-08-24 06:29:42 +00007520 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007521 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007522 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007524
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007526 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007528 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007529
John McCall97513962010-01-15 18:39:57 +00007530 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007531 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007532 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007533 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007534}
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregora16548e2009-08-11 05:31:07 +00007536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007538TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007539 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7540 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7541 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007543
John McCalldadc5752010-08-24 06:29:42 +00007544 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007549 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007550 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007551 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007552
John McCall5d7aa7f2010-01-19 22:33:45 +00007553 // Note: the expression type doesn't necessarily match the
7554 // type-as-written, but that's okay, because it should always be
7555 // derivable from the initializer.
7556
John McCalle15bbff2010-01-18 19:35:47 +00007557 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007558 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007559 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007560}
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregora16548e2009-08-11 05:31:07 +00007562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007563ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007564TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007565 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 if (!getDerived().AlwaysRebuild() &&
7570 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007571 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007572
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007574 SourceLocation FakeOperatorLoc =
7575 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007576 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 E->getAccessorLoc(),
7578 E->getAccessor());
7579}
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007583TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007584 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007585
Benjamin Kramerf0623432012-08-23 22:51:59 +00007586 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007587 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007588 Inits, &InitChanged))
7589 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007590
Douglas Gregora16548e2009-08-11 05:31:07 +00007591 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007592 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007593
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007594 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007595 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007596}
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregora16548e2009-08-11 05:31:07 +00007598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007600TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007602
Douglas Gregorebe10102009-08-20 07:17:43 +00007603 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007604 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007607
Douglas Gregorebe10102009-08-20 07:17:43 +00007608 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007609 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007610 bool ExprChanged = false;
7611 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7612 DEnd = E->designators_end();
7613 D != DEnd; ++D) {
7614 if (D->isFieldDesignator()) {
7615 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7616 D->getDotLoc(),
7617 D->getFieldLoc()));
7618 continue;
7619 }
Mike Stump11289f42009-09-09 15:08:12 +00007620
Douglas Gregora16548e2009-08-11 05:31:07 +00007621 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007622 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007625
7626 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007627 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007628
Douglas Gregora16548e2009-08-11 05:31:07 +00007629 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007630 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 continue;
7632 }
Mike Stump11289f42009-09-09 15:08:12 +00007633
Douglas Gregora16548e2009-08-11 05:31:07 +00007634 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007635 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7637 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007639
John McCalldadc5752010-08-24 06:29:42 +00007640 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007641 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007642 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007643
7644 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007645 End.get(),
7646 D->getLBracketLoc(),
7647 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregora16548e2009-08-11 05:31:07 +00007649 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7650 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007651
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007652 ArrayExprs.push_back(Start.get());
7653 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007654 }
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 if (!getDerived().AlwaysRebuild() &&
7657 Init.get() == E->getInit() &&
7658 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007659 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007660
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007661 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007663 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007664}
Mike Stump11289f42009-09-09 15:08:12 +00007665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007667ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007668TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007669 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007670 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007671
Douglas Gregor3da3c062009-10-28 00:29:27 +00007672 // FIXME: Will we ever have proper type location here? Will we actually
7673 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 QualType T = getDerived().TransformType(E->getType());
7675 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 if (!getDerived().AlwaysRebuild() &&
7679 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007680 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregora16548e2009-08-11 05:31:07 +00007682 return getDerived().RebuildImplicitValueInitExpr(T);
7683}
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007686ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007687TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007688 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7689 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007691
John McCalldadc5752010-08-24 06:29:42 +00007692 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007697 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007699 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007700
John McCallb268a282010-08-23 23:25:46 +00007701 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007702 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007703}
7704
7705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007706ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007707TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007709 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007710 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7711 &ArgumentChanged))
7712 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007713
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007715 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 E->getRParenLoc());
7717}
Mike Stump11289f42009-09-09 15:08:12 +00007718
Douglas Gregora16548e2009-08-11 05:31:07 +00007719/// \brief Transform an address-of-label expression.
7720///
7721/// By default, the transformation of an address-of-label expression always
7722/// rebuilds the expression, so that the label identifier can be resolved to
7723/// the corresponding label statement by semantic analysis.
7724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007726TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007727 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7728 E->getLabel());
7729 if (!LD)
7730 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007731
Douglas Gregora16548e2009-08-11 05:31:07 +00007732 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007733 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007734}
Mike Stump11289f42009-09-09 15:08:12 +00007735
7736template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007738TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007739 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007740 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007741 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007742 if (SubStmt.isInvalid()) {
7743 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007744 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007745 }
Mike Stump11289f42009-09-09 15:08:12 +00007746
Douglas Gregora16548e2009-08-11 05:31:07 +00007747 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007748 SubStmt.get() == E->getSubStmt()) {
7749 // Calling this an 'error' is unintuitive, but it does the right thing.
7750 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007751 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007752 }
Mike Stump11289f42009-09-09 15:08:12 +00007753
7754 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007755 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007756 E->getRParenLoc());
7757}
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007761TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007762 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007763 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007765
John McCalldadc5752010-08-24 06:29:42 +00007766 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007769
John McCalldadc5752010-08-24 06:29:42 +00007770 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007771 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007773
Douglas Gregora16548e2009-08-11 05:31:07 +00007774 if (!getDerived().AlwaysRebuild() &&
7775 Cond.get() == E->getCond() &&
7776 LHS.get() == E->getLHS() &&
7777 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007778 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007779
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007781 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007782 E->getRParenLoc());
7783}
Mike Stump11289f42009-09-09 15:08:12 +00007784
Douglas Gregora16548e2009-08-11 05:31:07 +00007785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007787TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007788 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007789}
7790
7791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007793TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007794 switch (E->getOperator()) {
7795 case OO_New:
7796 case OO_Delete:
7797 case OO_Array_New:
7798 case OO_Array_Delete:
7799 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007800
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007801 case OO_Call: {
7802 // This is a call to an object's operator().
7803 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7804
7805 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007806 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007807 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007808 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007809
7810 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007811 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7812 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007813
7814 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007815 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007816 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007817 Args))
7818 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007819
John McCallb268a282010-08-23 23:25:46 +00007820 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007821 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007822 E->getLocEnd());
7823 }
7824
7825#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7826 case OO_##Name:
7827#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7828#include "clang/Basic/OperatorKinds.def"
7829 case OO_Subscript:
7830 // Handled below.
7831 break;
7832
7833 case OO_Conditional:
7834 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007835
7836 case OO_None:
7837 case NUM_OVERLOADED_OPERATORS:
7838 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007839 }
7840
John McCalldadc5752010-08-24 06:29:42 +00007841 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007842 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007844
Richard Smithdb2630f2012-10-21 03:28:35 +00007845 ExprResult First;
7846 if (E->getOperator() == OO_Amp)
7847 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7848 else
7849 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007850 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007851 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007852
John McCalldadc5752010-08-24 06:29:42 +00007853 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 if (E->getNumArgs() == 2) {
7855 Second = getDerived().TransformExpr(E->getArg(1));
7856 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007857 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 }
Mike Stump11289f42009-09-09 15:08:12 +00007859
Douglas Gregora16548e2009-08-11 05:31:07 +00007860 if (!getDerived().AlwaysRebuild() &&
7861 Callee.get() == E->getCallee() &&
7862 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007863 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007864 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007865
Lang Hames5de91cc2012-10-02 04:45:10 +00007866 Sema::FPContractStateRAII FPContractState(getSema());
7867 getSema().FPFeatures.fp_contract = E->isFPContractable();
7868
Douglas Gregora16548e2009-08-11 05:31:07 +00007869 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7870 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007871 Callee.get(),
7872 First.get(),
7873 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007874}
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregora16548e2009-08-11 05:31:07 +00007876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007878TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7879 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007880}
Mike Stump11289f42009-09-09 15:08:12 +00007881
Douglas Gregora16548e2009-08-11 05:31:07 +00007882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007883ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007884TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7885 // Transform the callee.
7886 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7887 if (Callee.isInvalid())
7888 return ExprError();
7889
7890 // Transform exec config.
7891 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7892 if (EC.isInvalid())
7893 return ExprError();
7894
7895 // Transform arguments.
7896 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007897 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007898 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007899 &ArgChanged))
7900 return ExprError();
7901
7902 if (!getDerived().AlwaysRebuild() &&
7903 Callee.get() == E->getCallee() &&
7904 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007905 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007906
7907 // FIXME: Wrong source location information for the '('.
7908 SourceLocation FakeLParenLoc
7909 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7910 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007911 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007912 E->getRParenLoc(), EC.get());
7913}
7914
7915template<typename Derived>
7916ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007917TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007918 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7919 if (!Type)
7920 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007921
John McCalldadc5752010-08-24 06:29:42 +00007922 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007923 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007926
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007928 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007930 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007932 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007933 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007934 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007935 E->getAngleBrackets().getEnd(),
7936 // FIXME. this should be '(' location
7937 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007938 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007939 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007940}
Mike Stump11289f42009-09-09 15:08:12 +00007941
Douglas Gregora16548e2009-08-11 05:31:07 +00007942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007944TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7945 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007946}
Mike Stump11289f42009-09-09 15:08:12 +00007947
7948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007950TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7951 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007952}
7953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007955ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007956TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007957 CXXReinterpretCastExpr *E) {
7958 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007959}
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007963TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7964 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007965}
Mike Stump11289f42009-09-09 15:08:12 +00007966
Douglas Gregora16548e2009-08-11 05:31:07 +00007967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007968ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007969TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007970 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007971 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7972 if (!Type)
7973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007974
John McCalldadc5752010-08-24 06:29:42 +00007975 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007976 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007979
Douglas Gregora16548e2009-08-11 05:31:07 +00007980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007981 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007982 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007983 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007984
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007985 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007986 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007987 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007988 E->getRParenLoc());
7989}
Mike Stump11289f42009-09-09 15:08:12 +00007990
Douglas Gregora16548e2009-08-11 05:31:07 +00007991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007993TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007995 TypeSourceInfo *TInfo
7996 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7997 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007998 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007999
Douglas Gregora16548e2009-08-11 05:31:07 +00008000 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008001 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008002 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008003
Douglas Gregor9da64192010-04-26 22:37:10 +00008004 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8005 E->getLocStart(),
8006 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008007 E->getLocEnd());
8008 }
Mike Stump11289f42009-09-09 15:08:12 +00008009
Eli Friedman456f0182012-01-20 01:26:23 +00008010 // We don't know whether the subexpression is potentially evaluated until
8011 // after we perform semantic analysis. We speculatively assume it is
8012 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008013 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008014 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8015 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008016
John McCalldadc5752010-08-24 06:29:42 +00008017 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008020
Douglas Gregora16548e2009-08-11 05:31:07 +00008021 if (!getDerived().AlwaysRebuild() &&
8022 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008023 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008024
Douglas Gregor9da64192010-04-26 22:37:10 +00008025 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8026 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008027 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008028 E->getLocEnd());
8029}
8030
8031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008032ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008033TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8034 if (E->isTypeOperand()) {
8035 TypeSourceInfo *TInfo
8036 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8037 if (!TInfo)
8038 return ExprError();
8039
8040 if (!getDerived().AlwaysRebuild() &&
8041 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008042 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008043
Douglas Gregor69735112011-03-06 17:40:41 +00008044 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008045 E->getLocStart(),
8046 TInfo,
8047 E->getLocEnd());
8048 }
8049
Francois Pichet9f4f2072010-09-08 12:20:18 +00008050 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8051
8052 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8053 if (SubExpr.isInvalid())
8054 return ExprError();
8055
8056 if (!getDerived().AlwaysRebuild() &&
8057 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008058 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008059
8060 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8061 E->getLocStart(),
8062 SubExpr.get(),
8063 E->getLocEnd());
8064}
8065
8066template<typename Derived>
8067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008068TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008069 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008070}
Mike Stump11289f42009-09-09 15:08:12 +00008071
Douglas Gregora16548e2009-08-11 05:31:07 +00008072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008073ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008074TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008075 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008076 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008077}
Mike Stump11289f42009-09-09 15:08:12 +00008078
Douglas Gregora16548e2009-08-11 05:31:07 +00008079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008080ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008081TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008082 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008083
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008084 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8085 // Make sure that we capture 'this'.
8086 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008087 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008089
Douglas Gregorb15af892010-01-07 23:12:05 +00008090 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008091}
Mike Stump11289f42009-09-09 15:08:12 +00008092
Douglas Gregora16548e2009-08-11 05:31:07 +00008093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008096 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008097 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008099
Douglas Gregora16548e2009-08-11 05:31:07 +00008100 if (!getDerived().AlwaysRebuild() &&
8101 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008103
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008104 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8105 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008106}
Mike Stump11289f42009-09-09 15:08:12 +00008107
Douglas Gregora16548e2009-08-11 05:31:07 +00008108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008111 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008112 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8113 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008114 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008116
Chandler Carruth794da4c2010-02-08 06:42:49 +00008117 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008118 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008119 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008120
Douglas Gregor033f6752009-12-23 23:03:06 +00008121 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008122}
Mike Stump11289f42009-09-09 15:08:12 +00008123
Douglas Gregora16548e2009-08-11 05:31:07 +00008124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008125ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008126TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8127 FieldDecl *Field
8128 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8129 E->getField()));
8130 if (!Field)
8131 return ExprError();
8132
8133 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008134 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008135
8136 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8137}
8138
8139template<typename Derived>
8140ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008141TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8142 CXXScalarValueInitExpr *E) {
8143 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8144 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008145 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008148 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008149 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008150
Chad Rosier1dcde962012-08-08 18:46:20 +00008151 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008152 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008153 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008154}
Mike Stump11289f42009-09-09 15:08:12 +00008155
Douglas Gregora16548e2009-08-11 05:31:07 +00008156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008158TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008159 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008160 TypeSourceInfo *AllocTypeInfo
8161 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8162 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008164
Douglas Gregora16548e2009-08-11 05:31:07 +00008165 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008166 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 // Transform the placement arguments (if any).
8171 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008172 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008173 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008174 E->getNumPlacementArgs(), true,
8175 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008176 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008177
Sebastian Redl6047f072012-02-16 12:22:20 +00008178 // Transform the initializer (if any).
8179 Expr *OldInit = E->getInitializer();
8180 ExprResult NewInit;
8181 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008182 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008183 if (NewInit.isInvalid())
8184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008185
Sebastian Redl6047f072012-02-16 12:22:20 +00008186 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008187 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008188 if (E->getOperatorNew()) {
8189 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008190 getDerived().TransformDecl(E->getLocStart(),
8191 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008192 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008193 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008194 }
8195
Craig Topperc3ec1492014-05-26 06:22:03 +00008196 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008197 if (E->getOperatorDelete()) {
8198 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008199 getDerived().TransformDecl(E->getLocStart(),
8200 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008201 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008202 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008204
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008206 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008207 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008208 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008209 OperatorNew == E->getOperatorNew() &&
8210 OperatorDelete == E->getOperatorDelete() &&
8211 !ArgumentChanged) {
8212 // Mark any declarations we need as referenced.
8213 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008214 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008215 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008216 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008217 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008218
Sebastian Redl6047f072012-02-16 12:22:20 +00008219 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008220 QualType ElementType
8221 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8222 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8223 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8224 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008225 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008226 }
8227 }
8228 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008229
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008230 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008231 }
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregor0744ef62010-09-07 21:49:58 +00008233 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008234 if (!ArraySize.get()) {
8235 // If no array size was specified, but the new expression was
8236 // instantiated with an array type (e.g., "new T" where T is
8237 // instantiated with "int[4]"), extract the outer bound from the
8238 // array type as our array size. We do this with constant and
8239 // dependently-sized array types.
8240 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8241 if (!ArrayT) {
8242 // Do nothing
8243 } else if (const ConstantArrayType *ConsArrayT
8244 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008245 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8246 SemaRef.Context.getSizeType(),
8247 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008248 AllocType = ConsArrayT->getElementType();
8249 } else if (const DependentSizedArrayType *DepArrayT
8250 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8251 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008252 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008253 AllocType = DepArrayT->getElementType();
8254 }
8255 }
8256 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008257
Douglas Gregora16548e2009-08-11 05:31:07 +00008258 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8259 E->isGlobalNew(),
8260 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008261 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008263 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008264 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008265 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008266 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008267 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008268 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008269}
Mike Stump11289f42009-09-09 15:08:12 +00008270
Douglas Gregora16548e2009-08-11 05:31:07 +00008271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008273TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008274 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008275 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008277
Douglas Gregord2d9da02010-02-26 00:38:10 +00008278 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008279 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008280 if (E->getOperatorDelete()) {
8281 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008282 getDerived().TransformDecl(E->getLocStart(),
8283 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008284 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008285 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008287
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008289 Operand.get() == E->getArgument() &&
8290 OperatorDelete == E->getOperatorDelete()) {
8291 // Mark any declarations we need as referenced.
8292 // FIXME: instantiation-specific.
8293 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008294 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008295
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008296 if (!E->getArgument()->isTypeDependent()) {
8297 QualType Destroyed = SemaRef.Context.getBaseElementType(
8298 E->getDestroyedType());
8299 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8300 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008301 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008302 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008303 }
8304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008305
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008306 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008307 }
Mike Stump11289f42009-09-09 15:08:12 +00008308
Douglas Gregora16548e2009-08-11 05:31:07 +00008309 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8310 E->isGlobalDelete(),
8311 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008312 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008313}
Mike Stump11289f42009-09-09 15:08:12 +00008314
Douglas Gregora16548e2009-08-11 05:31:07 +00008315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008316ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008317TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008318 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008319 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008320 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008322
John McCallba7bf592010-08-24 05:47:05 +00008323 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008324 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008325 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008326 E->getOperatorLoc(),
8327 E->isArrow()? tok::arrow : tok::period,
8328 ObjectTypePtr,
8329 MayBePseudoDestructor);
8330 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008331 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008332
John McCallba7bf592010-08-24 05:47:05 +00008333 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008334 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8335 if (QualifierLoc) {
8336 QualifierLoc
8337 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8338 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008339 return ExprError();
8340 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008341 CXXScopeSpec SS;
8342 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008343
Douglas Gregor678f90d2010-02-25 01:56:36 +00008344 PseudoDestructorTypeStorage Destroyed;
8345 if (E->getDestroyedTypeInfo()) {
8346 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008347 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008348 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008349 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008350 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008351 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008352 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008353 // We aren't likely to be able to resolve the identifier down to a type
8354 // now anyway, so just retain the identifier.
8355 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8356 E->getDestroyedTypeLoc());
8357 } else {
8358 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008359 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008360 *E->getDestroyedTypeIdentifier(),
8361 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008362 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008363 SS, ObjectTypePtr,
8364 false);
8365 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008366 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008367
Douglas Gregor678f90d2010-02-25 01:56:36 +00008368 Destroyed
8369 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8370 E->getDestroyedTypeLoc());
8371 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008372
Craig Topperc3ec1492014-05-26 06:22:03 +00008373 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008374 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008375 CXXScopeSpec EmptySS;
8376 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008377 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008378 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008379 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008381
John McCallb268a282010-08-23 23:25:46 +00008382 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008383 E->getOperatorLoc(),
8384 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008385 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008386 ScopeTypeInfo,
8387 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008388 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008389 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008390}
Mike Stump11289f42009-09-09 15:08:12 +00008391
Douglas Gregorad8a3362009-09-04 17:36:40 +00008392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008393ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008394TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008395 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008396 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8397 Sema::LookupOrdinaryName);
8398
8399 // Transform all the decls.
8400 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8401 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008402 NamedDecl *InstD = static_cast<NamedDecl*>(
8403 getDerived().TransformDecl(Old->getNameLoc(),
8404 *I));
John McCall84d87672009-12-10 09:41:52 +00008405 if (!InstD) {
8406 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8407 // This can happen because of dependent hiding.
8408 if (isa<UsingShadowDecl>(*I))
8409 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008410 else {
8411 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008412 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008413 }
John McCall84d87672009-12-10 09:41:52 +00008414 }
John McCalle66edc12009-11-24 19:00:30 +00008415
8416 // Expand using declarations.
8417 if (isa<UsingDecl>(InstD)) {
8418 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008419 for (auto *I : UD->shadows())
8420 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008421 continue;
8422 }
8423
8424 R.addDecl(InstD);
8425 }
8426
8427 // Resolve a kind, but don't do any further analysis. If it's
8428 // ambiguous, the callee needs to deal with it.
8429 R.resolveKind();
8430
8431 // Rebuild the nested-name qualifier, if present.
8432 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008433 if (Old->getQualifierLoc()) {
8434 NestedNameSpecifierLoc QualifierLoc
8435 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8436 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008438
Douglas Gregor0da1d432011-02-28 20:01:57 +00008439 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008440 }
8441
Douglas Gregor9262f472010-04-27 18:19:34 +00008442 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008443 CXXRecordDecl *NamingClass
8444 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8445 Old->getNameLoc(),
8446 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008447 if (!NamingClass) {
8448 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008449 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008451
Douglas Gregorda7be082010-04-27 16:10:10 +00008452 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008453 }
8454
Abramo Bagnara7945c982012-01-27 09:46:47 +00008455 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8456
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008457 // If we have neither explicit template arguments, nor the template keyword,
8458 // it's a normal declaration name.
8459 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008460 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8461
8462 // If we have template arguments, rebuild them, then rebuild the
8463 // templateid expression.
8464 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008465 if (Old->hasExplicitTemplateArgs() &&
8466 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008467 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008468 TransArgs)) {
8469 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008470 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008471 }
John McCalle66edc12009-11-24 19:00:30 +00008472
Abramo Bagnara7945c982012-01-27 09:46:47 +00008473 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008474 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008475}
Mike Stump11289f42009-09-09 15:08:12 +00008476
Douglas Gregora16548e2009-08-11 05:31:07 +00008477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008478ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008479TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8480 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008481 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008482 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8483 TypeSourceInfo *From = E->getArg(I);
8484 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008485 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008486 TypeLocBuilder TLB;
8487 TLB.reserve(FromTL.getFullDataSize());
8488 QualType To = getDerived().TransformType(TLB, FromTL);
8489 if (To.isNull())
8490 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008491
Douglas Gregor29c42f22012-02-24 07:38:34 +00008492 if (To == From->getType())
8493 Args.push_back(From);
8494 else {
8495 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8496 ArgChanged = true;
8497 }
8498 continue;
8499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008500
Douglas Gregor29c42f22012-02-24 07:38:34 +00008501 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008502
Douglas Gregor29c42f22012-02-24 07:38:34 +00008503 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008504 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008505 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8506 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8507 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008508
Douglas Gregor29c42f22012-02-24 07:38:34 +00008509 // Determine whether the set of unexpanded parameter packs can and should
8510 // be expanded.
8511 bool Expand = true;
8512 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008513 Optional<unsigned> OrigNumExpansions =
8514 ExpansionTL.getTypePtr()->getNumExpansions();
8515 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008516 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8517 PatternTL.getSourceRange(),
8518 Unexpanded,
8519 Expand, RetainExpansion,
8520 NumExpansions))
8521 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008522
Douglas Gregor29c42f22012-02-24 07:38:34 +00008523 if (!Expand) {
8524 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008525 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008526 // expansion.
8527 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008528
Douglas Gregor29c42f22012-02-24 07:38:34 +00008529 TypeLocBuilder TLB;
8530 TLB.reserve(From->getTypeLoc().getFullDataSize());
8531
8532 QualType To = getDerived().TransformType(TLB, PatternTL);
8533 if (To.isNull())
8534 return ExprError();
8535
Chad Rosier1dcde962012-08-08 18:46:20 +00008536 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008537 PatternTL.getSourceRange(),
8538 ExpansionTL.getEllipsisLoc(),
8539 NumExpansions);
8540 if (To.isNull())
8541 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008542
Douglas Gregor29c42f22012-02-24 07:38:34 +00008543 PackExpansionTypeLoc ToExpansionTL
8544 = TLB.push<PackExpansionTypeLoc>(To);
8545 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8546 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8547 continue;
8548 }
8549
8550 // Expand the pack expansion by substituting for each argument in the
8551 // pack(s).
8552 for (unsigned I = 0; I != *NumExpansions; ++I) {
8553 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8554 TypeLocBuilder TLB;
8555 TLB.reserve(PatternTL.getFullDataSize());
8556 QualType To = getDerived().TransformType(TLB, PatternTL);
8557 if (To.isNull())
8558 return ExprError();
8559
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008560 if (To->containsUnexpandedParameterPack()) {
8561 To = getDerived().RebuildPackExpansionType(To,
8562 PatternTL.getSourceRange(),
8563 ExpansionTL.getEllipsisLoc(),
8564 NumExpansions);
8565 if (To.isNull())
8566 return ExprError();
8567
8568 PackExpansionTypeLoc ToExpansionTL
8569 = TLB.push<PackExpansionTypeLoc>(To);
8570 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8571 }
8572
Douglas Gregor29c42f22012-02-24 07:38:34 +00008573 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregor29c42f22012-02-24 07:38:34 +00008576 if (!RetainExpansion)
8577 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008578
Douglas Gregor29c42f22012-02-24 07:38:34 +00008579 // If we're supposed to retain a pack expansion, do so by temporarily
8580 // forgetting the partially-substituted parameter pack.
8581 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8582
8583 TypeLocBuilder TLB;
8584 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008585
Douglas Gregor29c42f22012-02-24 07:38:34 +00008586 QualType To = getDerived().TransformType(TLB, PatternTL);
8587 if (To.isNull())
8588 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008589
8590 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008591 PatternTL.getSourceRange(),
8592 ExpansionTL.getEllipsisLoc(),
8593 NumExpansions);
8594 if (To.isNull())
8595 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008596
Douglas Gregor29c42f22012-02-24 07:38:34 +00008597 PackExpansionTypeLoc ToExpansionTL
8598 = TLB.push<PackExpansionTypeLoc>(To);
8599 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8600 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008602
Douglas Gregor29c42f22012-02-24 07:38:34 +00008603 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008604 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008605
8606 return getDerived().RebuildTypeTrait(E->getTrait(),
8607 E->getLocStart(),
8608 Args,
8609 E->getLocEnd());
8610}
8611
8612template<typename Derived>
8613ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008614TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8615 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8616 if (!T)
8617 return ExprError();
8618
8619 if (!getDerived().AlwaysRebuild() &&
8620 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008621 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008622
8623 ExprResult SubExpr;
8624 {
8625 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8626 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8627 if (SubExpr.isInvalid())
8628 return ExprError();
8629
8630 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008631 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008632 }
8633
8634 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8635 E->getLocStart(),
8636 T,
8637 SubExpr.get(),
8638 E->getLocEnd());
8639}
8640
8641template<typename Derived>
8642ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008643TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8644 ExprResult SubExpr;
8645 {
8646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8647 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8648 if (SubExpr.isInvalid())
8649 return ExprError();
8650
8651 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008652 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008653 }
8654
8655 return getDerived().RebuildExpressionTrait(
8656 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8657}
8658
Reid Kleckner32506ed2014-06-12 23:03:48 +00008659template <typename Derived>
8660ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8661 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8662 TypeSourceInfo **RecoveryTSI) {
8663 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8664 DRE, AddrTaken, RecoveryTSI);
8665
8666 // Propagate both errors and recovered types, which return ExprEmpty.
8667 if (!NewDRE.isUsable())
8668 return NewDRE;
8669
8670 // We got an expr, wrap it up in parens.
8671 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8672 return PE;
8673 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8674 PE->getRParen());
8675}
8676
8677template <typename Derived>
8678ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8679 DependentScopeDeclRefExpr *E) {
8680 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8681 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008682}
8683
8684template<typename Derived>
8685ExprResult
8686TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8687 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008688 bool IsAddressOfOperand,
8689 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008690 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008691 NestedNameSpecifierLoc QualifierLoc
8692 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8693 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008694 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008695 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008696
John McCall31f82722010-11-12 08:19:04 +00008697 // TODO: If this is a conversion-function-id, verify that the
8698 // destination type name (if present) resolves the same way after
8699 // instantiation as it did in the local scope.
8700
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008701 DeclarationNameInfo NameInfo
8702 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8703 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008705
John McCalle66edc12009-11-24 19:00:30 +00008706 if (!E->hasExplicitTemplateArgs()) {
8707 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008708 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008709 // Note: it is sufficient to compare the Name component of NameInfo:
8710 // if name has not changed, DNLoc has not changed either.
8711 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008712 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008713
Reid Kleckner32506ed2014-06-12 23:03:48 +00008714 return getDerived().RebuildDependentScopeDeclRefExpr(
8715 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8716 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008717 }
John McCall6b51f282009-11-23 01:53:49 +00008718
8719 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008720 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8721 E->getNumTemplateArgs(),
8722 TransArgs))
8723 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008724
Reid Kleckner32506ed2014-06-12 23:03:48 +00008725 return getDerived().RebuildDependentScopeDeclRefExpr(
8726 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8727 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008728}
8729
8730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008731ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008732TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008733 // CXXConstructExprs other than for list-initialization and
8734 // CXXTemporaryObjectExpr are always implicit, so when we have
8735 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008736 if ((E->getNumArgs() == 1 ||
8737 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008738 (!getDerived().DropCallArgument(E->getArg(0))) &&
8739 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008740 return getDerived().TransformExpr(E->getArg(0));
8741
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8743
8744 QualType T = getDerived().TransformType(E->getType());
8745 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008746 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008747
8748 CXXConstructorDecl *Constructor
8749 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008750 getDerived().TransformDecl(E->getLocStart(),
8751 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008754
Douglas Gregora16548e2009-08-11 05:31:07 +00008755 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008756 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008757 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008758 &ArgumentChanged))
8759 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008760
Douglas Gregora16548e2009-08-11 05:31:07 +00008761 if (!getDerived().AlwaysRebuild() &&
8762 T == E->getType() &&
8763 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008764 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008765 // Mark the constructor as referenced.
8766 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008767 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008768 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008769 }
Mike Stump11289f42009-09-09 15:08:12 +00008770
Douglas Gregordb121ba2009-12-14 16:27:04 +00008771 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8772 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008773 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008774 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008775 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008776 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008777 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008778 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008779 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008780}
Mike Stump11289f42009-09-09 15:08:12 +00008781
Douglas Gregora16548e2009-08-11 05:31:07 +00008782/// \brief Transform a C++ temporary-binding expression.
8783///
Douglas Gregor363b1512009-12-24 18:51:59 +00008784/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8785/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008788TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008789 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008790}
Mike Stump11289f42009-09-09 15:08:12 +00008791
John McCall5d413782010-12-06 08:20:24 +00008792/// \brief Transform a C++ expression that contains cleanups that should
8793/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008794///
John McCall5d413782010-12-06 08:20:24 +00008795/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008796/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008798ExprResult
John McCall5d413782010-12-06 08:20:24 +00008799TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008800 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008801}
Mike Stump11289f42009-09-09 15:08:12 +00008802
Douglas Gregora16548e2009-08-11 05:31:07 +00008803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008804ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008805TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008806 CXXTemporaryObjectExpr *E) {
8807 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8808 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008810
Douglas Gregora16548e2009-08-11 05:31:07 +00008811 CXXConstructorDecl *Constructor
8812 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008813 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008814 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008817
Douglas Gregora16548e2009-08-11 05:31:07 +00008818 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008819 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008820 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008821 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008822 &ArgumentChanged))
8823 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008824
Douglas Gregora16548e2009-08-11 05:31:07 +00008825 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008826 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008827 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008828 !ArgumentChanged) {
8829 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008830 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008831 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008833
Richard Smithd59b8322012-12-19 01:39:02 +00008834 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008835 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8836 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008837 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008838 E->getLocEnd());
8839}
Mike Stump11289f42009-09-09 15:08:12 +00008840
Douglas Gregora16548e2009-08-11 05:31:07 +00008841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008842ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008843TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008844
8845 // Transform any init-capture expressions before entering the scope of the
8846 // lambda body, because they are not semantically within that scope.
8847 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8848 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8849 E->explicit_capture_begin());
8850
8851 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8852 CEnd = E->capture_end();
8853 C != CEnd; ++C) {
8854 if (!C->isInitCapture())
8855 continue;
8856 EnterExpressionEvaluationContext EEEC(getSema(),
8857 Sema::PotentiallyEvaluated);
8858 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8859 C->getCapturedVar()->getInit(),
8860 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8861
8862 if (NewExprInitResult.isInvalid())
8863 return ExprError();
8864 Expr *NewExprInit = NewExprInitResult.get();
8865
8866 VarDecl *OldVD = C->getCapturedVar();
8867 QualType NewInitCaptureType =
8868 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8869 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8870 NewExprInit);
8871 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008872 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8873 std::make_pair(NewExprInitResult, NewInitCaptureType);
8874
8875 }
8876
Faisal Vali524ca282013-11-12 01:40:44 +00008877 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008878 // Transform the template parameters, and add them to the current
8879 // instantiation scope. The null case is handled correctly.
8880 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8881 E->getTemplateParameterList());
8882
8883 // Check to see if the TypeSourceInfo of the call operator needs to
8884 // be transformed, and if so do the transformation in the
8885 // CurrentInstantiationScope.
8886
8887 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8888 FunctionProtoTypeLoc OldCallOpFPTL =
8889 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008890 TypeSourceInfo *NewCallOpTSI = nullptr;
8891
Faisal Vali2cba1332013-10-23 06:44:28 +00008892 const bool CallOpWasAlreadyTransformed =
8893 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8894
8895 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8896 if (CallOpWasAlreadyTransformed)
8897 NewCallOpTSI = OldCallOpTSI;
8898 else {
8899 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8900 // The transformation MUST be done in the CurrentInstantiationScope since
8901 // it introduces a mapping of the original to the newly created
8902 // transformed parameters.
8903
8904 TypeLocBuilder NewCallOpTLBuilder;
8905 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8906 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008907 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008908 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8909 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008910 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008911 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8912 // the vector below - this will be used to synthesize the
8913 // NewCallOperator. Additionally, add the parameters of the untransformed
8914 // lambda call operator to the CurrentInstantiationScope.
8915 SmallVector<ParmVarDecl *, 4> Params;
8916 {
8917 FunctionProtoTypeLoc NewCallOpFPTL =
8918 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8919 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008920 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008921
8922 for (unsigned I = 0; I < NewNumArgs; ++I) {
8923 // If this call operator's type does not require transformation,
8924 // the parameters do not get added to the current instantiation scope,
8925 // - so ADD them! This allows the following to compile when the enclosing
8926 // template is specialized and the entire lambda expression has to be
8927 // transformed.
8928 // template<class T> void foo(T t) {
8929 // auto L = [](auto a) {
8930 // auto M = [](char b) { <-- note: non-generic lambda
8931 // auto N = [](auto c) {
8932 // int x = sizeof(a);
8933 // x = sizeof(b); <-- specifically this line
8934 // x = sizeof(c);
8935 // };
8936 // };
8937 // };
8938 // }
8939 // foo('a')
8940 if (CallOpWasAlreadyTransformed)
8941 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8942 NewParamDeclArray[I]);
8943 // Add to Params array, so these parameters can be used to create
8944 // the newly transformed call operator.
8945 Params.push_back(NewParamDeclArray[I]);
8946 }
8947 }
8948
8949 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008950 return ExprError();
8951
Eli Friedmand564afb2012-09-19 01:18:11 +00008952 // Create the local class that will describe the lambda.
8953 CXXRecordDecl *Class
8954 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008955 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008956 /*KnownDependent=*/false,
8957 E->getCaptureDefault());
8958
Eli Friedmand564afb2012-09-19 01:18:11 +00008959 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8960
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008961 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008962 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008963 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008964 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008965 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008966 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008967 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008968
Faisal Vali2cba1332013-10-23 06:44:28 +00008969 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8970
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008971 return getDerived().TransformLambdaScope(E, NewCallOperator,
8972 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008973}
8974
8975template<typename Derived>
8976ExprResult
8977TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008978 CXXMethodDecl *CallOperator,
8979 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008980 bool Invalid = false;
8981
Douglas Gregorb4328232012-02-14 00:00:48 +00008982 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008983 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8984 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008985
Faisal Vali2b391ab2013-09-26 19:54:12 +00008986 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008987 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008988 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008989 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008990 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008991 E->hasExplicitParameters(),
8992 E->hasExplicitResultType(),
8993 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008994
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008995 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008996 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008997 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008998 CEnd = E->capture_end();
8999 C != CEnd; ++C) {
9000 // When we hit the first implicit capture, tell Sema that we've finished
9001 // the list of explicit captures.
9002 if (!FinishedExplicitCaptures && C->isImplicit()) {
9003 getSema().finishLambdaExplicitCaptures(LSI);
9004 FinishedExplicitCaptures = true;
9005 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009006
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009007 // Capturing 'this' is trivial.
9008 if (C->capturesThis()) {
9009 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9010 continue;
9011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009012
Richard Smithba71c082013-05-16 06:20:58 +00009013 // Rebuild init-captures, including the implied field declaration.
9014 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009015
9016 InitCaptureInfoTy InitExprTypePair =
9017 InitCaptureExprsAndTypes[C - E->capture_begin()];
9018 ExprResult Init = InitExprTypePair.first;
9019 QualType InitQualType = InitExprTypePair.second;
9020 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009021 Invalid = true;
9022 continue;
9023 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009024 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009025 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9026 OldVD->getLocation(), InitExprTypePair.second,
9027 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009028 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009029 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009030 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009031 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009032 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009033 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009034 continue;
9035 }
9036
9037 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9038
Douglas Gregor3e308b12012-02-14 19:27:52 +00009039 // Determine the capture kind for Sema.
9040 Sema::TryCaptureKind Kind
9041 = C->isImplicit()? Sema::TryCapture_Implicit
9042 : C->getCaptureKind() == LCK_ByCopy
9043 ? Sema::TryCapture_ExplicitByVal
9044 : Sema::TryCapture_ExplicitByRef;
9045 SourceLocation EllipsisLoc;
9046 if (C->isPackExpansion()) {
9047 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9048 bool ShouldExpand = false;
9049 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009050 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009051 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9052 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009053 Unexpanded,
9054 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009055 NumExpansions)) {
9056 Invalid = true;
9057 continue;
9058 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009059
Douglas Gregor3e308b12012-02-14 19:27:52 +00009060 if (ShouldExpand) {
9061 // The transform has determined that we should perform an expansion;
9062 // transform and capture each of the arguments.
9063 // expansion of the pattern. Do so.
9064 VarDecl *Pack = C->getCapturedVar();
9065 for (unsigned I = 0; I != *NumExpansions; ++I) {
9066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9067 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009069 Pack));
9070 if (!CapturedVar) {
9071 Invalid = true;
9072 continue;
9073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009074
Douglas Gregor3e308b12012-02-14 19:27:52 +00009075 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009076 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9077 }
Richard Smith9467be42014-06-06 17:33:35 +00009078
9079 // FIXME: Retain a pack expansion if RetainExpansion is true.
9080
Douglas Gregor3e308b12012-02-14 19:27:52 +00009081 continue;
9082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009083
Douglas Gregor3e308b12012-02-14 19:27:52 +00009084 EllipsisLoc = C->getEllipsisLoc();
9085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009086
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009087 // Transform the captured variable.
9088 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009089 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009090 C->getCapturedVar()));
9091 if (!CapturedVar) {
9092 Invalid = true;
9093 continue;
9094 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009096 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009097 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009098 }
9099 if (!FinishedExplicitCaptures)
9100 getSema().finishLambdaExplicitCaptures(LSI);
9101
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009102
9103 // Enter a new evaluation context to insulate the lambda from any
9104 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009105 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009106
9107 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009108 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009109 /*IsInstantiation=*/true);
9110 return ExprError();
9111 }
9112
9113 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009114 StmtResult Body = getDerived().TransformStmt(E->getBody());
9115 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009116 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009117 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009118 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009119 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009120
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009121 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009122 /*CurScope=*/nullptr,
9123 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009124}
9125
9126template<typename Derived>
9127ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009128TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009129 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009130 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9131 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009133
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009135 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009136 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009137 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009138 &ArgumentChanged))
9139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009142 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009143 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009144 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009145
Douglas Gregora16548e2009-08-11 05:31:07 +00009146 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009147 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009148 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009149 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 E->getRParenLoc());
9151}
Mike Stump11289f42009-09-09 15:08:12 +00009152
Douglas Gregora16548e2009-08-11 05:31:07 +00009153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009154ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009155TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009156 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009157 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009158 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009159 Expr *OldBase;
9160 QualType BaseType;
9161 QualType ObjectType;
9162 if (!E->isImplicitAccess()) {
9163 OldBase = E->getBase();
9164 Base = getDerived().TransformExpr(OldBase);
9165 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009167
John McCall2d74de92009-12-01 22:10:20 +00009168 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009169 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009170 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009171 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009172 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009173 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009174 ObjectTy,
9175 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009176 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009177 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009178
John McCallba7bf592010-08-24 05:47:05 +00009179 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009180 BaseType = ((Expr*) Base.get())->getType();
9181 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009182 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009183 BaseType = getDerived().TransformType(E->getBaseType());
9184 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9185 }
Mike Stump11289f42009-09-09 15:08:12 +00009186
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009187 // Transform the first part of the nested-name-specifier that qualifies
9188 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009189 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009190 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009191 E->getFirstQualifierFoundInScope(),
9192 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009193
Douglas Gregore16af532011-02-28 18:50:33 +00009194 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009195 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009196 QualifierLoc
9197 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9198 ObjectType,
9199 FirstQualifierInScope);
9200 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009201 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009202 }
Mike Stump11289f42009-09-09 15:08:12 +00009203
Abramo Bagnara7945c982012-01-27 09:46:47 +00009204 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9205
John McCall31f82722010-11-12 08:19:04 +00009206 // TODO: If this is a conversion-function-id, verify that the
9207 // destination type name (if present) resolves the same way after
9208 // instantiation as it did in the local scope.
9209
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009210 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009211 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009212 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009214
John McCall2d74de92009-12-01 22:10:20 +00009215 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009216 // This is a reference to a member without an explicitly-specified
9217 // template argument list. Optimize for this common case.
9218 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009219 Base.get() == OldBase &&
9220 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009221 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009222 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009223 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009225
John McCallb268a282010-08-23 23:25:46 +00009226 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009227 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009228 E->isArrow(),
9229 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009230 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009231 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009232 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009233 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009234 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009235 }
9236
John McCall6b51f282009-11-23 01:53:49 +00009237 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009238 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9239 E->getNumTemplateArgs(),
9240 TransArgs))
9241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009242
John McCallb268a282010-08-23 23:25:46 +00009243 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009244 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009245 E->isArrow(),
9246 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009247 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009248 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009249 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009250 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009251 &TransArgs);
9252}
9253
9254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009257 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009258 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009259 QualType BaseType;
9260 if (!Old->isImplicitAccess()) {
9261 Base = getDerived().TransformExpr(Old->getBase());
9262 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009263 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009264 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009265 Old->isArrow());
9266 if (Base.isInvalid())
9267 return ExprError();
9268 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009269 } else {
9270 BaseType = getDerived().TransformType(Old->getBaseType());
9271 }
John McCall10eae182009-11-30 22:42:35 +00009272
Douglas Gregor0da1d432011-02-28 20:01:57 +00009273 NestedNameSpecifierLoc QualifierLoc;
9274 if (Old->getQualifierLoc()) {
9275 QualifierLoc
9276 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9277 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009278 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009279 }
9280
Abramo Bagnara7945c982012-01-27 09:46:47 +00009281 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9282
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009283 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009284 Sema::LookupOrdinaryName);
9285
9286 // Transform all the decls.
9287 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9288 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009289 NamedDecl *InstD = static_cast<NamedDecl*>(
9290 getDerived().TransformDecl(Old->getMemberLoc(),
9291 *I));
John McCall84d87672009-12-10 09:41:52 +00009292 if (!InstD) {
9293 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9294 // This can happen because of dependent hiding.
9295 if (isa<UsingShadowDecl>(*I))
9296 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009297 else {
9298 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009299 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009300 }
John McCall84d87672009-12-10 09:41:52 +00009301 }
John McCall10eae182009-11-30 22:42:35 +00009302
9303 // Expand using declarations.
9304 if (isa<UsingDecl>(InstD)) {
9305 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009306 for (auto *I : UD->shadows())
9307 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009308 continue;
9309 }
9310
9311 R.addDecl(InstD);
9312 }
9313
9314 R.resolveKind();
9315
Douglas Gregor9262f472010-04-27 18:19:34 +00009316 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009317 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009318 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009319 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009320 Old->getMemberLoc(),
9321 Old->getNamingClass()));
9322 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009323 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009324
Douglas Gregorda7be082010-04-27 16:10:10 +00009325 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009327
John McCall10eae182009-11-30 22:42:35 +00009328 TemplateArgumentListInfo TransArgs;
9329 if (Old->hasExplicitTemplateArgs()) {
9330 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9331 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009332 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9333 Old->getNumTemplateArgs(),
9334 TransArgs))
9335 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009336 }
John McCall38836f02010-01-15 08:34:02 +00009337
9338 // FIXME: to do this check properly, we will need to preserve the
9339 // first-qualifier-in-scope here, just in case we had a dependent
9340 // base (and therefore couldn't do the check) and a
9341 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009342 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009343
John McCallb268a282010-08-23 23:25:46 +00009344 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009345 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009346 Old->getOperatorLoc(),
9347 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009348 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009349 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009350 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009351 R,
9352 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009353 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009354}
9355
9356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009357ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009358TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009359 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009360 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9361 if (SubExpr.isInvalid())
9362 return ExprError();
9363
9364 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009365 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009366
9367 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9368}
9369
9370template<typename Derived>
9371ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009372TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009373 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9374 if (Pattern.isInvalid())
9375 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009376
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009377 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009378 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009379
Douglas Gregorb8840002011-01-14 21:20:45 +00009380 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9381 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009382}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009383
9384template<typename Derived>
9385ExprResult
9386TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9387 // If E is not value-dependent, then nothing will change when we transform it.
9388 // Note: This is an instantiation-centric view.
9389 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009390 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009391
9392 // Note: None of the implementations of TryExpandParameterPacks can ever
9393 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009394 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009395 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9396 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009397 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009398 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009399 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009400 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009401 ShouldExpand, RetainExpansion,
9402 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009403 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009405 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009406 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009407
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009408 NamedDecl *Pack = E->getPack();
9409 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009410 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009411 Pack));
9412 if (!Pack)
9413 return ExprError();
9414 }
9415
Chad Rosier1dcde962012-08-08 18:46:20 +00009416
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009417 // We now know the length of the parameter pack, so build a new expression
9418 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009419 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9420 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009421 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009422}
9423
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009424template<typename Derived>
9425ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009426TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9427 SubstNonTypeTemplateParmPackExpr *E) {
9428 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009429 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009430}
9431
9432template<typename Derived>
9433ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009434TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9435 SubstNonTypeTemplateParmExpr *E) {
9436 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009437 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009438}
9439
9440template<typename Derived>
9441ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009442TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9443 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009444 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009445}
9446
9447template<typename Derived>
9448ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009449TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9450 MaterializeTemporaryExpr *E) {
9451 return getDerived().TransformExpr(E->GetTemporaryExpr());
9452}
Chad Rosier1dcde962012-08-08 18:46:20 +00009453
Douglas Gregorfe314812011-06-21 17:03:29 +00009454template<typename Derived>
9455ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009456TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9457 CXXStdInitializerListExpr *E) {
9458 return getDerived().TransformExpr(E->getSubExpr());
9459}
9460
9461template<typename Derived>
9462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009463TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009464 return SemaRef.MaybeBindToTemporary(E);
9465}
9466
9467template<typename Derived>
9468ExprResult
9469TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009470 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009471}
9472
9473template<typename Derived>
9474ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009475TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9476 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9477 if (SubExpr.isInvalid())
9478 return ExprError();
9479
9480 if (!getDerived().AlwaysRebuild() &&
9481 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009482 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009483
9484 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009485}
9486
9487template<typename Derived>
9488ExprResult
9489TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9490 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009491 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009492 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009493 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009494 /*IsCall=*/false, Elements, &ArgChanged))
9495 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009496
Ted Kremeneke65b0862012-03-06 20:05:56 +00009497 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9498 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009499
Ted Kremeneke65b0862012-03-06 20:05:56 +00009500 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9501 Elements.data(),
9502 Elements.size());
9503}
9504
9505template<typename Derived>
9506ExprResult
9507TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009508 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009509 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009510 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009511 bool ArgChanged = false;
9512 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9513 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009514
Ted Kremeneke65b0862012-03-06 20:05:56 +00009515 if (OrigElement.isPackExpansion()) {
9516 // This key/value element is a pack expansion.
9517 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9518 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9519 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9520 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9521
9522 // Determine whether the set of unexpanded parameter packs can
9523 // and should be expanded.
9524 bool Expand = true;
9525 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009526 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9527 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009528 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9529 OrigElement.Value->getLocEnd());
9530 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9531 PatternRange,
9532 Unexpanded,
9533 Expand, RetainExpansion,
9534 NumExpansions))
9535 return ExprError();
9536
9537 if (!Expand) {
9538 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009539 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009540 // expansion.
9541 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9542 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9543 if (Key.isInvalid())
9544 return ExprError();
9545
9546 if (Key.get() != OrigElement.Key)
9547 ArgChanged = true;
9548
9549 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9550 if (Value.isInvalid())
9551 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009552
Ted Kremeneke65b0862012-03-06 20:05:56 +00009553 if (Value.get() != OrigElement.Value)
9554 ArgChanged = true;
9555
Chad Rosier1dcde962012-08-08 18:46:20 +00009556 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009557 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9558 };
9559 Elements.push_back(Expansion);
9560 continue;
9561 }
9562
9563 // Record right away that the argument was changed. This needs
9564 // to happen even if the array expands to nothing.
9565 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009566
Ted Kremeneke65b0862012-03-06 20:05:56 +00009567 // The transform has determined that we should perform an elementwise
9568 // expansion of the pattern. Do so.
9569 for (unsigned I = 0; I != *NumExpansions; ++I) {
9570 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9571 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9572 if (Key.isInvalid())
9573 return ExprError();
9574
9575 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9576 if (Value.isInvalid())
9577 return ExprError();
9578
Chad Rosier1dcde962012-08-08 18:46:20 +00009579 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009580 Key.get(), Value.get(), SourceLocation(), NumExpansions
9581 };
9582
9583 // If any unexpanded parameter packs remain, we still have a
9584 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009585 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009586 if (Key.get()->containsUnexpandedParameterPack() ||
9587 Value.get()->containsUnexpandedParameterPack())
9588 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009589
Ted Kremeneke65b0862012-03-06 20:05:56 +00009590 Elements.push_back(Element);
9591 }
9592
Richard Smith9467be42014-06-06 17:33:35 +00009593 // FIXME: Retain a pack expansion if RetainExpansion is true.
9594
Ted Kremeneke65b0862012-03-06 20:05:56 +00009595 // We've finished with this pack expansion.
9596 continue;
9597 }
9598
9599 // Transform and check key.
9600 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9601 if (Key.isInvalid())
9602 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009603
Ted Kremeneke65b0862012-03-06 20:05:56 +00009604 if (Key.get() != OrigElement.Key)
9605 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009606
Ted Kremeneke65b0862012-03-06 20:05:56 +00009607 // Transform and check value.
9608 ExprResult Value
9609 = getDerived().TransformExpr(OrigElement.Value);
9610 if (Value.isInvalid())
9611 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
Ted Kremeneke65b0862012-03-06 20:05:56 +00009613 if (Value.get() != OrigElement.Value)
9614 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009615
9616 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009617 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009618 };
9619 Elements.push_back(Element);
9620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009621
Ted Kremeneke65b0862012-03-06 20:05:56 +00009622 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9623 return SemaRef.MaybeBindToTemporary(E);
9624
9625 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9626 Elements.data(),
9627 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009628}
9629
Mike Stump11289f42009-09-09 15:08:12 +00009630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009632TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009633 TypeSourceInfo *EncodedTypeInfo
9634 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9635 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009639 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009640 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009641
9642 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009643 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009644 E->getRParenLoc());
9645}
Mike Stump11289f42009-09-09 15:08:12 +00009646
Douglas Gregora16548e2009-08-11 05:31:07 +00009647template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009648ExprResult TreeTransform<Derived>::
9649TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009650 // This is a kind of implicit conversion, and it needs to get dropped
9651 // and recomputed for the same general reasons that ImplicitCastExprs
9652 // do, as well a more specific one: this expression is only valid when
9653 // it appears *immediately* as an argument expression.
9654 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009655}
9656
9657template<typename Derived>
9658ExprResult TreeTransform<Derived>::
9659TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009660 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009661 = getDerived().TransformType(E->getTypeInfoAsWritten());
9662 if (!TSInfo)
9663 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009664
John McCall31168b02011-06-15 23:02:42 +00009665 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009666 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009667 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009668
John McCall31168b02011-06-15 23:02:42 +00009669 if (!getDerived().AlwaysRebuild() &&
9670 TSInfo == E->getTypeInfoAsWritten() &&
9671 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009672 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009673
John McCall31168b02011-06-15 23:02:42 +00009674 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009675 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009676 Result.get());
9677}
9678
9679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009681TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009682 // Transform arguments.
9683 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009684 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009685 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009686 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009687 &ArgChanged))
9688 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009689
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009690 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9691 // Class message: transform the receiver type.
9692 TypeSourceInfo *ReceiverTypeInfo
9693 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9694 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009695 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009696
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009697 // If nothing changed, just retain the existing message send.
9698 if (!getDerived().AlwaysRebuild() &&
9699 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009700 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009701
9702 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009703 SmallVector<SourceLocation, 16> SelLocs;
9704 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009705 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9706 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009707 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009708 E->getMethodDecl(),
9709 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009710 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009711 E->getRightLoc());
9712 }
9713
9714 // Instance message: transform the receiver
9715 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9716 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009717 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009718 = getDerived().TransformExpr(E->getInstanceReceiver());
9719 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009720 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009721
9722 // If nothing changed, just retain the existing message send.
9723 if (!getDerived().AlwaysRebuild() &&
9724 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009725 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009726
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009727 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009728 SmallVector<SourceLocation, 16> SelLocs;
9729 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009730 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009731 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009732 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009733 E->getMethodDecl(),
9734 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009735 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009736 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009737}
9738
Mike Stump11289f42009-09-09 15:08:12 +00009739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009741TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009742 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009743}
9744
Mike Stump11289f42009-09-09 15:08:12 +00009745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009747TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009748 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009749}
9750
Mike Stump11289f42009-09-09 15:08:12 +00009751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009753TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009754 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009755 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009756 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009757 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009758
9759 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009760
Douglas Gregord51d90d2010-04-26 20:11:03 +00009761 // If nothing changed, just retain the existing expression.
9762 if (!getDerived().AlwaysRebuild() &&
9763 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009764 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009765
John McCallb268a282010-08-23 23:25:46 +00009766 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009767 E->getLocation(),
9768 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009769}
9770
Mike Stump11289f42009-09-09 15:08:12 +00009771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009772ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009773TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009774 // 'super' and types never change. Property never changes. Just
9775 // retain the existing expression.
9776 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009777 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009778
Douglas Gregor9faee212010-04-26 20:47:02 +00009779 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009780 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009781 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009782 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor9faee212010-04-26 20:47:02 +00009784 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009785
Douglas Gregor9faee212010-04-26 20:47:02 +00009786 // If nothing changed, just retain the existing expression.
9787 if (!getDerived().AlwaysRebuild() &&
9788 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009789 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009790
John McCallb7bd14f2010-12-02 01:19:52 +00009791 if (E->isExplicitProperty())
9792 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9793 E->getExplicitProperty(),
9794 E->getLocation());
9795
9796 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009797 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009798 E->getImplicitPropertyGetter(),
9799 E->getImplicitPropertySetter(),
9800 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009801}
9802
Mike Stump11289f42009-09-09 15:08:12 +00009803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009804ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009805TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9806 // Transform the base expression.
9807 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9808 if (Base.isInvalid())
9809 return ExprError();
9810
9811 // Transform the key expression.
9812 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9813 if (Key.isInvalid())
9814 return ExprError();
9815
9816 // If nothing changed, just retain the existing expression.
9817 if (!getDerived().AlwaysRebuild() &&
9818 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009819 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009820
Chad Rosier1dcde962012-08-08 18:46:20 +00009821 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009822 Base.get(), Key.get(),
9823 E->getAtIndexMethodDecl(),
9824 E->setAtIndexMethodDecl());
9825}
9826
9827template<typename Derived>
9828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009829TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009830 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009831 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009832 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009833 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009834
Douglas Gregord51d90d2010-04-26 20:11:03 +00009835 // If nothing changed, just retain the existing expression.
9836 if (!getDerived().AlwaysRebuild() &&
9837 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009838 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009839
John McCallb268a282010-08-23 23:25:46 +00009840 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009841 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009842 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009843}
9844
Mike Stump11289f42009-09-09 15:08:12 +00009845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009847TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009848 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009849 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009850 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009851 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009852 SubExprs, &ArgumentChanged))
9853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009854
Douglas Gregora16548e2009-08-11 05:31:07 +00009855 if (!getDerived().AlwaysRebuild() &&
9856 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009857 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009858
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009860 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009861 E->getRParenLoc());
9862}
9863
Mike Stump11289f42009-09-09 15:08:12 +00009864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009865ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009866TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9867 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9868 if (SrcExpr.isInvalid())
9869 return ExprError();
9870
9871 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9872 if (!Type)
9873 return ExprError();
9874
9875 if (!getDerived().AlwaysRebuild() &&
9876 Type == E->getTypeSourceInfo() &&
9877 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009878 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009879
9880 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9881 SrcExpr.get(), Type,
9882 E->getRParenLoc());
9883}
9884
9885template<typename Derived>
9886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009887TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009888 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009889
Craig Topperc3ec1492014-05-26 06:22:03 +00009890 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009891 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9892
9893 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009894 blockScope->TheDecl->setBlockMissingReturnType(
9895 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009896
Chris Lattner01cf8db2011-07-20 06:58:45 +00009897 SmallVector<ParmVarDecl*, 4> params;
9898 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009899
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009900 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009901 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9902 oldBlock->param_begin(),
9903 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009904 nullptr, paramTypes, &params)) {
9905 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009906 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009907 }
John McCall490112f2011-02-04 18:33:18 +00009908
Jordan Rosea0a86be2013-03-08 22:25:36 +00009909 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009910 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009911 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009912
Jordan Rose5c382722013-03-08 21:51:21 +00009913 QualType functionType =
9914 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009915 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009916 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009917
9918 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009919 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009920 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009921
9922 if (!oldBlock->blockMissingReturnType()) {
9923 blockScope->HasImplicitReturnType = false;
9924 blockScope->ReturnType = exprResultType;
9925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009926
John McCall3882ace2011-01-05 12:14:39 +00009927 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009928 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009929 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009930 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009931 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009932 }
John McCall3882ace2011-01-05 12:14:39 +00009933
John McCall490112f2011-02-04 18:33:18 +00009934#ifndef NDEBUG
9935 // In builds with assertions, make sure that we captured everything we
9936 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009937 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009938 for (const auto &I : oldBlock->captures()) {
9939 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009940
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009941 // Ignore parameter packs.
9942 if (isa<ParmVarDecl>(oldCapture) &&
9943 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9944 continue;
John McCall490112f2011-02-04 18:33:18 +00009945
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009946 VarDecl *newCapture =
9947 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9948 oldCapture));
9949 assert(blockScope->CaptureMap.count(newCapture));
9950 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009951 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009952 }
9953#endif
9954
9955 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009956 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009957}
9958
Mike Stump11289f42009-09-09 15:08:12 +00009959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009960ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009961TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009962 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009963}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009964
9965template<typename Derived>
9966ExprResult
9967TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009968 QualType RetTy = getDerived().TransformType(E->getType());
9969 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009970 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009971 SubExprs.reserve(E->getNumSubExprs());
9972 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9973 SubExprs, &ArgumentChanged))
9974 return ExprError();
9975
9976 if (!getDerived().AlwaysRebuild() &&
9977 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009978 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009979
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009980 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009981 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009982}
Chad Rosier1dcde962012-08-08 18:46:20 +00009983
Douglas Gregora16548e2009-08-11 05:31:07 +00009984//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009985// Type reconstruction
9986//===----------------------------------------------------------------------===//
9987
Mike Stump11289f42009-09-09 15:08:12 +00009988template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009989QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9990 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009991 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009992 getDerived().getBaseEntity());
9993}
9994
Mike Stump11289f42009-09-09 15:08:12 +00009995template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009996QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9997 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009998 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009999 getDerived().getBaseEntity());
10000}
10001
Mike Stump11289f42009-09-09 15:08:12 +000010002template<typename Derived>
10003QualType
John McCall70dd5f62009-10-30 00:06:24 +000010004TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10005 bool WrittenAsLValue,
10006 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010007 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010008 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010009}
10010
10011template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010012QualType
John McCall70dd5f62009-10-30 00:06:24 +000010013TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10014 QualType ClassType,
10015 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010016 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10017 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010018}
10019
10020template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010021QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010022TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10023 ArrayType::ArraySizeModifier SizeMod,
10024 const llvm::APInt *Size,
10025 Expr *SizeExpr,
10026 unsigned IndexTypeQuals,
10027 SourceRange BracketsRange) {
10028 if (SizeExpr || !Size)
10029 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10030 IndexTypeQuals, BracketsRange,
10031 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010032
10033 QualType Types[] = {
10034 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10035 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10036 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010037 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010038 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010039 QualType SizeType;
10040 for (unsigned I = 0; I != NumTypes; ++I)
10041 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10042 SizeType = Types[I];
10043 break;
10044 }
Mike Stump11289f42009-09-09 15:08:12 +000010045
Eli Friedman9562f392012-01-25 23:20:27 +000010046 // Note that we can return a VariableArrayType here in the case where
10047 // the element type was a dependent VariableArrayType.
10048 IntegerLiteral *ArraySize
10049 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10050 /*FIXME*/BracketsRange.getBegin());
10051 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010052 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010053 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010054}
Mike Stump11289f42009-09-09 15:08:12 +000010055
Douglas Gregord6ff3322009-08-04 16:50:30 +000010056template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010057QualType
10058TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010059 ArrayType::ArraySizeModifier SizeMod,
10060 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010061 unsigned IndexTypeQuals,
10062 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010063 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010064 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010065}
10066
10067template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010068QualType
Mike Stump11289f42009-09-09 15:08:12 +000010069TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010070 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010071 unsigned IndexTypeQuals,
10072 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010073 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010074 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010075}
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregord6ff3322009-08-04 16:50:30 +000010077template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010078QualType
10079TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010080 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010081 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010082 unsigned IndexTypeQuals,
10083 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010084 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010085 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010086 IndexTypeQuals, BracketsRange);
10087}
10088
10089template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010090QualType
10091TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010092 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010093 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010094 unsigned IndexTypeQuals,
10095 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010096 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010097 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010098 IndexTypeQuals, BracketsRange);
10099}
10100
10101template<typename Derived>
10102QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010103 unsigned NumElements,
10104 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010105 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010106 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010107}
Mike Stump11289f42009-09-09 15:08:12 +000010108
Douglas Gregord6ff3322009-08-04 16:50:30 +000010109template<typename Derived>
10110QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10111 unsigned NumElements,
10112 SourceLocation AttributeLoc) {
10113 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10114 NumElements, true);
10115 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010116 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10117 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010118 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010119}
Mike Stump11289f42009-09-09 15:08:12 +000010120
Douglas Gregord6ff3322009-08-04 16:50:30 +000010121template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010122QualType
10123TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010124 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010125 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010126 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010127}
Mike Stump11289f42009-09-09 15:08:12 +000010128
Douglas Gregord6ff3322009-08-04 16:50:30 +000010129template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010130QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10131 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010132 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010133 const FunctionProtoType::ExtProtoInfo &EPI) {
10134 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010135 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010136 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010137 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010138}
Mike Stump11289f42009-09-09 15:08:12 +000010139
Douglas Gregord6ff3322009-08-04 16:50:30 +000010140template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010141QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10142 return SemaRef.Context.getFunctionNoProtoType(T);
10143}
10144
10145template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010146QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10147 assert(D && "no decl found");
10148 if (D->isInvalidDecl()) return QualType();
10149
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010150 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010151 TypeDecl *Ty;
10152 if (isa<UsingDecl>(D)) {
10153 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010154 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010155 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10156
10157 // A valid resolved using typename decl points to exactly one type decl.
10158 assert(++Using->shadow_begin() == Using->shadow_end());
10159 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010160
John McCallb96ec562009-12-04 22:46:56 +000010161 } else {
10162 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10163 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10164 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10165 }
10166
10167 return SemaRef.Context.getTypeDeclType(Ty);
10168}
10169
10170template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010171QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10172 SourceLocation Loc) {
10173 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010174}
10175
10176template<typename Derived>
10177QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10178 return SemaRef.Context.getTypeOfType(Underlying);
10179}
10180
10181template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010182QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10183 SourceLocation Loc) {
10184 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010185}
10186
10187template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010188QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10189 UnaryTransformType::UTTKind UKind,
10190 SourceLocation Loc) {
10191 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10192}
10193
10194template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010195QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010196 TemplateName Template,
10197 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010198 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010199 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010200}
Mike Stump11289f42009-09-09 15:08:12 +000010201
Douglas Gregor1135c352009-08-06 05:28:30 +000010202template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010203QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10204 SourceLocation KWLoc) {
10205 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10206}
10207
10208template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010209TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010210TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010211 bool TemplateKW,
10212 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010213 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010214 Template);
10215}
10216
10217template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010218TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010219TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10220 const IdentifierInfo &Name,
10221 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010222 QualType ObjectType,
10223 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010224 UnqualifiedId TemplateName;
10225 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010226 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010227 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010228 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010229 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010230 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010231 /*EnteringContext=*/false,
10232 Template);
John McCall31f82722010-11-12 08:19:04 +000010233 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010234}
Mike Stump11289f42009-09-09 15:08:12 +000010235
Douglas Gregora16548e2009-08-11 05:31:07 +000010236template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010237TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010238TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010239 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010240 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010241 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010242 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010243 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010244 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010245 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010246 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010247 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010248 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010249 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010250 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010251 /*EnteringContext=*/false,
10252 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010253 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010254}
Chad Rosier1dcde962012-08-08 18:46:20 +000010255
Douglas Gregor71395fa2009-11-04 00:56:37 +000010256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010257ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010258TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10259 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010260 Expr *OrigCallee,
10261 Expr *First,
10262 Expr *Second) {
10263 Expr *Callee = OrigCallee->IgnoreParenCasts();
10264 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010265
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010266 if (First->getObjectKind() == OK_ObjCProperty) {
10267 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10268 if (BinaryOperator::isAssignmentOp(Opc))
10269 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10270 First, Second);
10271 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10272 if (Result.isInvalid())
10273 return ExprError();
10274 First = Result.get();
10275 }
10276
10277 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10278 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10279 if (Result.isInvalid())
10280 return ExprError();
10281 Second = Result.get();
10282 }
10283
Douglas Gregora16548e2009-08-11 05:31:07 +000010284 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010285 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010286 if (!First->getType()->isOverloadableType() &&
10287 !Second->getType()->isOverloadableType())
10288 return getSema().CreateBuiltinArraySubscriptExpr(First,
10289 Callee->getLocStart(),
10290 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010291 } else if (Op == OO_Arrow) {
10292 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010293 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10294 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010295 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010296 // The argument is not of overloadable type, so try to create a
10297 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010298 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010299 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010300
John McCallb268a282010-08-23 23:25:46 +000010301 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010302 }
10303 } else {
John McCallb268a282010-08-23 23:25:46 +000010304 if (!First->getType()->isOverloadableType() &&
10305 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010306 // Neither of the arguments is an overloadable type, so try to
10307 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010308 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010309 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010310 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010311 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010313
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010314 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010315 }
10316 }
Mike Stump11289f42009-09-09 15:08:12 +000010317
10318 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010319 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010320 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010321
John McCallb268a282010-08-23 23:25:46 +000010322 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010323 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010324 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010325 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010326 // If we've resolved this to a particular non-member function, just call
10327 // that function. If we resolved it to a member function,
10328 // CreateOverloaded* will find that function for us.
10329 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10330 if (!isa<CXXMethodDecl>(ND))
10331 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010332 }
Mike Stump11289f42009-09-09 15:08:12 +000010333
Douglas Gregora16548e2009-08-11 05:31:07 +000010334 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010335 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010336 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010337
Douglas Gregora16548e2009-08-11 05:31:07 +000010338 // Create the overloaded operator invocation for unary operators.
10339 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010340 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010341 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010342 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010343 }
Mike Stump11289f42009-09-09 15:08:12 +000010344
Douglas Gregore9d62932011-07-15 16:25:15 +000010345 if (Op == OO_Subscript) {
10346 SourceLocation LBrace;
10347 SourceLocation RBrace;
10348
10349 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10350 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10351 LBrace = SourceLocation::getFromRawEncoding(
10352 NameLoc.CXXOperatorName.BeginOpNameLoc);
10353 RBrace = SourceLocation::getFromRawEncoding(
10354 NameLoc.CXXOperatorName.EndOpNameLoc);
10355 } else {
10356 LBrace = Callee->getLocStart();
10357 RBrace = OpLoc;
10358 }
10359
10360 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10361 First, Second);
10362 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010363
Douglas Gregora16548e2009-08-11 05:31:07 +000010364 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010365 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010366 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010367 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10368 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010370
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010371 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010372}
Mike Stump11289f42009-09-09 15:08:12 +000010373
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010374template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010375ExprResult
John McCallb268a282010-08-23 23:25:46 +000010376TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010377 SourceLocation OperatorLoc,
10378 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010379 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010380 TypeSourceInfo *ScopeType,
10381 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010382 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010383 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010384 QualType BaseType = Base->getType();
10385 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010386 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010387 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010388 !BaseType->getAs<PointerType>()->getPointeeType()
10389 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010390 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010391 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010392 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010393 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010394 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010395 /*FIXME?*/true);
10396 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010397
Douglas Gregor678f90d2010-02-25 01:56:36 +000010398 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010399 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10400 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10401 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10402 NameInfo.setNamedTypeInfo(DestroyedType);
10403
Richard Smith8e4a3862012-05-15 06:15:11 +000010404 // The scope type is now known to be a valid nested name specifier
10405 // component. Tack it on to the end of the nested name specifier.
10406 if (ScopeType)
10407 SS.Extend(SemaRef.Context, SourceLocation(),
10408 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010409
Abramo Bagnara7945c982012-01-27 09:46:47 +000010410 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010411 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010412 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010413 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010414 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010415 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010416 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010417}
10418
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010419template<typename Derived>
10420StmtResult
10421TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010422 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010423 CapturedDecl *CD = S->getCapturedDecl();
10424 unsigned NumParams = CD->getNumParams();
10425 unsigned ContextParamPos = CD->getContextParamPosition();
10426 SmallVector<Sema::CapturedParamNameType, 4> Params;
10427 for (unsigned I = 0; I < NumParams; ++I) {
10428 if (I != ContextParamPos) {
10429 Params.push_back(
10430 std::make_pair(
10431 CD->getParam(I)->getName(),
10432 getDerived().TransformType(CD->getParam(I)->getType())));
10433 } else {
10434 Params.push_back(std::make_pair(StringRef(), QualType()));
10435 }
10436 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010437 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010438 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010439 StmtResult Body;
10440 {
10441 Sema::CompoundScopeRAII CompoundScope(getSema());
10442 Body = getDerived().TransformStmt(S->getCapturedStmt());
10443 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010444
10445 if (Body.isInvalid()) {
10446 getSema().ActOnCapturedRegionError();
10447 return StmtError();
10448 }
10449
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010450 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010451}
10452
Douglas Gregord6ff3322009-08-04 16:50:30 +000010453} // end namespace clang
10454
10455#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H