blob: 1f648d4aca6da5dbe9afb65fa978acc8a82e2ba8 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000607
Richard Smithdb2630f2012-10-21 03:28:35 +0000608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
611
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
615
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000617
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000620#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000622 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000623#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000625 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000626#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000627#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000628
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000630 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000631 OMPClause *Transform ## Class(Class *S);
632#include "clang/Basic/OpenMPKinds.def"
633
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// \brief Build a new pointer type given its pointee type.
635 ///
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
640 /// \brief Build a new block pointer type given its pointee type.
641 ///
Mike Stump11289f42009-09-09 15:08:12 +0000642 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 ///
John McCall70dd5f62009-10-30 00:06:24 +0000648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 ///
John McCall70dd5f62009-10-30 00:06:24 +0000652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
655 bool LValue,
656 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
660 ///
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
668 /// qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
676 Expr *SizeExpr,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
693 ///
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000696 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000706 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
Mike Stump11289f42009-09-09 15:08:12 +0000712 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// size modifier, size expression, and index type qualifiers.
714 ///
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000717 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000719 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
722
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
725 ///
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000729 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
733 ///
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
739 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// given the element type and number of elements.
741 ///
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000745 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new function type.
749 ///
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
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,
1301 ArrayRef<OMPClause *> Clauses,
1302 Stmt *AStmt,
1303 SourceLocation StartLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1306 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey 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
James Dennett2a4d13c2012-06-15 07:13:21 +00001520 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001521 ///
1522 /// By default, performs semantic analysis to build the new statement.
1523 /// Subclasses may override this routine to provide different behavior.
1524 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1525 Expr *object) {
1526 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1527 }
1528
James Dennett2a4d13c2012-06-15 07:13:21 +00001529 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001530 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001531 /// By default, performs semantic analysis to build the new statement.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001534 Expr *Object, Stmt *Body) {
1535 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001536 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001537
James Dennett2a4d13c2012-06-15 07:13:21 +00001538 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001539 ///
1540 /// By default, performs semantic analysis to build the new statement.
1541 /// Subclasses may override this routine to provide different behavior.
1542 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1543 Stmt *Body) {
1544 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1545 }
John McCall53848232011-07-27 01:07:15 +00001546
Douglas Gregorf68a5082010-04-22 23:10:45 +00001547 /// \brief Build a new Objective-C fast enumeration statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001552 Stmt *Element,
1553 Expr *Collection,
1554 SourceLocation RParenLoc,
1555 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001556 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001557 Element,
John McCallb268a282010-08-23 23:25:46 +00001558 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001559 RParenLoc);
1560 if (ForEachStmt.isInvalid())
1561 return StmtError();
1562
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001563 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001565
Douglas Gregorebe10102009-08-20 07:17:43 +00001566 /// \brief Build a new C++ exception declaration.
1567 ///
1568 /// By default, performs semantic analysis to build the new decaration.
1569 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001570 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001571 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001572 SourceLocation StartLoc,
1573 SourceLocation IdLoc,
1574 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001575 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001576 StartLoc, IdLoc, Id);
1577 if (Var)
1578 getSema().CurContext->addDecl(Var);
1579 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001580 }
1581
1582 /// \brief Build a new C++ catch statement.
1583 ///
1584 /// By default, performs semantic analysis to build the new statement.
1585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001586 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001587 VarDecl *ExceptionDecl,
1588 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001589 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1590 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregorebe10102009-08-20 07:17:43 +00001593 /// \brief Build a new C++ try statement.
1594 ///
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001597 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1598 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001599 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001600 }
Mike Stump11289f42009-09-09 15:08:12 +00001601
Richard Smith02e85f32011-04-14 22:09:26 +00001602 /// \brief Build a new C++0x range-based for statement.
1603 ///
1604 /// By default, performs semantic analysis to build the new statement.
1605 /// Subclasses may override this routine to provide different behavior.
1606 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1607 SourceLocation ColonLoc,
1608 Stmt *Range, Stmt *BeginEnd,
1609 Expr *Cond, Expr *Inc,
1610 Stmt *LoopVar,
1611 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001612 // If we've just learned that the range is actually an Objective-C
1613 // collection, treat this as an Objective-C fast enumeration loop.
1614 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1615 if (RangeStmt->isSingleDecl()) {
1616 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001617 if (RangeVar->isInvalidDecl())
1618 return StmtError();
1619
Douglas Gregorf7106af2013-04-08 18:40:13 +00001620 Expr *RangeExpr = RangeVar->getInit();
1621 if (!RangeExpr->isTypeDependent() &&
1622 RangeExpr->getType()->isObjCObjectPointerType())
1623 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1624 RParenLoc);
1625 }
1626 }
1627 }
1628
Richard Smith02e85f32011-04-14 22:09:26 +00001629 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001630 Cond, Inc, LoopVar, RParenLoc,
1631 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001632 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001633
1634 /// \brief Build a new C++0x range-based for statement.
1635 ///
1636 /// By default, performs semantic analysis to build the new statement.
1637 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001638 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001639 bool IsIfExists,
1640 NestedNameSpecifierLoc QualifierLoc,
1641 DeclarationNameInfo NameInfo,
1642 Stmt *Nested) {
1643 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1644 QualifierLoc, NameInfo, Nested);
1645 }
1646
Richard Smith02e85f32011-04-14 22:09:26 +00001647 /// \brief Attach body to a C++0x range-based for statement.
1648 ///
1649 /// By default, performs semantic analysis to finish the new statement.
1650 /// Subclasses may override this routine to provide different behavior.
1651 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1652 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001654
David Majnemerfad8f482013-10-15 09:33:02 +00001655 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntb530bc02014-07-19 00:45:07 +00001656 Stmt *TryBlock, Stmt *Handler, int HandlerIndex,
1657 int HandlerParentIndex) {
1658 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler,
1659 HandlerIndex, HandlerParentIndex);
John Wiegley1c0675e2011-04-28 01:08:34 +00001660 }
1661
David Majnemerfad8f482013-10-15 09:33:02 +00001662 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001663 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001664 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001665 }
1666
David Majnemerfad8f482013-10-15 09:33:02 +00001667 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1668 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001669 }
1670
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 /// \brief Build a new expression that references a declaration.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001676 LookupResult &R,
1677 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001678 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1679 }
1680
1681
1682 /// \brief Build a new expression that references a declaration.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001686 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001687 ValueDecl *VD,
1688 const DeclarationNameInfo &NameInfo,
1689 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001690 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001691 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001692
1693 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001694
1695 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001699 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001702 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001704 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 }
1706
Douglas Gregorad8a3362009-09-04 17:36:40 +00001707 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001708 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001712 SourceLocation OperatorLoc,
1713 bool isArrow,
1714 CXXScopeSpec &SS,
1715 TypeSourceInfo *ScopeType,
1716 SourceLocation CCLoc,
1717 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001718 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001719
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001721 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001724 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001725 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001726 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001727 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregor882211c2010-04-28 22:16:22 +00001730 /// \brief Build a new builtin offsetof expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001735 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001736 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001737 unsigned NumComponents,
1738 SourceLocation RParenLoc) {
1739 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1740 NumComponents, RParenLoc);
1741 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001742
1743 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001744 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001745 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001748 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1749 SourceLocation OpLoc,
1750 UnaryExprOrTypeTrait ExprKind,
1751 SourceRange R) {
1752 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
1754
Peter Collingbournee190dee2011-03-11 19:24:49 +00001755 /// \brief Build a new sizeof, alignof or vec step expression with an
1756 /// expression 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(Expr *SubExpr, SourceLocation OpLoc,
1761 UnaryExprOrTypeTrait ExprKind,
1762 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001763 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001764 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001767
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001768 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001772 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001777 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001779 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001780 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 RBracketLoc);
1782 }
1783
1784 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001785 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001788 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001790 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001791 Expr *ExecConfig = nullptr) {
1792 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001793 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 }
1795
1796 /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001801 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001802 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001803 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001804 const DeclarationNameInfo &MemberNameInfo,
1805 ValueDecl *Member,
1806 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001807 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001808 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001809 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1810 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001811 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001812 // We have a reference to an unnamed field. This is always the
1813 // base of an anonymous struct/union member access, i.e. the
1814 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001815 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001816 assert(Member->getType()->isRecordType() &&
1817 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001818
Richard Smithcab9a7d2011-10-26 19:06:56 +00001819 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001820 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001821 QualifierLoc.getNestedNameSpecifier(),
1822 FoundDecl, Member);
1823 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001824 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001825 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001826 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001827 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001828 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001829 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001830 cast<FieldDecl>(Member)->getType(),
1831 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001832 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001833 }
Mike Stump11289f42009-09-09 15:08:12 +00001834
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001835 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001836 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001837
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001838 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001839 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001840
John McCall16df1e52010-03-30 21:47:33 +00001841 // FIXME: this involves duplicating earlier analysis in a lot of
1842 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001843 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001844 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001845 R.resolveKind();
1846
John McCallb268a282010-08-23 23:25:46 +00001847 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001848 SS, TemplateKWLoc,
1849 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001850 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001854 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001858 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001859 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001860 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
1862
1863 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001864 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001868 SourceLocation QuestionLoc,
1869 Expr *LHS,
1870 SourceLocation ColonLoc,
1871 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001872 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1873 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 }
1875
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001877 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001881 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001883 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001884 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001885 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001893 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001896 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001897 Init);
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 SourceLocation OpLoc,
1906 SourceLocation AccessorLoc,
1907 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001908
John McCall10eae182009-11-30 22:42:35 +00001909 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001910 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001911 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001912 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001913 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001914 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001915 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001916 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001920 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001924 MultiExprArg Inits,
1925 SourceLocation RBraceLoc,
1926 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001927 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001928 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001929 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001930 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001931
Douglas Gregord3d93062009-11-09 17:16:50 +00001932 // Patch in the result type we were given, which may have been computed
1933 // when the initial InitListExpr was built.
1934 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1935 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001936 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 MultiExprArg ArrayExprs,
1945 SourceLocation EqualOrColonLoc,
1946 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001947 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001950 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001953
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001954 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001958 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// By default, builds the implicit value initialization without performing
1960 /// any semantic analysis. Subclasses may override this routine to provide
1961 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001963 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001967 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001970 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001971 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001972 SourceLocation RParenLoc) {
1973 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001974 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001975 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
1977
1978 /// \brief Build a new expression list in parentheses.
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 RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001983 MultiExprArg SubExprs,
1984 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001985 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001989 ///
1990 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 /// rather than attempting to map the label statement itself.
1992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001993 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001994 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001995 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001999 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002003 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002005 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 }
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 /// \brief Build a new __builtin_choose_expr expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002012 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 SourceLocation RParenLoc) {
2015 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002016 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 RParenLoc);
2018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Peter Collingbourne91147592011-04-15 00:35:48 +00002020 /// \brief Build a new generic selection expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2025 SourceLocation DefaultLoc,
2026 SourceLocation RParenLoc,
2027 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002028 ArrayRef<TypeSourceInfo *> Types,
2029 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002030 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002031 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002032 }
2033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new overloaded operator call expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// The semantic analysis provides the behavior of template instantiation,
2038 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002039 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// argument-dependent lookup, etc. Subclasses may override this routine to
2041 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002042 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002044 Expr *Callee,
2045 Expr *First,
2046 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002047
2048 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 /// reinterpret_cast.
2050 ///
2051 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002052 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 Stmt::StmtClass Class,
2056 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002057 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 SourceLocation RAngleLoc,
2059 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002060 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 SourceLocation RParenLoc) {
2062 switch (Class) {
2063 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002064 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002065 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002066 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002067
2068 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002069 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002070 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002071 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002074 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002075 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002080 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002081 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002082 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002083
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002085 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 }
Mike Stump11289f42009-09-09 15:08:12 +00002088
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// \brief Build a new C++ static_cast expression.
2090 ///
2091 /// By default, performs semantic analysis to build the new expression.
2092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002095 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 SourceLocation RAngleLoc,
2097 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002098 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002100 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002101 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002102 SourceRange(LAngleLoc, RAngleLoc),
2103 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
2105
2106 /// \brief Build a new C++ dynamic_cast expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002110 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002112 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 SourceLocation RAngleLoc,
2114 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002117 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002118 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002119 SourceRange(LAngleLoc, RAngleLoc),
2120 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 }
2122
2123 /// \brief Build a new C++ reinterpret_cast expression.
2124 ///
2125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002127 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002129 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 SourceLocation RAngleLoc,
2131 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002132 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002134 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002135 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002136 SourceRange(LAngleLoc, RAngleLoc),
2137 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 }
2139
2140 /// \brief Build a new C++ const_cast expression.
2141 ///
2142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002144 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002146 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 SourceLocation RAngleLoc,
2148 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002149 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002151 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002152 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002153 SourceRange(LAngleLoc, RAngleLoc),
2154 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 }
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 /// \brief Build a new C++ functional-style cast expression.
2158 ///
2159 /// By default, performs semantic analysis to build the new expression.
2160 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002161 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2162 SourceLocation LParenLoc,
2163 Expr *Sub,
2164 SourceLocation RParenLoc) {
2165 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002166 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 RParenLoc);
2168 }
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// \brief Build a new C++ typeid(type) expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002175 SourceLocation TypeidLoc,
2176 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002178 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002179 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Francois Pichet9f4f2072010-09-08 12:20:18 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new C++ typeid(expr) expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002188 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002189 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002191 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002192 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002193 }
2194
Francois Pichet9f4f2072010-09-08 12:20:18 +00002195 /// \brief Build a new C++ __uuidof(type) expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
2199 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2200 SourceLocation TypeidLoc,
2201 TypeSourceInfo *Operand,
2202 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002203 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002204 RParenLoc);
2205 }
2206
2207 /// \brief Build a new C++ __uuidof(expr) 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 Expr *Operand,
2214 SourceLocation RParenLoc) {
2215 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2216 RParenLoc);
2217 }
2218
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 /// \brief Build a new C++ "this" expression.
2220 ///
2221 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002222 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002224 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002225 QualType ThisType,
2226 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002227 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002228 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 }
2230
2231 /// \brief Build a new C++ throw expression.
2232 ///
2233 /// By default, performs semantic analysis to build the new expression.
2234 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002235 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2236 bool IsThrownVariableInScope) {
2237 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 }
2239
2240 /// \brief Build a new C++ default-argument expression.
2241 ///
2242 /// By default, builds a new default-argument expression, which does not
2243 /// require any semantic analysis. Subclasses may override this routine to
2244 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002245 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002246 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002247 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 }
2249
Richard Smith852c9db2013-04-20 22:23:05 +00002250 /// \brief Build a new C++11 default-initialization expression.
2251 ///
2252 /// By default, builds a new default field initialization expression, which
2253 /// does not require any semantic analysis. Subclasses may override this
2254 /// routine to provide different behavior.
2255 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2256 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002257 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002258 }
2259
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 /// \brief Build a new C++ zero-initialization expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002264 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2265 SourceLocation LParenLoc,
2266 SourceLocation RParenLoc) {
2267 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002268 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// \brief Build a new C++ "new" expression.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002276 bool UseGlobal,
2277 SourceLocation PlacementLParen,
2278 MultiExprArg PlacementArgs,
2279 SourceLocation PlacementRParen,
2280 SourceRange TypeIdParens,
2281 QualType AllocatedType,
2282 TypeSourceInfo *AllocatedTypeInfo,
2283 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002284 SourceRange DirectInitRange,
2285 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002286 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002288 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002290 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002291 AllocatedType,
2292 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002293 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002294 DirectInitRange,
2295 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 }
Mike Stump11289f42009-09-09 15:08:12 +00002297
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 /// \brief Build a new C++ "delete" expression.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002302 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 bool IsGlobalDelete,
2304 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002305 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002307 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregor29c42f22012-02-24 07:38:34 +00002310 /// \brief Build a new type trait expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
2314 ExprResult RebuildTypeTrait(TypeTrait Trait,
2315 SourceLocation StartLoc,
2316 ArrayRef<TypeSourceInfo *> Args,
2317 SourceLocation RParenLoc) {
2318 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002320
John Wiegley6242b6a2011-04-28 00:16:57 +00002321 /// \brief Build a new array type trait expression.
2322 ///
2323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
2325 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2326 SourceLocation StartLoc,
2327 TypeSourceInfo *TSInfo,
2328 Expr *DimExpr,
2329 SourceLocation RParenLoc) {
2330 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2331 }
2332
John Wiegleyf9f65842011-04-25 06:54:41 +00002333 /// \brief Build a new expression 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 RebuildExpressionTrait(ExpressionTrait Trait,
2338 SourceLocation StartLoc,
2339 Expr *Queried,
2340 SourceLocation RParenLoc) {
2341 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2342 }
2343
Mike Stump11289f42009-09-09 15:08:12 +00002344 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 /// expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002349 ExprResult RebuildDependentScopeDeclRefExpr(
2350 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002351 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002352 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002353 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002354 bool IsAddressOfOperand,
2355 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002357 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002358
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002359 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002360 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2361 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002362
Reid Kleckner32506ed2014-06-12 23:03:48 +00002363 return getSema().BuildQualifiedDeclarationNameExpr(
2364 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 }
2366
2367 /// \brief Build a new template-id expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002371 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002372 SourceLocation TemplateKWLoc,
2373 LookupResult &R,
2374 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002375 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002376 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2377 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 }
2379
2380 /// \brief Build a new object-construction expression.
2381 ///
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002384 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002385 SourceLocation Loc,
2386 CXXConstructorDecl *Constructor,
2387 bool IsElidable,
2388 MultiExprArg Args,
2389 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002390 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002391 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002392 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002393 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002394 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002395 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002396 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002397 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002398 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002399
Douglas Gregordb121ba2009-12-14 16:27:04 +00002400 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002401 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002402 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002403 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002404 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002405 RequiresZeroInit, ConstructKind,
2406 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 }
2408
2409 /// \brief Build a new object-construction expression.
2410 ///
2411 /// By default, performs semantic analysis to build the new expression.
2412 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002413 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2414 SourceLocation LParenLoc,
2415 MultiExprArg Args,
2416 SourceLocation RParenLoc) {
2417 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002419 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 RParenLoc);
2421 }
2422
2423 /// \brief Build a new object-construction expression.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002427 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2428 SourceLocation LParenLoc,
2429 MultiExprArg Args,
2430 SourceLocation RParenLoc) {
2431 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002433 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 RParenLoc);
2435 }
Mike Stump11289f42009-09-09 15:08:12 +00002436
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 /// \brief Build a new member reference expression.
2438 ///
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002442 QualType BaseType,
2443 bool IsArrow,
2444 SourceLocation OperatorLoc,
2445 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002446 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002447 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002448 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002449 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002451 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002452
John McCallb268a282010-08-23 23:25:46 +00002453 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002454 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002455 SS, TemplateKWLoc,
2456 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002457 MemberNameInfo,
2458 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 }
2460
John McCall10eae182009-11-30 22:42:35 +00002461 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002462 ///
2463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002465 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2466 SourceLocation OperatorLoc,
2467 bool IsArrow,
2468 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002469 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002470 NamedDecl *FirstQualifierInScope,
2471 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002472 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002473 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002474 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002475
John McCallb268a282010-08-23 23:25:46 +00002476 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002477 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002478 SS, TemplateKWLoc,
2479 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002480 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002483 /// \brief Build a new noexcept expression.
2484 ///
2485 /// By default, performs semantic analysis to build the new expression.
2486 /// Subclasses may override this routine to provide different behavior.
2487 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2488 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2489 }
2490
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002491 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002492 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2493 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002494 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002495 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002496 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002497 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2498 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002499 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002500
2501 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2502 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002503 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002504 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002505
Patrick Beard0caa3942012-04-19 00:25:12 +00002506 /// \brief Build a new Objective-C boxed expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2511 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002513
Ted Kremeneke65b0862012-03-06 20:05:56 +00002514 /// \brief Build a new Objective-C array literal.
2515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
2518 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2519 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002520 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002521 MultiExprArg(Elements, NumElements));
2522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002523
2524 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002525 Expr *Base, Expr *Key,
2526 ObjCMethodDecl *getterMethod,
2527 ObjCMethodDecl *setterMethod) {
2528 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2529 getterMethod, setterMethod);
2530 }
2531
2532 /// \brief Build a new Objective-C dictionary literal.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
2536 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2537 ObjCDictionaryElement *Elements,
2538 unsigned NumElements) {
2539 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002541
James Dennett2a4d13c2012-06-15 07:13:21 +00002542 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 ///
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002546 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002547 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002549 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002550 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002551
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002552 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002553 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002554 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002555 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002556 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002557 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002558 MultiExprArg Args,
2559 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002560 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2561 ReceiverTypeInfo->getType(),
2562 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002563 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002564 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002565 }
2566
2567 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002568 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002569 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002570 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002571 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002572 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002573 MultiExprArg Args,
2574 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002575 return SemaRef.BuildInstanceMessage(Receiver,
2576 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002577 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002578 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002579 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002580 }
2581
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 /// \brief Build a new Objective-C ivar reference expression.
2583 ///
2584 /// By default, performs semantic analysis to build the new expression.
2585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002586 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002587 SourceLocation IvarLoc,
2588 bool IsArrow, bool IsFreeIvar) {
2589 // FIXME: We lose track of the IsFreeIvar bit.
2590 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002591 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2592 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002593 /*FIXME:*/IvarLoc, IsArrow,
2594 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002595 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002596 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002597 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002598 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002599
2600 /// \brief Build a new Objective-C property reference expression.
2601 ///
2602 /// By default, performs semantic analysis to build the new expression.
2603 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002604 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002605 ObjCPropertyDecl *Property,
2606 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002607 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002608 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2609 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2610 /*FIXME:*/PropertyLoc,
2611 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002612 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002613 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002614 NameInfo,
2615 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002617
John McCallb7bd14f2010-12-02 01:19:52 +00002618 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002619 ///
2620 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002621 /// Subclasses may override this routine to provide different behavior.
2622 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2623 ObjCMethodDecl *Getter,
2624 ObjCMethodDecl *Setter,
2625 SourceLocation PropertyLoc) {
2626 // Since these expressions can only be value-dependent, we do not
2627 // need to perform semantic analysis again.
2628 return Owned(
2629 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2630 VK_LValue, OK_ObjCProperty,
2631 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002632 }
2633
Douglas Gregord51d90d2010-04-26 20:11:03 +00002634 /// \brief Build a new Objective-C "isa" expression.
2635 ///
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002638 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002639 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002640 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002641 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2642 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002643 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002644 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002645 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002646 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002647 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002648 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002649
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 /// \brief Build a new shuffle vector expression.
2651 ///
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002654 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002655 MultiExprArg SubExprs,
2656 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002657 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002658 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2660 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2661 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002662 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002663
Douglas Gregora16548e2009-08-11 05:31:07 +00002664 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002665 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002666 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2667 SemaRef.Context.BuiltinFnTy,
2668 VK_RValue, BuiltinLoc);
2669 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2670 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002671 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002672
2673 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002674 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002675 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002676 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002677
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002679 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002680 }
John McCall31f82722010-11-12 08:19:04 +00002681
Hal Finkelc4d7c822013-09-18 03:29:45 +00002682 /// \brief Build a new convert vector expression.
2683 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2684 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2685 SourceLocation RParenLoc) {
2686 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2687 BuiltinLoc, RParenLoc);
2688 }
2689
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002690 /// \brief Build a new template argument pack expansion.
2691 ///
2692 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002693 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002694 /// different behavior.
2695 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002696 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002697 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002698 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002699 case TemplateArgument::Expression: {
2700 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002701 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2702 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002703 if (Result.isInvalid())
2704 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002705
Douglas Gregor98318c22011-01-03 21:37:45 +00002706 return TemplateArgumentLoc(Result.get(), Result.get());
2707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002708
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002709 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002710 return TemplateArgumentLoc(TemplateArgument(
2711 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002712 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002713 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002714 Pattern.getTemplateNameLoc(),
2715 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002716
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002717 case TemplateArgument::Null:
2718 case TemplateArgument::Integral:
2719 case TemplateArgument::Declaration:
2720 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002721 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002722 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002723 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002724
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002725 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002726 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002727 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002728 EllipsisLoc,
2729 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002730 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2731 Expansion);
2732 break;
2733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002734
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002735 return TemplateArgumentLoc();
2736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002737
Douglas Gregor968f23a2011-01-03 19:31:53 +00002738 /// \brief Build a new expression pack expansion.
2739 ///
2740 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002741 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002742 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002743 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002744 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002745 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002746 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002747
2748 /// \brief Build a new atomic operation expression.
2749 ///
2750 /// By default, performs semantic analysis to build the new expression.
2751 /// Subclasses may override this routine to provide different behavior.
2752 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2753 MultiExprArg SubExprs,
2754 QualType RetTy,
2755 AtomicExpr::AtomicOp Op,
2756 SourceLocation RParenLoc) {
2757 // Just create the expression; there is not any interesting semantic
2758 // analysis here because we can't actually build an AtomicExpr until
2759 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002760 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002761 RParenLoc);
2762 }
2763
John McCall31f82722010-11-12 08:19:04 +00002764private:
Douglas Gregor14454802011-02-25 02:25:35 +00002765 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2766 QualType ObjectType,
2767 NamedDecl *FirstQualifierInScope,
2768 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002769
2770 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2771 QualType ObjectType,
2772 NamedDecl *FirstQualifierInScope,
2773 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002774
2775 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2776 NamedDecl *FirstQualifierInScope,
2777 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778};
Douglas Gregora16548e2009-08-11 05:31:07 +00002779
Douglas Gregorebe10102009-08-20 07:17:43 +00002780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002781StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002782 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002783 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002784
Douglas Gregorebe10102009-08-20 07:17:43 +00002785 switch (S->getStmtClass()) {
2786 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002787
Douglas Gregorebe10102009-08-20 07:17:43 +00002788 // Transform individual statement nodes
2789#define STMT(Node, Parent) \
2790 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002791#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002792#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002793#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002794
Douglas Gregorebe10102009-08-20 07:17:43 +00002795 // Transform expressions by calling TransformExpr.
2796#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002797#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002798#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002799#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002800 {
John McCalldadc5752010-08-24 06:29:42 +00002801 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002802 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002804
Richard Smith945f8d32013-01-14 22:39:08 +00002805 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002806 }
Mike Stump11289f42009-09-09 15:08:12 +00002807 }
2808
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002809 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002810}
Mike Stump11289f42009-09-09 15:08:12 +00002811
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002812template<typename Derived>
2813OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2814 if (!S)
2815 return S;
2816
2817 switch (S->getClauseKind()) {
2818 default: break;
2819 // Transform individual clause nodes
2820#define OPENMP_CLAUSE(Name, Class) \
2821 case OMPC_ ## Name : \
2822 return getDerived().Transform ## Class(cast<Class>(S));
2823#include "clang/Basic/OpenMPKinds.def"
2824 }
2825
2826 return S;
2827}
2828
Mike Stump11289f42009-09-09 15:08:12 +00002829
Douglas Gregore922c772009-08-04 22:27:00 +00002830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002831ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002832 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002833 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002834
2835 switch (E->getStmtClass()) {
2836 case Stmt::NoStmtClass: break;
2837#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002838#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002839#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002840 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002841#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002842 }
2843
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002844 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002845}
2846
2847template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002848ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2849 bool CXXDirectInit) {
2850 // Initializers are instantiated like expressions, except that various outer
2851 // layers are stripped.
2852 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002853 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002854
2855 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2856 Init = ExprTemp->getSubExpr();
2857
Richard Smithe6ca4752013-05-30 22:40:16 +00002858 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2859 Init = MTE->GetTemporaryExpr();
2860
Richard Smithd59b8322012-12-19 01:39:02 +00002861 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2862 Init = Binder->getSubExpr();
2863
2864 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2865 Init = ICE->getSubExprAsWritten();
2866
Richard Smithcc1b96d2013-06-12 22:31:48 +00002867 if (CXXStdInitializerListExpr *ILE =
2868 dyn_cast<CXXStdInitializerListExpr>(Init))
2869 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2870
Richard Smith38a549b2012-12-21 08:13:35 +00002871 // If this is not a direct-initializer, we only need to reconstruct
2872 // InitListExprs. Other forms of copy-initialization will be a no-op if
2873 // the initializer is already the right type.
2874 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2875 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2876 return getDerived().TransformExpr(Init);
2877
2878 // Revert value-initialization back to empty parens.
2879 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2880 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002881 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002882 Parens.getEnd());
2883 }
2884
2885 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2886 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002887 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002888 SourceLocation());
2889
2890 // Revert initialization by constructor back to a parenthesized or braced list
2891 // of expressions. Any other form of initializer can just be reused directly.
2892 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002893 return getDerived().TransformExpr(Init);
2894
Richard Smithf8adcdc2014-07-17 05:12:35 +00002895 // If the initialization implicitly converted an initializer list to a
2896 // std::initializer_list object, unwrap the std::initializer_list too.
2897 if (Construct && Construct->isStdInitListInitialization())
2898 return TransformInitializer(Construct->getArg(0), CXXDirectInit);
2899
Richard Smithd59b8322012-12-19 01:39:02 +00002900 SmallVector<Expr*, 8> NewArgs;
2901 bool ArgChanged = false;
2902 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2903 /*IsCall*/true, NewArgs, &ArgChanged))
2904 return ExprError();
2905
2906 // If this was list initialization, revert to list form.
2907 if (Construct->isListInitialization())
2908 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2909 Construct->getLocEnd(),
2910 Construct->getType());
2911
Richard Smithd59b8322012-12-19 01:39:02 +00002912 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002913 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002914 if (Parens.isInvalid()) {
2915 // This was a variable declaration's initialization for which no initializer
2916 // was specified.
2917 assert(NewArgs.empty() &&
2918 "no parens or braces but have direct init with arguments?");
2919 return ExprEmpty();
2920 }
Richard Smithd59b8322012-12-19 01:39:02 +00002921 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2922 Parens.getEnd());
2923}
2924
2925template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002926bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2927 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002928 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002929 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002930 bool *ArgChanged) {
2931 for (unsigned I = 0; I != NumInputs; ++I) {
2932 // If requested, drop call arguments that need to be dropped.
2933 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2934 if (ArgChanged)
2935 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregora3efea12011-01-03 19:04:46 +00002937 break;
2938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
Douglas Gregor968f23a2011-01-03 19:31:53 +00002940 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2941 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002942
Chris Lattner01cf8db2011-07-20 06:58:45 +00002943 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002944 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2945 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor968f23a2011-01-03 19:31:53 +00002947 // Determine whether the set of unexpanded parameter packs can and should
2948 // be expanded.
2949 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002950 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002951 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2952 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002953 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2954 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002955 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002956 Expand, RetainExpansion,
2957 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002958 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002959
Douglas Gregor968f23a2011-01-03 19:31:53 +00002960 if (!Expand) {
2961 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002962 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002963 // expansion.
2964 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2965 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2966 if (OutPattern.isInvalid())
2967 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
2969 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002970 Expansion->getEllipsisLoc(),
2971 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002972 if (Out.isInvalid())
2973 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002974
Douglas Gregor968f23a2011-01-03 19:31:53 +00002975 if (ArgChanged)
2976 *ArgChanged = true;
2977 Outputs.push_back(Out.get());
2978 continue;
2979 }
John McCall542e7c62011-07-06 07:30:07 +00002980
2981 // Record right away that the argument was changed. This needs
2982 // to happen even if the array expands to nothing.
2983 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregor968f23a2011-01-03 19:31:53 +00002985 // The transform has determined that we should perform an elementwise
2986 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002987 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002988 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2989 ExprResult Out = getDerived().TransformExpr(Pattern);
2990 if (Out.isInvalid())
2991 return true;
2992
Richard Smith9467be42014-06-06 17:33:35 +00002993 // FIXME: Can this happen? We should not try to expand the pack
2994 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002995 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002996 Out = getDerived().RebuildPackExpansion(
2997 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002998 if (Out.isInvalid())
2999 return true;
3000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003001
Douglas Gregor968f23a2011-01-03 19:31:53 +00003002 Outputs.push_back(Out.get());
3003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Richard Smith9467be42014-06-06 17:33:35 +00003005 // If we're supposed to retain a pack expansion, do so by temporarily
3006 // forgetting the partially-substituted parameter pack.
3007 if (RetainExpansion) {
3008 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3009
3010 ExprResult Out = getDerived().TransformExpr(Pattern);
3011 if (Out.isInvalid())
3012 return true;
3013
3014 Out = getDerived().RebuildPackExpansion(
3015 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3016 if (Out.isInvalid())
3017 return true;
3018
3019 Outputs.push_back(Out.get());
3020 }
3021
Douglas Gregor968f23a2011-01-03 19:31:53 +00003022 continue;
3023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003024
Richard Smithd59b8322012-12-19 01:39:02 +00003025 ExprResult Result =
3026 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3027 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003028 if (Result.isInvalid())
3029 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003030
Douglas Gregora3efea12011-01-03 19:04:46 +00003031 if (Result.get() != Inputs[I] && ArgChanged)
3032 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
3034 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003036
Douglas Gregora3efea12011-01-03 19:04:46 +00003037 return false;
3038}
3039
3040template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003041NestedNameSpecifierLoc
3042TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3043 NestedNameSpecifierLoc NNS,
3044 QualType ObjectType,
3045 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003046 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003047 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003048 Qualifier = Qualifier.getPrefix())
3049 Qualifiers.push_back(Qualifier);
3050
3051 CXXScopeSpec SS;
3052 while (!Qualifiers.empty()) {
3053 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3054 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003055
Douglas Gregor14454802011-02-25 02:25:35 +00003056 switch (QNNS->getKind()) {
3057 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003058 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003059 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003060 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003061 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003062 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003063 FirstQualifierInScope, false))
3064 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor14454802011-02-25 02:25:35 +00003066 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
Douglas Gregor14454802011-02-25 02:25:35 +00003068 case NestedNameSpecifier::Namespace: {
3069 NamespaceDecl *NS
3070 = cast_or_null<NamespaceDecl>(
3071 getDerived().TransformDecl(
3072 Q.getLocalBeginLoc(),
3073 QNNS->getAsNamespace()));
3074 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3075 break;
3076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor14454802011-02-25 02:25:35 +00003078 case NestedNameSpecifier::NamespaceAlias: {
3079 NamespaceAliasDecl *Alias
3080 = cast_or_null<NamespaceAliasDecl>(
3081 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3082 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003083 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003084 Q.getLocalEndLoc());
3085 break;
3086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003087
Douglas Gregor14454802011-02-25 02:25:35 +00003088 case NestedNameSpecifier::Global:
3089 // There is no meaningful transformation that one could perform on the
3090 // global scope.
3091 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3092 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003093
Douglas Gregor14454802011-02-25 02:25:35 +00003094 case NestedNameSpecifier::TypeSpecWithTemplate:
3095 case NestedNameSpecifier::TypeSpec: {
3096 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3097 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003098
Douglas Gregor14454802011-02-25 02:25:35 +00003099 if (!TL)
3100 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregor14454802011-02-25 02:25:35 +00003102 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003103 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003104 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003105 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003106 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003107 if (TL.getType()->isEnumeralType())
3108 SemaRef.Diag(TL.getBeginLoc(),
3109 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003110 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3111 Q.getLocalEndLoc());
3112 break;
3113 }
Richard Trieude756fb2011-05-07 01:36:37 +00003114 // If the nested-name-specifier is an invalid type def, don't emit an
3115 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003116 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3117 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003118 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003119 << TL.getType() << SS.getRange();
3120 }
Douglas Gregor14454802011-02-25 02:25:35 +00003121 return NestedNameSpecifierLoc();
3122 }
Douglas Gregore16af532011-02-28 18:50:33 +00003123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregore16af532011-02-28 18:50:33 +00003125 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003126 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003127 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003129
Douglas Gregor14454802011-02-25 02:25:35 +00003130 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003131 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003132 !getDerived().AlwaysRebuild())
3133 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
3135 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003136 // nested-name-specifier, do so.
3137 if (SS.location_size() == NNS.getDataLength() &&
3138 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3139 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3140
3141 // Allocate new nested-name-specifier location information.
3142 return SS.getWithLocInContext(SemaRef.Context);
3143}
3144
3145template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003146DeclarationNameInfo
3147TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003148::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003149 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003150 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003151 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003152
3153 switch (Name.getNameKind()) {
3154 case DeclarationName::Identifier:
3155 case DeclarationName::ObjCZeroArgSelector:
3156 case DeclarationName::ObjCOneArgSelector:
3157 case DeclarationName::ObjCMultiArgSelector:
3158 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003159 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003160 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003161 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorf816bd72009-09-03 22:13:48 +00003163 case DeclarationName::CXXConstructorName:
3164 case DeclarationName::CXXDestructorName:
3165 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003166 TypeSourceInfo *NewTInfo;
3167 CanQualType NewCanTy;
3168 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003169 NewTInfo = getDerived().TransformType(OldTInfo);
3170 if (!NewTInfo)
3171 return DeclarationNameInfo();
3172 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003173 }
3174 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003175 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003176 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003177 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003178 if (NewT.isNull())
3179 return DeclarationNameInfo();
3180 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3181 }
Mike Stump11289f42009-09-09 15:08:12 +00003182
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003183 DeclarationName NewName
3184 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3185 NewCanTy);
3186 DeclarationNameInfo NewNameInfo(NameInfo);
3187 NewNameInfo.setName(NewName);
3188 NewNameInfo.setNamedTypeInfo(NewTInfo);
3189 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003190 }
Mike Stump11289f42009-09-09 15:08:12 +00003191 }
3192
David Blaikie83d382b2011-09-23 05:06:16 +00003193 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003194}
3195
3196template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003197TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003198TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3199 TemplateName Name,
3200 SourceLocation NameLoc,
3201 QualType ObjectType,
3202 NamedDecl *FirstQualifierInScope) {
3203 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3204 TemplateDecl *Template = QTN->getTemplateDecl();
3205 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregor9db53502011-03-02 18:07:45 +00003207 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003208 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003209 Template));
3210 if (!TransTemplate)
3211 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003212
Douglas Gregor9db53502011-03-02 18:07:45 +00003213 if (!getDerived().AlwaysRebuild() &&
3214 SS.getScopeRep() == QTN->getQualifier() &&
3215 TransTemplate == Template)
3216 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Douglas Gregor9db53502011-03-02 18:07:45 +00003218 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3219 TransTemplate);
3220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregor9db53502011-03-02 18:07:45 +00003222 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3223 if (SS.getScopeRep()) {
3224 // These apply to the scope specifier, not the template.
3225 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003226 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003227 }
3228
Douglas Gregor9db53502011-03-02 18:07:45 +00003229 if (!getDerived().AlwaysRebuild() &&
3230 SS.getScopeRep() == DTN->getQualifier() &&
3231 ObjectType.isNull())
3232 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003233
Douglas Gregor9db53502011-03-02 18:07:45 +00003234 if (DTN->isIdentifier()) {
3235 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003236 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003237 NameLoc,
3238 ObjectType,
3239 FirstQualifierInScope);
3240 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003241
Douglas Gregor9db53502011-03-02 18:07:45 +00003242 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3243 ObjectType);
3244 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003245
Douglas Gregor9db53502011-03-02 18:07:45 +00003246 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3247 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003248 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003249 Template));
3250 if (!TransTemplate)
3251 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregor9db53502011-03-02 18:07:45 +00003253 if (!getDerived().AlwaysRebuild() &&
3254 TransTemplate == Template)
3255 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003256
Douglas Gregor9db53502011-03-02 18:07:45 +00003257 return TemplateName(TransTemplate);
3258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor9db53502011-03-02 18:07:45 +00003260 if (SubstTemplateTemplateParmPackStorage *SubstPack
3261 = Name.getAsSubstTemplateTemplateParmPack()) {
3262 TemplateTemplateParmDecl *TransParam
3263 = cast_or_null<TemplateTemplateParmDecl>(
3264 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3265 if (!TransParam)
3266 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003267
Douglas Gregor9db53502011-03-02 18:07:45 +00003268 if (!getDerived().AlwaysRebuild() &&
3269 TransParam == SubstPack->getParameterPack())
3270 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
3272 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003273 SubstPack->getArgumentPack());
3274 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003275
Douglas Gregor9db53502011-03-02 18:07:45 +00003276 // These should be getting filtered out before they reach the AST.
3277 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003278}
3279
3280template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003281void TreeTransform<Derived>::InventTemplateArgumentLoc(
3282 const TemplateArgument &Arg,
3283 TemplateArgumentLoc &Output) {
3284 SourceLocation Loc = getDerived().getBaseLocation();
3285 switch (Arg.getKind()) {
3286 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003287 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003288 break;
3289
3290 case TemplateArgument::Type:
3291 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003292 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003293
John McCall0ad16662009-10-29 08:12:44 +00003294 break;
3295
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003296 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003297 case TemplateArgument::TemplateExpansion: {
3298 NestedNameSpecifierLocBuilder Builder;
3299 TemplateName Template = Arg.getAsTemplate();
3300 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3301 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3302 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3303 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregor9d802122011-03-02 17:09:35 +00003305 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003306 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003307 Builder.getWithLocInContext(SemaRef.Context),
3308 Loc);
3309 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003310 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003311 Builder.getWithLocInContext(SemaRef.Context),
3312 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003314 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003315 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003316
John McCall0ad16662009-10-29 08:12:44 +00003317 case TemplateArgument::Expression:
3318 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3319 break;
3320
3321 case TemplateArgument::Declaration:
3322 case TemplateArgument::Integral:
3323 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003324 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003325 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003326 break;
3327 }
3328}
3329
3330template<typename Derived>
3331bool TreeTransform<Derived>::TransformTemplateArgument(
3332 const TemplateArgumentLoc &Input,
3333 TemplateArgumentLoc &Output) {
3334 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003335 switch (Arg.getKind()) {
3336 case TemplateArgument::Null:
3337 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003338 case TemplateArgument::Pack:
3339 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003340 case TemplateArgument::NullPtr:
3341 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003342
Douglas Gregore922c772009-08-04 22:27:00 +00003343 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003344 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003345 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003346 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003347
3348 DI = getDerived().TransformType(DI);
3349 if (!DI) return true;
3350
3351 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3352 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003353 }
Mike Stump11289f42009-09-09 15:08:12 +00003354
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003355 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003356 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3357 if (QualifierLoc) {
3358 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3359 if (!QualifierLoc)
3360 return true;
3361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregordf846d12011-03-02 18:46:51 +00003363 CXXScopeSpec SS;
3364 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003365 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003366 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3367 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003368 if (Template.isNull())
3369 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003370
Douglas Gregor9d802122011-03-02 17:09:35 +00003371 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003372 Input.getTemplateNameLoc());
3373 return false;
3374 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003375
3376 case TemplateArgument::TemplateExpansion:
3377 llvm_unreachable("Caller should expand pack expansions");
3378
Douglas Gregore922c772009-08-04 22:27:00 +00003379 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003380 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003381 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003382 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003383
John McCall0ad16662009-10-29 08:12:44 +00003384 Expr *InputExpr = Input.getSourceExpression();
3385 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3386
Chris Lattnercdb591a2011-04-25 20:37:58 +00003387 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003388 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003389 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003390 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003391 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003392 }
Douglas Gregore922c772009-08-04 22:27:00 +00003393 }
Mike Stump11289f42009-09-09 15:08:12 +00003394
Douglas Gregore922c772009-08-04 22:27:00 +00003395 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003396 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003397}
3398
Douglas Gregorfe921a72010-12-20 23:36:19 +00003399/// \brief Iterator adaptor that invents template argument location information
3400/// for each of the template arguments in its underlying iterator.
3401template<typename Derived, typename InputIterator>
3402class TemplateArgumentLocInventIterator {
3403 TreeTransform<Derived> &Self;
3404 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregorfe921a72010-12-20 23:36:19 +00003406public:
3407 typedef TemplateArgumentLoc value_type;
3408 typedef TemplateArgumentLoc reference;
3409 typedef typename std::iterator_traits<InputIterator>::difference_type
3410 difference_type;
3411 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregorfe921a72010-12-20 23:36:19 +00003413 class pointer {
3414 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregorfe921a72010-12-20 23:36:19 +00003416 public:
3417 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregorfe921a72010-12-20 23:36:19 +00003419 const TemplateArgumentLoc *operator->() const { return &Arg; }
3420 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Douglas Gregorfe921a72010-12-20 23:36:19 +00003422 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregorfe921a72010-12-20 23:36:19 +00003424 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3425 InputIterator Iter)
3426 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregorfe921a72010-12-20 23:36:19 +00003428 TemplateArgumentLocInventIterator &operator++() {
3429 ++Iter;
3430 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregorfe921a72010-12-20 23:36:19 +00003433 TemplateArgumentLocInventIterator operator++(int) {
3434 TemplateArgumentLocInventIterator Old(*this);
3435 ++(*this);
3436 return Old;
3437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregorfe921a72010-12-20 23:36:19 +00003439 reference operator*() const {
3440 TemplateArgumentLoc Result;
3441 Self.InventTemplateArgumentLoc(*Iter, Result);
3442 return Result;
3443 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregorfe921a72010-12-20 23:36:19 +00003447 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3448 const TemplateArgumentLocInventIterator &Y) {
3449 return X.Iter == Y.Iter;
3450 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003451
Douglas Gregorfe921a72010-12-20 23:36:19 +00003452 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3453 const TemplateArgumentLocInventIterator &Y) {
3454 return X.Iter != Y.Iter;
3455 }
3456};
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor42cafa82010-12-20 17:42:22 +00003458template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003459template<typename InputIterator>
3460bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3461 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003462 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003463 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003464 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003465 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003467 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3468 // Unpack argument packs, which we translate them into separate
3469 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003470 // FIXME: We could do much better if we could guarantee that the
3471 // TemplateArgumentLocInfo for the pack expansion would be usable for
3472 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003473 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003474 TemplateArgument::pack_iterator>
3475 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003476 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003477 In.getArgument().pack_begin()),
3478 PackLocIterator(*this,
3479 In.getArgument().pack_end()),
3480 Outputs))
3481 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003483 continue;
3484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003486 if (In.getArgument().isPackExpansion()) {
3487 // We have a pack expansion, for which we will be substituting into
3488 // the pattern.
3489 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003490 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003491 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003492 = getSema().getTemplateArgumentPackExpansionPattern(
3493 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Chris Lattner01cf8db2011-07-20 06:58:45 +00003495 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003496 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3497 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003499 // Determine whether the set of unexpanded parameter packs can and should
3500 // be expanded.
3501 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003502 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003503 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003504 if (getDerived().TryExpandParameterPacks(Ellipsis,
3505 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003506 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003507 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003508 RetainExpansion,
3509 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003510 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003512 if (!Expand) {
3513 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003514 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003515 // expansion.
3516 TemplateArgumentLoc OutPattern;
3517 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3518 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3519 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003521 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3522 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003523 if (Out.getArgument().isNull())
3524 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003526 Outputs.addArgument(Out);
3527 continue;
3528 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003530 // The transform has determined that we should perform an elementwise
3531 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003532 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003533 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3534
3535 if (getDerived().TransformTemplateArgument(Pattern, Out))
3536 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003538 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003539 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3540 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003541 if (Out.getArgument().isNull())
3542 return true;
3543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003544
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003545 Outputs.addArgument(Out);
3546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
Douglas Gregor48d24112011-01-10 20:53:55 +00003548 // If we're supposed to retain a pack expansion, do so by temporarily
3549 // forgetting the partially-substituted parameter pack.
3550 if (RetainExpansion) {
3551 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregor48d24112011-01-10 20:53:55 +00003553 if (getDerived().TransformTemplateArgument(Pattern, Out))
3554 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003556 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3557 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003558 if (Out.getArgument().isNull())
3559 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregor48d24112011-01-10 20:53:55 +00003561 Outputs.addArgument(Out);
3562 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003564 continue;
3565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003566
3567 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003568 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003569 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003570
Douglas Gregor42cafa82010-12-20 17:42:22 +00003571 Outputs.addArgument(Out);
3572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor42cafa82010-12-20 17:42:22 +00003574 return false;
3575
3576}
3577
Douglas Gregord6ff3322009-08-04 16:50:30 +00003578//===----------------------------------------------------------------------===//
3579// Type transformation
3580//===----------------------------------------------------------------------===//
3581
3582template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003583QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003584 if (getDerived().AlreadyTransformed(T))
3585 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003586
John McCall550e0c22009-10-21 00:40:46 +00003587 // Temporary workaround. All of these transformations should
3588 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003589 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3590 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
John McCall31f82722010-11-12 08:19:04 +00003592 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003593
John McCall550e0c22009-10-21 00:40:46 +00003594 if (!NewDI)
3595 return QualType();
3596
3597 return NewDI->getType();
3598}
3599
3600template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003601TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003602 // Refine the base location to the type's location.
3603 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3604 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003605 if (getDerived().AlreadyTransformed(DI->getType()))
3606 return DI;
3607
3608 TypeLocBuilder TLB;
3609
3610 TypeLoc TL = DI->getTypeLoc();
3611 TLB.reserve(TL.getFullDataSize());
3612
John McCall31f82722010-11-12 08:19:04 +00003613 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003614 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003615 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003616
John McCallbcd03502009-12-07 02:54:59 +00003617 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003618}
3619
3620template<typename Derived>
3621QualType
John McCall31f82722010-11-12 08:19:04 +00003622TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003623 switch (T.getTypeLocClass()) {
3624#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003625#define TYPELOC(CLASS, PARENT) \
3626 case TypeLoc::CLASS: \
3627 return getDerived().Transform##CLASS##Type(TLB, \
3628 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003629#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003630 }
Mike Stump11289f42009-09-09 15:08:12 +00003631
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003632 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003633}
3634
3635/// FIXME: By default, this routine adds type qualifiers only to types
3636/// that can have qualifiers, and silently suppresses those qualifiers
3637/// that are not permitted (e.g., qualifiers on reference or function
3638/// types). This is the right thing for template instantiation, but
3639/// probably not for other clients.
3640template<typename Derived>
3641QualType
3642TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003643 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003644 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003645
John McCall31f82722010-11-12 08:19:04 +00003646 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003647 if (Result.isNull())
3648 return QualType();
3649
3650 // Silently suppress qualifiers if the result type can't be qualified.
3651 // FIXME: this is the right thing for template instantiation, but
3652 // probably not for other clients.
3653 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003654 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003655
John McCall31168b02011-06-15 23:02:42 +00003656 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003657 // resulting type.
3658 if (Quals.hasObjCLifetime()) {
3659 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3660 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003661 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003662 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003663 // A lifetime qualifier applied to a substituted template parameter
3664 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003665 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003666 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003667 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3668 QualType Replacement = SubstTypeParam->getReplacementType();
3669 Qualifiers Qs = Replacement.getQualifiers();
3670 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003671 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003672 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3673 Qs);
3674 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003675 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003676 Replacement);
3677 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003678 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3679 // 'auto' types behave the same way as template parameters.
3680 QualType Deduced = AutoTy->getDeducedType();
3681 Qualifiers Qs = Deduced.getQualifiers();
3682 Qs.removeObjCLifetime();
3683 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3684 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003685 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3686 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003687 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003688 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003689 // Otherwise, complain about the addition of a qualifier to an
3690 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003691 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003692 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003693 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregore46db902011-06-17 22:11:49 +00003695 Quals.removeObjCLifetime();
3696 }
3697 }
3698 }
John McCallcb0f89a2010-06-05 06:41:15 +00003699 if (!Quals.empty()) {
3700 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003701 // BuildQualifiedType might not add qualifiers if they are invalid.
3702 if (Result.hasLocalQualifiers())
3703 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003704 // No location information to preserve.
3705 }
John McCall550e0c22009-10-21 00:40:46 +00003706
3707 return Result;
3708}
3709
Douglas Gregor14454802011-02-25 02:25:35 +00003710template<typename Derived>
3711TypeLoc
3712TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3713 QualType ObjectType,
3714 NamedDecl *UnqualLookup,
3715 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003716 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003717 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003719 TypeSourceInfo *TSI =
3720 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3721 if (TSI)
3722 return TSI->getTypeLoc();
3723 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003724}
3725
Douglas Gregor579c15f2011-03-02 18:32:08 +00003726template<typename Derived>
3727TypeSourceInfo *
3728TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3729 QualType ObjectType,
3730 NamedDecl *UnqualLookup,
3731 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003732 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003733 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003734
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003735 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3736 UnqualLookup, SS);
3737}
3738
3739template <typename Derived>
3740TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3741 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3742 CXXScopeSpec &SS) {
3743 QualType T = TL.getType();
3744 assert(!getDerived().AlreadyTransformed(T));
3745
Douglas Gregor579c15f2011-03-02 18:32:08 +00003746 TypeLocBuilder TLB;
3747 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Douglas Gregor579c15f2011-03-02 18:32:08 +00003749 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003750 TemplateSpecializationTypeLoc SpecTL =
3751 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor579c15f2011-03-02 18:32:08 +00003753 TemplateName Template
3754 = getDerived().TransformTemplateName(SS,
3755 SpecTL.getTypePtr()->getTemplateName(),
3756 SpecTL.getTemplateNameLoc(),
3757 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003758 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003759 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
3761 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003762 Template);
3763 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003764 DependentTemplateSpecializationTypeLoc SpecTL =
3765 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor579c15f2011-03-02 18:32:08 +00003767 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 = getDerived().RebuildTemplateName(SS,
3769 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003770 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003771 ObjectType, UnqualLookup);
3772 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003773 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
3775 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003776 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003777 Template,
3778 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003779 } else {
3780 // Nothing special needs to be done for these.
3781 Result = getDerived().TransformType(TLB, TL);
3782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
3784 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003785 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregor579c15f2011-03-02 18:32:08 +00003787 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3788}
3789
John McCall550e0c22009-10-21 00:40:46 +00003790template <class TyLoc> static inline
3791QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3792 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3793 NewT.setNameLoc(T.getNameLoc());
3794 return T.getType();
3795}
3796
John McCall550e0c22009-10-21 00:40:46 +00003797template<typename Derived>
3798QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003799 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003800 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3801 NewT.setBuiltinLoc(T.getBuiltinLoc());
3802 if (T.needsExtraLocalData())
3803 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3804 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003805}
Mike Stump11289f42009-09-09 15:08:12 +00003806
Douglas Gregord6ff3322009-08-04 16:50:30 +00003807template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003808QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003809 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003810 // FIXME: recurse?
3811 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Reid Kleckner0503a872013-12-05 01:23:43 +00003814template <typename Derived>
3815QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3816 AdjustedTypeLoc TL) {
3817 // Adjustments applied during transformation are handled elsewhere.
3818 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3819}
3820
Douglas Gregord6ff3322009-08-04 16:50:30 +00003821template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003822QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3823 DecayedTypeLoc TL) {
3824 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3825 if (OriginalType.isNull())
3826 return QualType();
3827
3828 QualType Result = TL.getType();
3829 if (getDerived().AlwaysRebuild() ||
3830 OriginalType != TL.getOriginalLoc().getType())
3831 Result = SemaRef.Context.getDecayedType(OriginalType);
3832 TLB.push<DecayedTypeLoc>(Result);
3833 // Nothing to set for DecayedTypeLoc.
3834 return Result;
3835}
3836
3837template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003838QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003839 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003840 QualType PointeeType
3841 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003842 if (PointeeType.isNull())
3843 return QualType();
3844
3845 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003846 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003847 // A dependent pointer type 'T *' has is being transformed such
3848 // that an Objective-C class type is being replaced for 'T'. The
3849 // resulting pointer type is an ObjCObjectPointerType, not a
3850 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003851 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003852
John McCall8b07ec22010-05-15 11:32:37 +00003853 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3854 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003855 return Result;
3856 }
John McCall31f82722010-11-12 08:19:04 +00003857
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003858 if (getDerived().AlwaysRebuild() ||
3859 PointeeType != TL.getPointeeLoc().getType()) {
3860 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3861 if (Result.isNull())
3862 return QualType();
3863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
John McCall31168b02011-06-15 23:02:42 +00003865 // Objective-C ARC can add lifetime qualifiers to the type that we're
3866 // pointing to.
3867 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003868
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003869 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3870 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003871 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003872}
Mike Stump11289f42009-09-09 15:08:12 +00003873
3874template<typename Derived>
3875QualType
John McCall550e0c22009-10-21 00:40:46 +00003876TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003877 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003878 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003879 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3880 if (PointeeType.isNull())
3881 return QualType();
3882
3883 QualType Result = TL.getType();
3884 if (getDerived().AlwaysRebuild() ||
3885 PointeeType != TL.getPointeeLoc().getType()) {
3886 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003887 TL.getSigilLoc());
3888 if (Result.isNull())
3889 return QualType();
3890 }
3891
Douglas Gregor049211a2010-04-22 16:50:51 +00003892 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003893 NewT.setSigilLoc(TL.getSigilLoc());
3894 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003895}
3896
John McCall70dd5f62009-10-30 00:06:24 +00003897/// Transforms a reference type. Note that somewhat paradoxically we
3898/// don't care whether the type itself is an l-value type or an r-value
3899/// type; we only care if the type was *written* as an l-value type
3900/// or an r-value type.
3901template<typename Derived>
3902QualType
3903TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003904 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003905 const ReferenceType *T = TL.getTypePtr();
3906
3907 // Note that this works with the pointee-as-written.
3908 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3909 if (PointeeType.isNull())
3910 return QualType();
3911
3912 QualType Result = TL.getType();
3913 if (getDerived().AlwaysRebuild() ||
3914 PointeeType != T->getPointeeTypeAsWritten()) {
3915 Result = getDerived().RebuildReferenceType(PointeeType,
3916 T->isSpelledAsLValue(),
3917 TL.getSigilLoc());
3918 if (Result.isNull())
3919 return QualType();
3920 }
3921
John McCall31168b02011-06-15 23:02:42 +00003922 // Objective-C ARC can add lifetime qualifiers to the type that we're
3923 // referring to.
3924 TLB.TypeWasModifiedSafely(
3925 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3926
John McCall70dd5f62009-10-30 00:06:24 +00003927 // r-value references can be rebuilt as l-value references.
3928 ReferenceTypeLoc NewTL;
3929 if (isa<LValueReferenceType>(Result))
3930 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3931 else
3932 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3933 NewTL.setSigilLoc(TL.getSigilLoc());
3934
3935 return Result;
3936}
3937
Mike Stump11289f42009-09-09 15:08:12 +00003938template<typename Derived>
3939QualType
John McCall550e0c22009-10-21 00:40:46 +00003940TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003941 LValueReferenceTypeLoc TL) {
3942 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003943}
3944
Mike Stump11289f42009-09-09 15:08:12 +00003945template<typename Derived>
3946QualType
John McCall550e0c22009-10-21 00:40:46 +00003947TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003948 RValueReferenceTypeLoc TL) {
3949 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003950}
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003953QualType
John McCall550e0c22009-10-21 00:40:46 +00003954TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003955 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003956 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957 if (PointeeType.isNull())
3958 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003959
Abramo Bagnara509357842011-03-05 14:42:21 +00003960 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003961 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003962 if (OldClsTInfo) {
3963 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3964 if (!NewClsTInfo)
3965 return QualType();
3966 }
3967
3968 const MemberPointerType *T = TL.getTypePtr();
3969 QualType OldClsType = QualType(T->getClass(), 0);
3970 QualType NewClsType;
3971 if (NewClsTInfo)
3972 NewClsType = NewClsTInfo->getType();
3973 else {
3974 NewClsType = getDerived().TransformType(OldClsType);
3975 if (NewClsType.isNull())
3976 return QualType();
3977 }
Mike Stump11289f42009-09-09 15:08:12 +00003978
John McCall550e0c22009-10-21 00:40:46 +00003979 QualType Result = TL.getType();
3980 if (getDerived().AlwaysRebuild() ||
3981 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003982 NewClsType != OldClsType) {
3983 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003984 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003985 if (Result.isNull())
3986 return QualType();
3987 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988
Reid Kleckner0503a872013-12-05 01:23:43 +00003989 // If we had to adjust the pointee type when building a member pointer, make
3990 // sure to push TypeLoc info for it.
3991 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3992 if (MPT && PointeeType != MPT->getPointeeType()) {
3993 assert(isa<AdjustedType>(MPT->getPointeeType()));
3994 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3995 }
3996
John McCall550e0c22009-10-21 00:40:46 +00003997 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3998 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003999 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004000
4001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002}
4003
Mike Stump11289f42009-09-09 15:08:12 +00004004template<typename Derived>
4005QualType
John McCall550e0c22009-10-21 00:40:46 +00004006TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004008 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004009 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004010 if (ElementType.isNull())
4011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004012
John McCall550e0c22009-10-21 00:40:46 +00004013 QualType Result = TL.getType();
4014 if (getDerived().AlwaysRebuild() ||
4015 ElementType != T->getElementType()) {
4016 Result = getDerived().RebuildConstantArrayType(ElementType,
4017 T->getSizeModifier(),
4018 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004019 T->getIndexTypeCVRQualifiers(),
4020 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004021 if (Result.isNull())
4022 return QualType();
4023 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004024
4025 // We might have either a ConstantArrayType or a VariableArrayType now:
4026 // a ConstantArrayType is allowed to have an element type which is a
4027 // VariableArrayType if the type is dependent. Fortunately, all array
4028 // types have the same location layout.
4029 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004030 NewTL.setLBracketLoc(TL.getLBracketLoc());
4031 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004032
John McCall550e0c22009-10-21 00:40:46 +00004033 Expr *Size = TL.getSizeExpr();
4034 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004035 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4036 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004037 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4038 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004039 }
4040 NewTL.setSizeExpr(Size);
4041
4042 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004047 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004049 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004050 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004051 if (ElementType.isNull())
4052 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004053
John McCall550e0c22009-10-21 00:40:46 +00004054 QualType Result = TL.getType();
4055 if (getDerived().AlwaysRebuild() ||
4056 ElementType != T->getElementType()) {
4057 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004058 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004059 T->getIndexTypeCVRQualifiers(),
4060 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004061 if (Result.isNull())
4062 return QualType();
4063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
John McCall550e0c22009-10-21 00:40:46 +00004065 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4066 NewTL.setLBracketLoc(TL.getLBracketLoc());
4067 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004068 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004069
4070 return Result;
4071}
4072
4073template<typename Derived>
4074QualType
4075TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004076 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004077 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004078 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4079 if (ElementType.isNull())
4080 return QualType();
4081
John McCalldadc5752010-08-24 06:29:42 +00004082 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004083 = getDerived().TransformExpr(T->getSizeExpr());
4084 if (SizeResult.isInvalid())
4085 return QualType();
4086
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004087 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004088
4089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
4091 ElementType != T->getElementType() ||
4092 Size != T->getSizeExpr()) {
4093 Result = getDerived().RebuildVariableArrayType(ElementType,
4094 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004095 Size,
John McCall550e0c22009-10-21 00:40:46 +00004096 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004097 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004098 if (Result.isNull())
4099 return QualType();
4100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004101
Serge Pavlov774c6d02014-02-06 03:49:11 +00004102 // We might have constant size array now, but fortunately it has the same
4103 // location layout.
4104 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004105 NewTL.setLBracketLoc(TL.getLBracketLoc());
4106 NewTL.setRBracketLoc(TL.getRBracketLoc());
4107 NewTL.setSizeExpr(Size);
4108
4109 return Result;
4110}
4111
4112template<typename Derived>
4113QualType
4114TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004115 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004116 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004117 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4118 if (ElementType.isNull())
4119 return QualType();
4120
Richard Smith764d2fe2011-12-20 02:08:33 +00004121 // Array bounds are constant expressions.
4122 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4123 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004124
John McCall33ddac02011-01-19 10:06:00 +00004125 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4126 Expr *origSize = TL.getSizeExpr();
4127 if (!origSize) origSize = T->getSizeExpr();
4128
4129 ExprResult sizeResult
4130 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004131 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004132 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004133 return QualType();
4134
John McCall33ddac02011-01-19 10:06:00 +00004135 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004136
4137 QualType Result = TL.getType();
4138 if (getDerived().AlwaysRebuild() ||
4139 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004140 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004141 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4142 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004143 size,
John McCall550e0c22009-10-21 00:40:46 +00004144 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004145 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004146 if (Result.isNull())
4147 return QualType();
4148 }
John McCall550e0c22009-10-21 00:40:46 +00004149
4150 // We might have any sort of array type now, but fortunately they
4151 // all have the same location layout.
4152 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4153 NewTL.setLBracketLoc(TL.getLBracketLoc());
4154 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004155 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004156
4157 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
4160template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004162 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004163 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004164 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004165
4166 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167 QualType ElementType = getDerived().TransformType(T->getElementType());
4168 if (ElementType.isNull())
4169 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004170
Richard Smith764d2fe2011-12-20 02:08:33 +00004171 // Vector sizes are constant expressions.
4172 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4173 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004174
John McCalldadc5752010-08-24 06:29:42 +00004175 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004176 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177 if (Size.isInvalid())
4178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall550e0c22009-10-21 00:40:46 +00004180 QualType Result = TL.getType();
4181 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004182 ElementType != T->getElementType() ||
4183 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004184 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004185 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004187 if (Result.isNull())
4188 return QualType();
4189 }
John McCall550e0c22009-10-21 00:40:46 +00004190
4191 // Result might be dependent or not.
4192 if (isa<DependentSizedExtVectorType>(Result)) {
4193 DependentSizedExtVectorTypeLoc NewTL
4194 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4195 NewTL.setNameLoc(TL.getNameLoc());
4196 } else {
4197 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4198 NewTL.setNameLoc(TL.getNameLoc());
4199 }
4200
4201 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
4204template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004205QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004206 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004207 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208 QualType ElementType = getDerived().TransformType(T->getElementType());
4209 if (ElementType.isNull())
4210 return QualType();
4211
John McCall550e0c22009-10-21 00:40:46 +00004212 QualType Result = TL.getType();
4213 if (getDerived().AlwaysRebuild() ||
4214 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004215 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004216 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004217 if (Result.isNull())
4218 return QualType();
4219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004220
John McCall550e0c22009-10-21 00:40:46 +00004221 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4222 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004223
John McCall550e0c22009-10-21 00:40:46 +00004224 return Result;
4225}
4226
4227template<typename Derived>
4228QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004229 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004230 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004231 QualType ElementType = getDerived().TransformType(T->getElementType());
4232 if (ElementType.isNull())
4233 return QualType();
4234
4235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 ElementType != T->getElementType()) {
4238 Result = getDerived().RebuildExtVectorType(ElementType,
4239 T->getNumElements(),
4240 /*FIXME*/ SourceLocation());
4241 if (Result.isNull())
4242 return QualType();
4243 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004244
John McCall550e0c22009-10-21 00:40:46 +00004245 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4246 NewTL.setNameLoc(TL.getNameLoc());
4247
4248 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004249}
Mike Stump11289f42009-09-09 15:08:12 +00004250
David Blaikie05785d12013-02-20 22:23:23 +00004251template <typename Derived>
4252ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4253 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4254 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004255 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004256 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004257
Douglas Gregor715e4612011-01-14 22:40:04 +00004258 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004259 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004260 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004261 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004262 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004263
Douglas Gregor715e4612011-01-14 22:40:04 +00004264 TypeLocBuilder TLB;
4265 TypeLoc NewTL = OldDI->getTypeLoc();
4266 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004267
4268 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004269 OldExpansionTL.getPatternLoc());
4270 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004271 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004272
4273 Result = RebuildPackExpansionType(Result,
4274 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004275 OldExpansionTL.getEllipsisLoc(),
4276 NumExpansions);
4277 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004278 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004279
Douglas Gregor715e4612011-01-14 22:40:04 +00004280 PackExpansionTypeLoc NewExpansionTL
4281 = TLB.push<PackExpansionTypeLoc>(Result);
4282 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4283 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4284 } else
4285 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004286 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004287 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004288
John McCall8fb0d9d2011-05-01 22:35:37 +00004289 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004290 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004291
4292 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4293 OldParm->getDeclContext(),
4294 OldParm->getInnerLocStart(),
4295 OldParm->getLocation(),
4296 OldParm->getIdentifier(),
4297 NewDI->getType(),
4298 NewDI,
4299 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004300 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004301 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4302 OldParm->getFunctionScopeIndex() + indexAdjustment);
4303 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004304}
4305
4306template<typename Derived>
4307bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004308 TransformFunctionTypeParams(SourceLocation Loc,
4309 ParmVarDecl **Params, unsigned NumParams,
4310 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004311 SmallVectorImpl<QualType> &OutParamTypes,
4312 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004313 int indexAdjustment = 0;
4314
Douglas Gregordd472162011-01-07 00:20:55 +00004315 for (unsigned i = 0; i != NumParams; ++i) {
4316 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004317 assert(OldParm->getFunctionScopeIndex() == i);
4318
David Blaikie05785d12013-02-20 22:23:23 +00004319 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004320 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004321 if (OldParm->isParameterPack()) {
4322 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004323 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004324
Douglas Gregor5499af42011-01-05 23:12:31 +00004325 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004326 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004327 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004328 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4329 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004330 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4331
Douglas Gregor5499af42011-01-05 23:12:31 +00004332 // Determine whether we should expand the parameter packs.
4333 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004334 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004335 Optional<unsigned> OrigNumExpansions =
4336 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004337 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004338 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4339 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004340 Unexpanded,
4341 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004342 RetainExpansion,
4343 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004344 return true;
4345 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004346
Douglas Gregor5499af42011-01-05 23:12:31 +00004347 if (ShouldExpand) {
4348 // Expand the function parameter pack into multiple, separate
4349 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004350 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004351 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004352 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004353 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004354 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004355 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004356 OrigNumExpansions,
4357 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004358 if (!NewParm)
4359 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004360
Douglas Gregordd472162011-01-07 00:20:55 +00004361 OutParamTypes.push_back(NewParm->getType());
4362 if (PVars)
4363 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004365
4366 // If we're supposed to retain a pack expansion, do so by temporarily
4367 // forgetting the partially-substituted parameter pack.
4368 if (RetainExpansion) {
4369 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004370 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004371 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004372 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004373 OrigNumExpansions,
4374 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004375 if (!NewParm)
4376 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004378 OutParamTypes.push_back(NewParm->getType());
4379 if (PVars)
4380 PVars->push_back(NewParm);
4381 }
4382
John McCall8fb0d9d2011-05-01 22:35:37 +00004383 // The next parameter should have the same adjustment as the
4384 // last thing we pushed, but we post-incremented indexAdjustment
4385 // on every push. Also, if we push nothing, the adjustment should
4386 // go down by one.
4387 indexAdjustment--;
4388
Douglas Gregor5499af42011-01-05 23:12:31 +00004389 // We're done with the pack expansion.
4390 continue;
4391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004392
4393 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004394 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004395 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4396 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004397 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004398 NumExpansions,
4399 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004400 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004401 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004402 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004403 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004404
John McCall58f10c32010-03-11 09:03:00 +00004405 if (!NewParm)
4406 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 OutParamTypes.push_back(NewParm->getType());
4409 if (PVars)
4410 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004411 continue;
4412 }
John McCall58f10c32010-03-11 09:03:00 +00004413
4414 // Deal with the possibility that we don't have a parameter
4415 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004416 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004417 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004418 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004419 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004420 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004421 = dyn_cast<PackExpansionType>(OldType)) {
4422 // We have a function parameter pack that may need to be expanded.
4423 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004424 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
Douglas Gregor5499af42011-01-05 23:12:31 +00004427 // Determine whether we should expand the parameter packs.
4428 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004429 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004430 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004431 Unexpanded,
4432 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004433 RetainExpansion,
4434 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004435 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004437
Douglas Gregor5499af42011-01-05 23:12:31 +00004438 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004439 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004440 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004441 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4443 QualType NewType = getDerived().TransformType(Pattern);
4444 if (NewType.isNull())
4445 return true;
John McCall58f10c32010-03-11 09:03:00 +00004446
Douglas Gregordd472162011-01-07 00:20:55 +00004447 OutParamTypes.push_back(NewType);
4448 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004449 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004451
Douglas Gregor5499af42011-01-05 23:12:31 +00004452 // We're done with the pack expansion.
4453 continue;
4454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004455
Douglas Gregor48d24112011-01-10 20:53:55 +00004456 // If we're supposed to retain a pack expansion, do so by temporarily
4457 // forgetting the partially-substituted parameter pack.
4458 if (RetainExpansion) {
4459 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4460 QualType NewType = getDerived().TransformType(Pattern);
4461 if (NewType.isNull())
4462 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004463
Douglas Gregor48d24112011-01-10 20:53:55 +00004464 OutParamTypes.push_back(NewType);
4465 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004466 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004467 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004468
Chad Rosier1dcde962012-08-08 18:46:20 +00004469 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004470 // expansion.
4471 OldType = Expansion->getPattern();
4472 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004473 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4474 NewType = getDerived().TransformType(OldType);
4475 } else {
4476 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004478
Douglas Gregor5499af42011-01-05 23:12:31 +00004479 if (NewType.isNull())
4480 return true;
4481
4482 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004483 NewType = getSema().Context.getPackExpansionType(NewType,
4484 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004485
Douglas Gregordd472162011-01-07 00:20:55 +00004486 OutParamTypes.push_back(NewType);
4487 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004488 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004489 }
4490
John McCall8fb0d9d2011-05-01 22:35:37 +00004491#ifndef NDEBUG
4492 if (PVars) {
4493 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4494 if (ParmVarDecl *parm = (*PVars)[i])
4495 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004497#endif
4498
4499 return false;
4500}
John McCall58f10c32010-03-11 09:03:00 +00004501
4502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004503QualType
John McCall550e0c22009-10-21 00:40:46 +00004504TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004505 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004506 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004507}
4508
4509template<typename Derived>
4510QualType
4511TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4512 FunctionProtoTypeLoc TL,
4513 CXXRecordDecl *ThisContext,
4514 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004515 // Transform the parameters and return type.
4516 //
Richard Smithf623c962012-04-17 00:58:00 +00004517 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004518 // When the function has a trailing return type, we instantiate the
4519 // parameters before the return type, since the return type can then refer
4520 // to the parameters themselves (via decltype, sizeof, etc.).
4521 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004522 SmallVector<QualType, 4> ParamTypes;
4523 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004524 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004525
Douglas Gregor7fb25412010-10-01 18:44:50 +00004526 QualType ResultType;
4527
Richard Smith1226c602012-08-14 22:51:13 +00004528 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004529 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004530 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004531 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004532 return QualType();
4533
Douglas Gregor3024f072012-04-16 07:05:22 +00004534 {
4535 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004536 // If a declaration declares a member function or member function
4537 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004538 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004539 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004540 // declarator.
4541 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004542
Alp Toker42a16a62014-01-25 23:51:36 +00004543 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004544 if (ResultType.isNull())
4545 return QualType();
4546 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004547 }
4548 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004549 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004550 if (ResultType.isNull())
4551 return QualType();
4552
Alp Toker9cacbab2014-01-20 20:26:09 +00004553 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004554 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004555 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004556 return QualType();
4557 }
4558
Richard Smithf623c962012-04-17 00:58:00 +00004559 // FIXME: Need to transform the exception-specification too.
4560
John McCall550e0c22009-10-21 00:40:46 +00004561 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004562 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004563 T->getNumParams() != ParamTypes.size() ||
4564 !std::equal(T->param_type_begin(), T->param_type_end(),
4565 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004566 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004567 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004568 if (Result.isNull())
4569 return QualType();
4570 }
Mike Stump11289f42009-09-09 15:08:12 +00004571
John McCall550e0c22009-10-21 00:40:46 +00004572 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004573 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004574 NewTL.setLParenLoc(TL.getLParenLoc());
4575 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004576 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004577 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4578 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004579
4580 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004581}
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583template<typename Derived>
4584QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004585 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004586 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004587 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004588 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004589 if (ResultType.isNull())
4590 return QualType();
4591
4592 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004593 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004594 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4595
4596 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004597 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004598 NewTL.setLParenLoc(TL.getLParenLoc());
4599 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004600 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004601
4602 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004603}
Mike Stump11289f42009-09-09 15:08:12 +00004604
John McCallb96ec562009-12-04 22:46:56 +00004605template<typename Derived> QualType
4606TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004607 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004608 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004609 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004610 if (!D)
4611 return QualType();
4612
4613 QualType Result = TL.getType();
4614 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4615 Result = getDerived().RebuildUnresolvedUsingType(D);
4616 if (Result.isNull())
4617 return QualType();
4618 }
4619
4620 // We might get an arbitrary type spec type back. We should at
4621 // least always get a type spec type, though.
4622 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4623 NewTL.setNameLoc(TL.getNameLoc());
4624
4625 return Result;
4626}
4627
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004629QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004630 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004631 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004632 TypedefNameDecl *Typedef
4633 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4634 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004635 if (!Typedef)
4636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004637
John McCall550e0c22009-10-21 00:40:46 +00004638 QualType Result = TL.getType();
4639 if (getDerived().AlwaysRebuild() ||
4640 Typedef != T->getDecl()) {
4641 Result = getDerived().RebuildTypedefType(Typedef);
4642 if (Result.isNull())
4643 return QualType();
4644 }
Mike Stump11289f42009-09-09 15:08:12 +00004645
John McCall550e0c22009-10-21 00:40:46 +00004646 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4647 NewTL.setNameLoc(TL.getNameLoc());
4648
4649 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004653QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004654 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004655 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4657 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004658
John McCalldadc5752010-08-24 06:29:42 +00004659 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004660 if (E.isInvalid())
4661 return QualType();
4662
Eli Friedmane4f22df2012-02-29 04:03:55 +00004663 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4664 if (E.isInvalid())
4665 return QualType();
4666
John McCall550e0c22009-10-21 00:40:46 +00004667 QualType Result = TL.getType();
4668 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004669 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004670 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004671 if (Result.isNull())
4672 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004673 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004674 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall550e0c22009-10-21 00:40:46 +00004676 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004677 NewTL.setTypeofLoc(TL.getTypeofLoc());
4678 NewTL.setLParenLoc(TL.getLParenLoc());
4679 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004680
4681 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004682}
Mike Stump11289f42009-09-09 15:08:12 +00004683
4684template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004685QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004686 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004687 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4688 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4689 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004691
John McCall550e0c22009-10-21 00:40:46 +00004692 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004693 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4694 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004695 if (Result.isNull())
4696 return QualType();
4697 }
Mike Stump11289f42009-09-09 15:08:12 +00004698
John McCall550e0c22009-10-21 00:40:46 +00004699 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004700 NewTL.setTypeofLoc(TL.getTypeofLoc());
4701 NewTL.setLParenLoc(TL.getLParenLoc());
4702 NewTL.setRParenLoc(TL.getRParenLoc());
4703 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004704
4705 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004706}
Mike Stump11289f42009-09-09 15:08:12 +00004707
4708template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004709QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004710 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004711 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004712
Douglas Gregore922c772009-08-04 22:27:00 +00004713 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4715 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004716
John McCalldadc5752010-08-24 06:29:42 +00004717 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718 if (E.isInvalid())
4719 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004720
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004721 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004722 if (E.isInvalid())
4723 return QualType();
4724
John McCall550e0c22009-10-21 00:40:46 +00004725 QualType Result = TL.getType();
4726 if (getDerived().AlwaysRebuild() ||
4727 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004728 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004729 if (Result.isNull())
4730 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004731 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004732 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004733
John McCall550e0c22009-10-21 00:40:46 +00004734 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4735 NewTL.setNameLoc(TL.getNameLoc());
4736
4737 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004738}
4739
4740template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004741QualType TreeTransform<Derived>::TransformUnaryTransformType(
4742 TypeLocBuilder &TLB,
4743 UnaryTransformTypeLoc TL) {
4744 QualType Result = TL.getType();
4745 if (Result->isDependentType()) {
4746 const UnaryTransformType *T = TL.getTypePtr();
4747 QualType NewBase =
4748 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4749 Result = getDerived().RebuildUnaryTransformType(NewBase,
4750 T->getUTTKind(),
4751 TL.getKWLoc());
4752 if (Result.isNull())
4753 return QualType();
4754 }
4755
4756 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4757 NewTL.setKWLoc(TL.getKWLoc());
4758 NewTL.setParensRange(TL.getParensRange());
4759 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4760 return Result;
4761}
4762
4763template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004764QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4765 AutoTypeLoc TL) {
4766 const AutoType *T = TL.getTypePtr();
4767 QualType OldDeduced = T->getDeducedType();
4768 QualType NewDeduced;
4769 if (!OldDeduced.isNull()) {
4770 NewDeduced = getDerived().TransformType(OldDeduced);
4771 if (NewDeduced.isNull())
4772 return QualType();
4773 }
4774
4775 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004776 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4777 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004778 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004779 if (Result.isNull())
4780 return QualType();
4781 }
4782
4783 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4784 NewTL.setNameLoc(TL.getNameLoc());
4785
4786 return Result;
4787}
4788
4789template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004790QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004791 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004792 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004793 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004794 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4795 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004796 if (!Record)
4797 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004798
John McCall550e0c22009-10-21 00:40:46 +00004799 QualType Result = TL.getType();
4800 if (getDerived().AlwaysRebuild() ||
4801 Record != T->getDecl()) {
4802 Result = getDerived().RebuildRecordType(Record);
4803 if (Result.isNull())
4804 return QualType();
4805 }
Mike Stump11289f42009-09-09 15:08:12 +00004806
John McCall550e0c22009-10-21 00:40:46 +00004807 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4808 NewTL.setNameLoc(TL.getNameLoc());
4809
4810 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004811}
Mike Stump11289f42009-09-09 15:08:12 +00004812
4813template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004814QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004815 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004816 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004817 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004818 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4819 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004820 if (!Enum)
4821 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004822
John McCall550e0c22009-10-21 00:40:46 +00004823 QualType Result = TL.getType();
4824 if (getDerived().AlwaysRebuild() ||
4825 Enum != T->getDecl()) {
4826 Result = getDerived().RebuildEnumType(Enum);
4827 if (Result.isNull())
4828 return QualType();
4829 }
Mike Stump11289f42009-09-09 15:08:12 +00004830
John McCall550e0c22009-10-21 00:40:46 +00004831 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4832 NewTL.setNameLoc(TL.getNameLoc());
4833
4834 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004835}
John McCallfcc33b02009-09-05 00:15:47 +00004836
John McCalle78aac42010-03-10 03:28:59 +00004837template<typename Derived>
4838QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4839 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004841 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4842 TL.getTypePtr()->getDecl());
4843 if (!D) return QualType();
4844
4845 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4846 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4847 return T;
4848}
4849
Douglas Gregord6ff3322009-08-04 16:50:30 +00004850template<typename Derived>
4851QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004852 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004853 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004854 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004855}
4856
Mike Stump11289f42009-09-09 15:08:12 +00004857template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004858QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004859 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004860 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004861 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004862
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004863 // Substitute into the replacement type, which itself might involve something
4864 // that needs to be transformed. This only tends to occur with default
4865 // template arguments of template template parameters.
4866 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4867 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4868 if (Replacement.isNull())
4869 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004870
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004871 // Always canonicalize the replacement type.
4872 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4873 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004874 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004875 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004876
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004877 // Propagate type-source information.
4878 SubstTemplateTypeParmTypeLoc NewTL
4879 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4880 NewTL.setNameLoc(TL.getNameLoc());
4881 return Result;
4882
John McCallcebee162009-10-18 09:09:24 +00004883}
4884
4885template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004886QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4887 TypeLocBuilder &TLB,
4888 SubstTemplateTypeParmPackTypeLoc TL) {
4889 return TransformTypeSpecType(TLB, TL);
4890}
4891
4892template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004893QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004894 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004895 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004896 const TemplateSpecializationType *T = TL.getTypePtr();
4897
Douglas Gregordf846d12011-03-02 18:46:51 +00004898 // The nested-name-specifier never matters in a TemplateSpecializationType,
4899 // because we can't have a dependent nested-name-specifier anyway.
4900 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004901 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004902 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4903 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004904 if (Template.isNull())
4905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004906
John McCall31f82722010-11-12 08:19:04 +00004907 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4908}
4909
Eli Friedman0dfb8892011-10-06 23:00:33 +00004910template<typename Derived>
4911QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4912 AtomicTypeLoc TL) {
4913 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4914 if (ValueType.isNull())
4915 return QualType();
4916
4917 QualType Result = TL.getType();
4918 if (getDerived().AlwaysRebuild() ||
4919 ValueType != TL.getValueLoc().getType()) {
4920 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4921 if (Result.isNull())
4922 return QualType();
4923 }
4924
4925 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4926 NewTL.setKWLoc(TL.getKWLoc());
4927 NewTL.setLParenLoc(TL.getLParenLoc());
4928 NewTL.setRParenLoc(TL.getRParenLoc());
4929
4930 return Result;
4931}
4932
Chad Rosier1dcde962012-08-08 18:46:20 +00004933 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004934 /// container that provides a \c getArgLoc() member function.
4935 ///
4936 /// This iterator is intended to be used with the iterator form of
4937 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4938 template<typename ArgLocContainer>
4939 class TemplateArgumentLocContainerIterator {
4940 ArgLocContainer *Container;
4941 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004942
Douglas Gregorfe921a72010-12-20 23:36:19 +00004943 public:
4944 typedef TemplateArgumentLoc value_type;
4945 typedef TemplateArgumentLoc reference;
4946 typedef int difference_type;
4947 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004948
Douglas Gregorfe921a72010-12-20 23:36:19 +00004949 class pointer {
4950 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregorfe921a72010-12-20 23:36:19 +00004952 public:
4953 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004954
Douglas Gregorfe921a72010-12-20 23:36:19 +00004955 const TemplateArgumentLoc *operator->() const {
4956 return &Arg;
4957 }
4958 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004959
4960
Douglas Gregorfe921a72010-12-20 23:36:19 +00004961 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004962
Douglas Gregorfe921a72010-12-20 23:36:19 +00004963 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4964 unsigned Index)
4965 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
Douglas Gregorfe921a72010-12-20 23:36:19 +00004967 TemplateArgumentLocContainerIterator &operator++() {
4968 ++Index;
4969 return *this;
4970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Douglas Gregorfe921a72010-12-20 23:36:19 +00004972 TemplateArgumentLocContainerIterator operator++(int) {
4973 TemplateArgumentLocContainerIterator Old(*this);
4974 ++(*this);
4975 return Old;
4976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004977
Douglas Gregorfe921a72010-12-20 23:36:19 +00004978 TemplateArgumentLoc operator*() const {
4979 return Container->getArgLoc(Index);
4980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004981
Douglas Gregorfe921a72010-12-20 23:36:19 +00004982 pointer operator->() const {
4983 return pointer(Container->getArgLoc(Index));
4984 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004985
Douglas Gregorfe921a72010-12-20 23:36:19 +00004986 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004987 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004988 return X.Container == Y.Container && X.Index == Y.Index;
4989 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004990
Douglas Gregorfe921a72010-12-20 23:36:19 +00004991 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004992 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004993 return !(X == Y);
4994 }
4995 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004996
4997
John McCall31f82722010-11-12 08:19:04 +00004998template <typename Derived>
4999QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5000 TypeLocBuilder &TLB,
5001 TemplateSpecializationTypeLoc TL,
5002 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005003 TemplateArgumentListInfo NewTemplateArgs;
5004 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5005 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005006 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5007 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005008 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005009 ArgIterator(TL, TL.getNumArgs()),
5010 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005012
John McCall0ad16662009-10-29 08:12:44 +00005013 // FIXME: maybe don't rebuild if all the template arguments are the same.
5014
5015 QualType Result =
5016 getDerived().RebuildTemplateSpecializationType(Template,
5017 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005018 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005019
5020 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005021 // Specializations of template template parameters are represented as
5022 // TemplateSpecializationTypes, and substitution of type alias templates
5023 // within a dependent context can transform them into
5024 // DependentTemplateSpecializationTypes.
5025 if (isa<DependentTemplateSpecializationType>(Result)) {
5026 DependentTemplateSpecializationTypeLoc NewTL
5027 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005028 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005029 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005030 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005031 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005032 NewTL.setLAngleLoc(TL.getLAngleLoc());
5033 NewTL.setRAngleLoc(TL.getRAngleLoc());
5034 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5035 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5036 return Result;
5037 }
5038
John McCall0ad16662009-10-29 08:12:44 +00005039 TemplateSpecializationTypeLoc NewTL
5040 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005041 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005042 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5043 NewTL.setLAngleLoc(TL.getLAngleLoc());
5044 NewTL.setRAngleLoc(TL.getRAngleLoc());
5045 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5046 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005047 }
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCall0ad16662009-10-29 08:12:44 +00005049 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005050}
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregor5a064722011-02-28 17:23:35 +00005052template <typename Derived>
5053QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5054 TypeLocBuilder &TLB,
5055 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005056 TemplateName Template,
5057 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005058 TemplateArgumentListInfo NewTemplateArgs;
5059 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5060 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5061 typedef TemplateArgumentLocContainerIterator<
5062 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005063 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005064 ArgIterator(TL, TL.getNumArgs()),
5065 NewTemplateArgs))
5066 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005067
Douglas Gregor5a064722011-02-28 17:23:35 +00005068 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005069
Douglas Gregor5a064722011-02-28 17:23:35 +00005070 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5071 QualType Result
5072 = getSema().Context.getDependentTemplateSpecializationType(
5073 TL.getTypePtr()->getKeyword(),
5074 DTN->getQualifier(),
5075 DTN->getIdentifier(),
5076 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005077
Douglas Gregor5a064722011-02-28 17:23:35 +00005078 DependentTemplateSpecializationTypeLoc NewTL
5079 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005080 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005081 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005082 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005083 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005084 NewTL.setLAngleLoc(TL.getLAngleLoc());
5085 NewTL.setRAngleLoc(TL.getRAngleLoc());
5086 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5087 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5088 return Result;
5089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005090
5091 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005092 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005093 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005094 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005095
Douglas Gregor5a064722011-02-28 17:23:35 +00005096 if (!Result.isNull()) {
5097 /// FIXME: Wrap this in an elaborated-type-specifier?
5098 TemplateSpecializationTypeLoc NewTL
5099 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005100 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005101 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005102 NewTL.setLAngleLoc(TL.getLAngleLoc());
5103 NewTL.setRAngleLoc(TL.getRAngleLoc());
5104 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5105 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005107
Douglas Gregor5a064722011-02-28 17:23:35 +00005108 return Result;
5109}
5110
Mike Stump11289f42009-09-09 15:08:12 +00005111template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005112QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005113TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005114 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005115 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005116
Douglas Gregor844cb502011-03-01 18:12:44 +00005117 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005118 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005119 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005120 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005121 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5122 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005123 return QualType();
5124 }
Mike Stump11289f42009-09-09 15:08:12 +00005125
John McCall31f82722010-11-12 08:19:04 +00005126 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5127 if (NamedT.isNull())
5128 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005129
Richard Smith3f1b5d02011-05-05 21:57:07 +00005130 // C++0x [dcl.type.elab]p2:
5131 // If the identifier resolves to a typedef-name or the simple-template-id
5132 // resolves to an alias template specialization, the
5133 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005134 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5135 if (const TemplateSpecializationType *TST =
5136 NamedT->getAs<TemplateSpecializationType>()) {
5137 TemplateName Template = TST->getTemplateName();
5138 if (TypeAliasTemplateDecl *TAT =
5139 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5140 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5141 diag::err_tag_reference_non_tag) << 4;
5142 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5143 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005144 }
5145 }
5146
John McCall550e0c22009-10-21 00:40:46 +00005147 QualType Result = TL.getType();
5148 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005149 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005150 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005151 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005152 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005153 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005154 if (Result.isNull())
5155 return QualType();
5156 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005157
Abramo Bagnara6150c882010-05-11 21:36:43 +00005158 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005159 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005160 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005162}
Mike Stump11289f42009-09-09 15:08:12 +00005163
5164template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005165QualType TreeTransform<Derived>::TransformAttributedType(
5166 TypeLocBuilder &TLB,
5167 AttributedTypeLoc TL) {
5168 const AttributedType *oldType = TL.getTypePtr();
5169 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5170 if (modifiedType.isNull())
5171 return QualType();
5172
5173 QualType result = TL.getType();
5174
5175 // FIXME: dependent operand expressions?
5176 if (getDerived().AlwaysRebuild() ||
5177 modifiedType != oldType->getModifiedType()) {
5178 // TODO: this is really lame; we should really be rebuilding the
5179 // equivalent type from first principles.
5180 QualType equivalentType
5181 = getDerived().TransformType(oldType->getEquivalentType());
5182 if (equivalentType.isNull())
5183 return QualType();
5184 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5185 modifiedType,
5186 equivalentType);
5187 }
5188
5189 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5190 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5191 if (TL.hasAttrOperand())
5192 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5193 if (TL.hasAttrExprOperand())
5194 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5195 else if (TL.hasAttrEnumOperand())
5196 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5197
5198 return result;
5199}
5200
5201template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005202QualType
5203TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5204 ParenTypeLoc TL) {
5205 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5206 if (Inner.isNull())
5207 return QualType();
5208
5209 QualType Result = TL.getType();
5210 if (getDerived().AlwaysRebuild() ||
5211 Inner != TL.getInnerLoc().getType()) {
5212 Result = getDerived().RebuildParenType(Inner);
5213 if (Result.isNull())
5214 return QualType();
5215 }
5216
5217 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5218 NewTL.setLParenLoc(TL.getLParenLoc());
5219 NewTL.setRParenLoc(TL.getRParenLoc());
5220 return Result;
5221}
5222
5223template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005224QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005225 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005226 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005227
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005228 NestedNameSpecifierLoc QualifierLoc
5229 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5230 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005232
John McCallc392f372010-06-11 00:33:02 +00005233 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005234 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005235 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005236 QualifierLoc,
5237 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005238 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005239 if (Result.isNull())
5240 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241
Abramo Bagnarad7548482010-05-19 21:37:53 +00005242 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5243 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005244 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5245
Abramo Bagnarad7548482010-05-19 21:37:53 +00005246 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005247 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005248 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005249 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005250 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005251 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005252 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005253 NewTL.setNameLoc(TL.getNameLoc());
5254 }
John McCall550e0c22009-10-21 00:40:46 +00005255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256}
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregord6ff3322009-08-04 16:50:30 +00005258template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005259QualType TreeTransform<Derived>::
5260 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005261 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005262 NestedNameSpecifierLoc QualifierLoc;
5263 if (TL.getQualifierLoc()) {
5264 QualifierLoc
5265 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5266 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005267 return QualType();
5268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005269
John McCall31f82722010-11-12 08:19:04 +00005270 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005271 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005272}
5273
5274template<typename Derived>
5275QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005276TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5277 DependentTemplateSpecializationTypeLoc TL,
5278 NestedNameSpecifierLoc QualifierLoc) {
5279 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregora7a795b2011-03-01 20:11:18 +00005281 TemplateArgumentListInfo NewTemplateArgs;
5282 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5283 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005284
Douglas Gregora7a795b2011-03-01 20:11:18 +00005285 typedef TemplateArgumentLocContainerIterator<
5286 DependentTemplateSpecializationTypeLoc> ArgIterator;
5287 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5288 ArgIterator(TL, TL.getNumArgs()),
5289 NewTemplateArgs))
5290 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005291
Douglas Gregora7a795b2011-03-01 20:11:18 +00005292 QualType Result
5293 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5294 QualifierLoc,
5295 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005296 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005297 NewTemplateArgs);
5298 if (Result.isNull())
5299 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
Douglas Gregora7a795b2011-03-01 20:11:18 +00005301 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5302 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005303
Douglas Gregora7a795b2011-03-01 20:11:18 +00005304 // Copy information relevant to the template specialization.
5305 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005306 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005307 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005308 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005309 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5310 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005311 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005312 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005313
Douglas Gregora7a795b2011-03-01 20:11:18 +00005314 // Copy information relevant to the elaborated type.
5315 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005316 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005317 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005318 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5319 DependentTemplateSpecializationTypeLoc SpecTL
5320 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005321 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005322 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005323 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005324 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005325 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5326 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005327 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005328 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005329 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005330 TemplateSpecializationTypeLoc SpecTL
5331 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005332 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005333 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005334 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5335 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005336 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005337 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005338 }
5339 return Result;
5340}
5341
5342template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005343QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5344 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005345 QualType Pattern
5346 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005347 if (Pattern.isNull())
5348 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005349
5350 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005351 if (getDerived().AlwaysRebuild() ||
5352 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005353 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005354 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005355 TL.getEllipsisLoc(),
5356 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005357 if (Result.isNull())
5358 return QualType();
5359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
Douglas Gregor822d0302011-01-12 17:07:58 +00005361 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5362 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5363 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005364}
5365
5366template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005367QualType
5368TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005369 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005370 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005371 TLB.pushFullCopy(TL);
5372 return TL.getType();
5373}
5374
5375template<typename Derived>
5376QualType
5377TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005378 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005379 // ObjCObjectType is never dependent.
5380 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005381 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005382}
Mike Stump11289f42009-09-09 15:08:12 +00005383
5384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005385QualType
5386TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005387 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005388 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005389 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005390 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005391}
5392
Douglas Gregord6ff3322009-08-04 16:50:30 +00005393//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005394// Statement transformation
5395//===----------------------------------------------------------------------===//
5396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005397StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005398TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005399 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005400}
5401
5402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005403StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005404TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5405 return getDerived().TransformCompoundStmt(S, false);
5406}
5407
5408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005410TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005411 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005412 Sema::CompoundScopeRAII CompoundScope(getSema());
5413
John McCall1ababa62010-08-27 19:56:05 +00005414 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005415 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005416 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005417 for (auto *B : S->body()) {
5418 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005419 if (Result.isInvalid()) {
5420 // Immediately fail if this was a DeclStmt, since it's very
5421 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005422 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005423 return StmtError();
5424
5425 // Otherwise, just keep processing substatements and fail later.
5426 SubStmtInvalid = true;
5427 continue;
5428 }
Mike Stump11289f42009-09-09 15:08:12 +00005429
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005430 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005431 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 }
Mike Stump11289f42009-09-09 15:08:12 +00005433
John McCall1ababa62010-08-27 19:56:05 +00005434 if (SubStmtInvalid)
5435 return StmtError();
5436
Douglas Gregorebe10102009-08-20 07:17:43 +00005437 if (!getDerived().AlwaysRebuild() &&
5438 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005439 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005440
5441 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005442 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005443 S->getRBracLoc(),
5444 IsStmtExpr);
5445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregorebe10102009-08-20 07:17:43 +00005447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005449TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005450 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005451 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005452 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5453 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005454
Eli Friedman06577382009-11-19 03:14:00 +00005455 // Transform the left-hand case value.
5456 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005457 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005458 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005459 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005460
Eli Friedman06577382009-11-19 03:14:00 +00005461 // Transform the right-hand case value (for the GNU case-range extension).
5462 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005463 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005464 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005466 }
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregorebe10102009-08-20 07:17:43 +00005468 // Build the case statement.
5469 // Case statements are always rebuilt so that they will attached to their
5470 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005471 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005472 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005473 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005474 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 S->getColonLoc());
5476 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005480 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005483
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005485 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005486}
5487
5488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 // Transform the statement following the default 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 // Default statements are always rebuilt
5497 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005498 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005499}
Mike Stump11289f42009-09-09 15:08:12 +00005500
Douglas Gregorebe10102009-08-20 07:17:43 +00005501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005502StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005503TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
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
Chris Lattnercab02a62011-02-17 20:34:02 +00005508 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5509 S->getDecl());
5510 if (!LD)
5511 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005512
5513
Douglas Gregorebe10102009-08-20 07:17:43 +00005514 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005515 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005516 cast<LabelDecl>(LD), SourceLocation(),
5517 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005518}
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregorebe10102009-08-20 07:17:43 +00005520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005521StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005522TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5523 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5524 if (SubStmt.isInvalid())
5525 return StmtError();
5526
5527 // TODO: transform attributes
5528 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5529 return S;
5530
5531 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5532 S->getAttrs(),
5533 SubStmt.get());
5534}
5535
5536template<typename Derived>
5537StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005538TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005539 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005540 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005541 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005542 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005543 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005544 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005545 getDerived().TransformDefinition(
5546 S->getConditionVariable()->getLocation(),
5547 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005548 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005550 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005551 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005553 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005555
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005556 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005557 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005558 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005559 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005560 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005562
John McCallb268a282010-08-23 23:25:46 +00005563 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005564 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005566
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005567 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005568 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005570
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005572 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005573 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005577 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005578 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregorebe10102009-08-20 07:17:43 +00005581 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005582 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005583 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005584 Then.get() == S->getThen() &&
5585 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005586 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005588 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005589 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005590 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005591}
5592
5593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005595TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005597 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005598 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005599 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005600 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005601 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005602 getDerived().TransformDefinition(
5603 S->getConditionVariable()->getLocation(),
5604 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005605 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005607 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005608 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005609
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005610 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005612 }
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005615 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005616 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005617 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005618 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005619 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005622 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005624 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregorebe10102009-08-20 07:17:43 +00005626 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005627 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5628 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005629}
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregorebe10102009-08-20 07:17:43 +00005631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005632StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005633TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005634 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005635 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005636 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005637 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005638 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005639 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005640 getDerived().TransformDefinition(
5641 S->getConditionVariable()->getLocation(),
5642 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005643 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005645 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005646 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005647
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005648 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005650
5651 if (S->getCond()) {
5652 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005653 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5654 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005655 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005656 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005658 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005659 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005660 }
Mike Stump11289f42009-09-09 15:08:12 +00005661
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005662 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005663 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005667 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005672 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005673 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005675 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005677 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005678 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregorebe10102009-08-20 07:17:43 +00005681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005682StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005683TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005685 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005689 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005690 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005691 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005693
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 if (!getDerived().AlwaysRebuild() &&
5695 Cond.get() == S->getCond() &&
5696 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005697 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005698
John McCallb268a282010-08-23 23:25:46 +00005699 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5700 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 S->getRParenLoc());
5702}
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005706TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005707 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005708 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005709 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005710 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregorebe10102009-08-20 07:17:43 +00005712 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005713 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005714 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005715 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005716 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005717 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005718 getDerived().TransformDefinition(
5719 S->getConditionVariable()->getLocation(),
5720 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005721 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005723 } else {
5724 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005726 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005728
5729 if (S->getCond()) {
5730 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005731 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5732 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005733 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005734 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005736
John McCallb268a282010-08-23 23:25:46 +00005737 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005738 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005739 }
Mike Stump11289f42009-09-09 15:08:12 +00005740
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005741 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005742 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005743 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005744
Douglas Gregorebe10102009-08-20 07:17:43 +00005745 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005746 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005747 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005749
Richard Smith945f8d32013-01-14 22:39:08 +00005750 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005751 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005752 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005753
Douglas Gregorebe10102009-08-20 07:17:43 +00005754 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005755 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005756 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005757 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregorebe10102009-08-20 07:17:43 +00005759 if (!getDerived().AlwaysRebuild() &&
5760 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005761 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005762 Inc.get() == S->getInc() &&
5763 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005764 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005765
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005767 Init.get(), FullCond, ConditionVar,
5768 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005769}
5770
5771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005772StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005773TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005774 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5775 S->getLabel());
5776 if (!LD)
5777 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005778
Douglas Gregorebe10102009-08-20 07:17:43 +00005779 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005780 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005781 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005782}
5783
5784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005785StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005786TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005787 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005788 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005790 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorebe10102009-08-20 07:17:43 +00005792 if (!getDerived().AlwaysRebuild() &&
5793 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005794 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005795
5796 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005797 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005798}
5799
5800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005802TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005803 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005804}
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregorebe10102009-08-20 07:17:43 +00005806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005807StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005808TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005809 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005810}
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregorebe10102009-08-20 07:17:43 +00005812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005813StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005814TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005815 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005816 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005817 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005818
Mike Stump11289f42009-09-09 15:08:12 +00005819 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005820 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005821 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005827 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005828 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005829 for (auto *D : S->decls()) {
5830 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005831 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005832 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005833
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005834 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005835 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 Decls.push_back(Transformed);
5838 }
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregorebe10102009-08-20 07:17:43 +00005840 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005841 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005842
Rafael Espindolaab417692013-07-09 12:05:01 +00005843 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregorebe10102009-08-20 07:17:43 +00005846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005848TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
Benjamin Kramerf0623432012-08-23 22:51:59 +00005850 SmallVector<Expr*, 8> Constraints;
5851 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005852 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005853
John McCalldadc5752010-08-24 06:29:42 +00005854 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005855 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005856
5857 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Anders Carlssonaaeef072010-01-24 05:50:09 +00005859 // Go through the outputs.
5860 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005861 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Anders Carlssonaaeef072010-01-24 05:50:09 +00005863 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005864 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
Anders Carlssonaaeef072010-01-24 05:50:09 +00005866 // Transform the output expr.
5867 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005868 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005869 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
Anders Carlssonaaeef072010-01-24 05:50:09 +00005872 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005873
John McCallb268a282010-08-23 23:25:46 +00005874 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Anders Carlssonaaeef072010-01-24 05:50:09 +00005877 // Go through the inputs.
5878 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005879 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
Anders Carlssonaaeef072010-01-24 05:50:09 +00005881 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005882 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
Anders Carlssonaaeef072010-01-24 05:50:09 +00005884 // Transform the input expr.
5885 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005887 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
Anders Carlssonaaeef072010-01-24 05:50:09 +00005890 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
John McCallb268a282010-08-23 23:25:46 +00005892 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005894
Anders Carlssonaaeef072010-01-24 05:50:09 +00005895 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005896 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005897
5898 // Go through the clobbers.
5899 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005900 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005901
5902 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005903 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005904 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5905 S->isVolatile(), S->getNumOutputs(),
5906 S->getNumInputs(), Names.data(),
5907 Constraints, Exprs, AsmString.get(),
5908 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005909}
5910
Chad Rosier32503022012-06-11 20:47:18 +00005911template<typename Derived>
5912StmtResult
5913TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005914 ArrayRef<Token> AsmToks =
5915 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005916
John McCallf413f5e2013-05-03 00:10:13 +00005917 bool HadError = false, HadChange = false;
5918
5919 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5920 SmallVector<Expr*, 8> TransformedExprs;
5921 TransformedExprs.reserve(SrcExprs.size());
5922 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5923 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5924 if (!Result.isUsable()) {
5925 HadError = true;
5926 } else {
5927 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005928 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005929 }
5930 }
5931
5932 if (HadError) return StmtError();
5933 if (!HadChange && !getDerived().AlwaysRebuild())
5934 return Owned(S);
5935
Chad Rosierb6f46c12012-08-15 16:53:30 +00005936 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005937 AsmToks, S->getAsmString(),
5938 S->getNumOutputs(), S->getNumInputs(),
5939 S->getAllConstraints(), S->getClobbers(),
5940 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005941}
Douglas Gregorebe10102009-08-20 07:17:43 +00005942
5943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005944StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005945TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005946 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005947 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005948 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005949 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005950
Douglas Gregor96c79492010-04-23 22:50:49 +00005951 // Transform the @catch statements (if present).
5952 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005953 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005954 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005955 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005956 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005958 if (Catch.get() != S->getCatchStmt(I))
5959 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005960 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005962
Douglas Gregor306de2f2010-04-22 23:59:56 +00005963 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005964 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005965 if (S->getFinallyStmt()) {
5966 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5967 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005969 }
5970
5971 // If nothing changed, just retain this statement.
5972 if (!getDerived().AlwaysRebuild() &&
5973 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005974 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005975 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005976 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005977
Douglas Gregor306de2f2010-04-22 23:59:56 +00005978 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005979 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005980 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005981}
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregorebe10102009-08-20 07:17:43 +00005983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005984StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005985TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005986 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005987 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005988 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005989 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005990 if (FromVar->getTypeSourceInfo()) {
5991 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5992 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005993 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005996 QualType T;
5997 if (TSInfo)
5998 T = TSInfo->getType();
5999 else {
6000 T = getDerived().TransformType(FromVar->getType());
6001 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006002 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006004
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006005 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6006 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006009
John McCalldadc5752010-08-24 06:29:42 +00006010 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006011 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
6014 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006015 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006016 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006017}
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregorebe10102009-08-20 07:17:43 +00006019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006020StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006021TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006022 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006023 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006024 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006025 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006026
Douglas Gregor306de2f2010-04-22 23:59:56 +00006027 // If nothing changed, just retain this statement.
6028 if (!getDerived().AlwaysRebuild() &&
6029 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006030 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006031
6032 // Build a new statement.
6033 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006034 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregorebe10102009-08-20 07:17:43 +00006037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006039TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006040 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006041 if (S->getThrowExpr()) {
6042 Operand = getDerived().TransformExpr(S->getThrowExpr());
6043 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006044 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006046
Douglas Gregor2900c162010-04-22 21:44:01 +00006047 if (!getDerived().AlwaysRebuild() &&
6048 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006049 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006050
John McCallb268a282010-08-23 23:25:46 +00006051 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
Douglas Gregorebe10102009-08-20 07:17:43 +00006054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006056TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006057 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006058 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006059 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006060 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006062 Object =
6063 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6064 Object.get());
6065 if (Object.isInvalid())
6066 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006067
Douglas Gregor6148de72010-04-22 22:01:21 +00006068 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006069 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006070 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006072
Douglas Gregor6148de72010-04-22 22:01:21 +00006073 // If nothing change, just retain the current statement.
6074 if (!getDerived().AlwaysRebuild() &&
6075 Object.get() == S->getSynchExpr() &&
6076 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006077 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006078
6079 // Build a new statement.
6080 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006081 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006082}
6083
6084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085StmtResult
John McCall31168b02011-06-15 23:02:42 +00006086TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6087 ObjCAutoreleasePoolStmt *S) {
6088 // Transform the body.
6089 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6090 if (Body.isInvalid())
6091 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006092
John McCall31168b02011-06-15 23:02:42 +00006093 // If nothing changed, just retain this statement.
6094 if (!getDerived().AlwaysRebuild() &&
6095 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006096 return S;
John McCall31168b02011-06-15 23:02:42 +00006097
6098 // Build a new statement.
6099 return getDerived().RebuildObjCAutoreleasePoolStmt(
6100 S->getAtLoc(), Body.get());
6101}
6102
6103template<typename Derived>
6104StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006105TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006106 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006107 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006108 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006109 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006111
Douglas Gregorf68a5082010-04-22 23:10:45 +00006112 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006113 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006114 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006115 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006116
Douglas Gregorf68a5082010-04-22 23:10:45 +00006117 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006118 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006119 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
Douglas Gregorf68a5082010-04-22 23:10:45 +00006122 // If nothing changed, just retain this statement.
6123 if (!getDerived().AlwaysRebuild() &&
6124 Element.get() == S->getElement() &&
6125 Collection.get() == S->getCollection() &&
6126 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006127 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006128
Douglas Gregorf68a5082010-04-22 23:10:45 +00006129 // Build a new statement.
6130 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006131 Element.get(),
6132 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006133 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006134 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006135}
6136
David Majnemer5f7efef2013-10-15 09:50:08 +00006137template <typename Derived>
6138StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006140 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006141 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6142 TypeSourceInfo *T =
6143 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006144 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006146
David Majnemer5f7efef2013-10-15 09:50:08 +00006147 Var = getDerived().RebuildExceptionDecl(
6148 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6149 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006150 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006151 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 }
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregorebe10102009-08-20 07:17:43 +00006154 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006155 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006156 if (Handler.isInvalid())
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 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006161 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006162
David Majnemer5f7efef2013-10-15 09:50:08 +00006163 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006164}
Mike Stump11289f42009-09-09 15:08:12 +00006165
David Majnemer5f7efef2013-10-15 09:50:08 +00006166template <typename Derived>
6167StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006168 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006169 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 // Transform the handlers.
6174 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006175 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006176 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006177 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006182 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 }
Mike Stump11289f42009-09-09 15:08:12 +00006184
David Majnemer5f7efef2013-10-15 09:50:08 +00006185 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006187 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006188
John McCallb268a282010-08-23 23:25:46 +00006189 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006190 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006191}
Mike Stump11289f42009-09-09 15:08:12 +00006192
Richard Smith02e85f32011-04-14 22:09:26 +00006193template<typename Derived>
6194StmtResult
6195TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6196 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6197 if (Range.isInvalid())
6198 return StmtError();
6199
6200 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6201 if (BeginEnd.isInvalid())
6202 return StmtError();
6203
6204 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6205 if (Cond.isInvalid())
6206 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006207 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006208 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006209 if (Cond.isInvalid())
6210 return StmtError();
6211 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006212 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006213
6214 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6215 if (Inc.isInvalid())
6216 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006217 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006218 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006219
6220 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6221 if (LoopVar.isInvalid())
6222 return StmtError();
6223
6224 StmtResult NewStmt = S;
6225 if (getDerived().AlwaysRebuild() ||
6226 Range.get() != S->getRangeStmt() ||
6227 BeginEnd.get() != S->getBeginEndStmt() ||
6228 Cond.get() != S->getCond() ||
6229 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006230 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006231 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6232 S->getColonLoc(), Range.get(),
6233 BeginEnd.get(), Cond.get(),
6234 Inc.get(), LoopVar.get(),
6235 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006236 if (NewStmt.isInvalid())
6237 return StmtError();
6238 }
Richard Smith02e85f32011-04-14 22:09:26 +00006239
6240 StmtResult Body = getDerived().TransformStmt(S->getBody());
6241 if (Body.isInvalid())
6242 return StmtError();
6243
6244 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6245 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006246 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006247 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6248 S->getColonLoc(), Range.get(),
6249 BeginEnd.get(), Cond.get(),
6250 Inc.get(), LoopVar.get(),
6251 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006252 if (NewStmt.isInvalid())
6253 return StmtError();
6254 }
Richard Smith02e85f32011-04-14 22:09:26 +00006255
6256 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006257 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006258
6259 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6260}
6261
John Wiegley1c0675e2011-04-28 01:08:34 +00006262template<typename Derived>
6263StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006264TreeTransform<Derived>::TransformMSDependentExistsStmt(
6265 MSDependentExistsStmt *S) {
6266 // Transform the nested-name-specifier, if any.
6267 NestedNameSpecifierLoc QualifierLoc;
6268 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006269 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006270 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6271 if (!QualifierLoc)
6272 return StmtError();
6273 }
6274
6275 // Transform the declaration name.
6276 DeclarationNameInfo NameInfo = S->getNameInfo();
6277 if (NameInfo.getName()) {
6278 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6279 if (!NameInfo.getName())
6280 return StmtError();
6281 }
6282
6283 // Check whether anything changed.
6284 if (!getDerived().AlwaysRebuild() &&
6285 QualifierLoc == S->getQualifierLoc() &&
6286 NameInfo.getName() == S->getNameInfo().getName())
6287 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006288
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006289 // Determine whether this name exists, if we can.
6290 CXXScopeSpec SS;
6291 SS.Adopt(QualifierLoc);
6292 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006293 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006294 case Sema::IER_Exists:
6295 if (S->isIfExists())
6296 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006297
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006298 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6299
6300 case Sema::IER_DoesNotExist:
6301 if (S->isIfNotExists())
6302 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006303
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006304 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006306 case Sema::IER_Dependent:
6307 Dependent = true;
6308 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006309
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006310 case Sema::IER_Error:
6311 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006313
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006314 // We need to continue with the instantiation, so do so now.
6315 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6316 if (SubStmt.isInvalid())
6317 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006318
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006319 // If we have resolved the name, just transform to the substatement.
6320 if (!Dependent)
6321 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006323 // The name is still dependent, so build a dependent expression again.
6324 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6325 S->isIfExists(),
6326 QualifierLoc,
6327 NameInfo,
6328 SubStmt.get());
6329}
6330
6331template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006332ExprResult
6333TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6334 NestedNameSpecifierLoc QualifierLoc;
6335 if (E->getQualifierLoc()) {
6336 QualifierLoc
6337 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6338 if (!QualifierLoc)
6339 return ExprError();
6340 }
6341
6342 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6343 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6344 if (!PD)
6345 return ExprError();
6346
6347 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6348 if (Base.isInvalid())
6349 return ExprError();
6350
6351 return new (SemaRef.getASTContext())
6352 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6353 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6354 QualifierLoc, E->getMemberLoc());
6355}
6356
David Majnemerfad8f482013-10-15 09:33:02 +00006357template <typename Derived>
6358StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006359 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006360 if (TryBlock.isInvalid())
6361 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006362
6363 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006364 if (Handler.isInvalid())
6365 return StmtError();
6366
David Majnemerfad8f482013-10-15 09:33:02 +00006367 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6368 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006369 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006370
Warren Huntb530bc02014-07-19 00:45:07 +00006371 return getDerived().RebuildSEHTryStmt(
6372 S->getIsCXXTry(), S->getTryLoc(), TryBlock.get(), Handler.get(),
6373 S->getHandlerIndex(), S->getHandlerParentIndex());
John Wiegley1c0675e2011-04-28 01:08:34 +00006374}
6375
David Majnemerfad8f482013-10-15 09:33:02 +00006376template <typename Derived>
6377StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006378 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006379 if (Block.isInvalid())
6380 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006381
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006382 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006383}
6384
David Majnemerfad8f482013-10-15 09:33:02 +00006385template <typename Derived>
6386StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006387 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006388 if (FilterExpr.isInvalid())
6389 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006390
David Majnemer7e755502013-10-15 09:30:14 +00006391 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006392 if (Block.isInvalid())
6393 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006394
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006395 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6396 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006397}
6398
David Majnemerfad8f482013-10-15 09:33:02 +00006399template <typename Derived>
6400StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6401 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006402 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6403 else
6404 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6405}
6406
Nico Weber9b982072014-07-07 00:12:30 +00006407template<typename Derived>
6408StmtResult
6409TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6410 return S;
6411}
6412
Alexander Musman64d33f12014-06-04 07:53:32 +00006413//===----------------------------------------------------------------------===//
6414// OpenMP directive transformation
6415//===----------------------------------------------------------------------===//
6416template <typename Derived>
6417StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6418 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006419
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006420 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006421 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006422 ArrayRef<OMPClause *> Clauses = D->clauses();
6423 TClauses.reserve(Clauses.size());
6424 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6425 I != E; ++I) {
6426 if (*I) {
6427 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006428 if (Clause)
6429 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006430 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006431 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006432 }
6433 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006434 StmtResult AssociatedStmt;
6435 if (D->hasAssociatedStmt()) {
6436 if (!D->getAssociatedStmt()) {
6437 return StmtError();
6438 }
6439 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6440 if (AssociatedStmt.isInvalid()) {
6441 return StmtError();
6442 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006443 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006444 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006445 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006446 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006447
Alexander Musman64d33f12014-06-04 07:53:32 +00006448 return getDerived().RebuildOMPExecutableDirective(
6449 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6450 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006451}
6452
Alexander Musman64d33f12014-06-04 07:53:32 +00006453template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006454StmtResult
6455TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6456 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006457 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6458 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006459 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6460 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6461 return Res;
6462}
6463
Alexander Musman64d33f12014-06-04 07:53:32 +00006464template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006465StmtResult
6466TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6467 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006468 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6469 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006470 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6471 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006472 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006473}
6474
Alexey Bataevf29276e2014-06-18 04:14:57 +00006475template <typename Derived>
6476StmtResult
6477TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6478 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006479 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6480 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006481 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6482 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6483 return Res;
6484}
6485
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006486template <typename Derived>
6487StmtResult
6488TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6489 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006490 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6491 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006492 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6493 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6494 return Res;
6495}
6496
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006497template <typename Derived>
6498StmtResult
6499TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6500 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006501 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6502 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006503 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6504 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6505 return Res;
6506}
6507
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006508template <typename Derived>
6509StmtResult
6510TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6511 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006512 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6513 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006514 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6515 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6516 return Res;
6517}
6518
Alexey Bataev4acb8592014-07-07 13:01:15 +00006519template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006520StmtResult
6521TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6522 DeclarationNameInfo DirName;
6523 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6524 D->getLocStart());
6525 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6526 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6527 return Res;
6528}
6529
6530template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006531StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6532 OMPParallelForDirective *D) {
6533 DeclarationNameInfo DirName;
6534 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6535 nullptr, D->getLocStart());
6536 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6537 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6538 return Res;
6539}
6540
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006541template <typename Derived>
6542StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6543 OMPParallelSectionsDirective *D) {
6544 DeclarationNameInfo DirName;
6545 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6546 nullptr, D->getLocStart());
6547 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6548 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6549 return Res;
6550}
6551
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006552template <typename Derived>
6553StmtResult
6554TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6555 DeclarationNameInfo DirName;
6556 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6557 D->getLocStart());
6558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6560 return Res;
6561}
6562
Alexey Bataev68446b72014-07-18 07:47:19 +00006563template <typename Derived>
6564StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6565 OMPTaskyieldDirective *D) {
6566 DeclarationNameInfo DirName;
6567 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6568 D->getLocStart());
6569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6570 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6571 return Res;
6572}
6573
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006574template <typename Derived>
6575StmtResult
6576TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6577 DeclarationNameInfo DirName;
6578 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6579 D->getLocStart());
6580 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6581 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6582 return Res;
6583}
6584
Alexey Bataev2df347a2014-07-18 10:17:07 +00006585template <typename Derived>
6586StmtResult
6587TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6588 DeclarationNameInfo DirName;
6589 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6590 D->getLocStart());
6591 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6592 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6593 return Res;
6594}
6595
Alexander Musman64d33f12014-06-04 07:53:32 +00006596//===----------------------------------------------------------------------===//
6597// OpenMP clause transformation
6598//===----------------------------------------------------------------------===//
6599template <typename Derived>
6600OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006601 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6602 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006603 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006604 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006605 C->getLParenLoc(), C->getLocEnd());
6606}
6607
Alexander Musman64d33f12014-06-04 07:53:32 +00006608template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006609OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6610 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6611 if (Cond.isInvalid())
6612 return nullptr;
6613 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6614 C->getLParenLoc(), C->getLocEnd());
6615}
6616
6617template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006618OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006619TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6620 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6621 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006622 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006623 return getDerived().RebuildOMPNumThreadsClause(
6624 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006625}
6626
Alexey Bataev62c87d22014-03-21 04:51:18 +00006627template <typename Derived>
6628OMPClause *
6629TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6630 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6631 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006632 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006633 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006634 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006635}
6636
Alexander Musman8bd31e62014-05-27 15:12:19 +00006637template <typename Derived>
6638OMPClause *
6639TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6640 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6641 if (E.isInvalid())
6642 return 0;
6643 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006644 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006645}
6646
Alexander Musman64d33f12014-06-04 07:53:32 +00006647template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006648OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006649TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006650 return getDerived().RebuildOMPDefaultClause(
6651 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6652 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006653}
6654
Alexander Musman64d33f12014-06-04 07:53:32 +00006655template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006656OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006657TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006658 return getDerived().RebuildOMPProcBindClause(
6659 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6660 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006661}
6662
Alexander Musman64d33f12014-06-04 07:53:32 +00006663template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006664OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006665TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6666 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6667 if (E.isInvalid())
6668 return nullptr;
6669 return getDerived().RebuildOMPScheduleClause(
6670 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6671 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6672}
6673
6674template <typename Derived>
6675OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006676TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6677 // No need to rebuild this clause, no template-dependent parameters.
6678 return C;
6679}
6680
6681template <typename Derived>
6682OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006683TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6684 // No need to rebuild this clause, no template-dependent parameters.
6685 return C;
6686}
6687
6688template <typename Derived>
6689OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006690TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6691 // No need to rebuild this clause, no template-dependent parameters.
6692 return C;
6693}
6694
6695template <typename Derived>
6696OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006697TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6698 // No need to rebuild this clause, no template-dependent parameters.
6699 return C;
6700}
6701
6702template <typename Derived>
6703OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006704TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006705 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006706 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006707 for (auto *VE : C->varlists()) {
6708 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006709 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006710 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006711 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006712 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006713 return getDerived().RebuildOMPPrivateClause(
6714 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006715}
6716
Alexander Musman64d33f12014-06-04 07:53:32 +00006717template <typename Derived>
6718OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6719 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006720 llvm::SmallVector<Expr *, 16> Vars;
6721 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006722 for (auto *VE : C->varlists()) {
6723 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006724 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006725 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006726 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006727 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006728 return getDerived().RebuildOMPFirstprivateClause(
6729 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006730}
6731
Alexander Musman64d33f12014-06-04 07:53:32 +00006732template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006733OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006734TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6735 llvm::SmallVector<Expr *, 16> Vars;
6736 Vars.reserve(C->varlist_size());
6737 for (auto *VE : C->varlists()) {
6738 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6739 if (EVar.isInvalid())
6740 return nullptr;
6741 Vars.push_back(EVar.get());
6742 }
6743 return getDerived().RebuildOMPLastprivateClause(
6744 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6745}
6746
6747template <typename Derived>
6748OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006749TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6750 llvm::SmallVector<Expr *, 16> Vars;
6751 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006752 for (auto *VE : C->varlists()) {
6753 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006754 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006755 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006756 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006757 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006758 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6759 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006760}
6761
Alexander Musman64d33f12014-06-04 07:53:32 +00006762template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006763OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006764TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6765 llvm::SmallVector<Expr *, 16> Vars;
6766 Vars.reserve(C->varlist_size());
6767 for (auto *VE : C->varlists()) {
6768 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6769 if (EVar.isInvalid())
6770 return nullptr;
6771 Vars.push_back(EVar.get());
6772 }
6773 CXXScopeSpec ReductionIdScopeSpec;
6774 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6775
6776 DeclarationNameInfo NameInfo = C->getNameInfo();
6777 if (NameInfo.getName()) {
6778 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6779 if (!NameInfo.getName())
6780 return nullptr;
6781 }
6782 return getDerived().RebuildOMPReductionClause(
6783 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6784 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6785}
6786
6787template <typename Derived>
6788OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006789TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6790 llvm::SmallVector<Expr *, 16> Vars;
6791 Vars.reserve(C->varlist_size());
6792 for (auto *VE : C->varlists()) {
6793 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6794 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006795 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006796 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006797 }
6798 ExprResult Step = getDerived().TransformExpr(C->getStep());
6799 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006800 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006801 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6802 C->getLParenLoc(),
6803 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006804}
6805
Alexander Musman64d33f12014-06-04 07:53:32 +00006806template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006807OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006808TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6809 llvm::SmallVector<Expr *, 16> Vars;
6810 Vars.reserve(C->varlist_size());
6811 for (auto *VE : C->varlists()) {
6812 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6813 if (EVar.isInvalid())
6814 return nullptr;
6815 Vars.push_back(EVar.get());
6816 }
6817 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6818 if (Alignment.isInvalid())
6819 return nullptr;
6820 return getDerived().RebuildOMPAlignedClause(
6821 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6822 C->getColonLoc(), C->getLocEnd());
6823}
6824
Alexander Musman64d33f12014-06-04 07:53:32 +00006825template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006826OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006827TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6828 llvm::SmallVector<Expr *, 16> Vars;
6829 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006830 for (auto *VE : C->varlists()) {
6831 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006832 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006833 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006834 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006835 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006836 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6837 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006838}
6839
Alexey Bataevbae9a792014-06-27 10:37:06 +00006840template <typename Derived>
6841OMPClause *
6842TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6843 llvm::SmallVector<Expr *, 16> Vars;
6844 Vars.reserve(C->varlist_size());
6845 for (auto *VE : C->varlists()) {
6846 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6847 if (EVar.isInvalid())
6848 return nullptr;
6849 Vars.push_back(EVar.get());
6850 }
6851 return getDerived().RebuildOMPCopyprivateClause(
6852 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6853}
6854
Douglas Gregorebe10102009-08-20 07:17:43 +00006855//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006856// Expression transformation
6857//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006861 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006862}
Mike Stump11289f42009-09-09 15:08:12 +00006863
6864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006866TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006867 NestedNameSpecifierLoc QualifierLoc;
6868 if (E->getQualifierLoc()) {
6869 QualifierLoc
6870 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6871 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006872 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006873 }
John McCallce546572009-12-08 09:08:17 +00006874
6875 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006876 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6877 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006878 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
John McCall815039a2010-08-17 21:27:17 +00006881 DeclarationNameInfo NameInfo = E->getNameInfo();
6882 if (NameInfo.getName()) {
6883 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6884 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006886 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006887
6888 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006889 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006890 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006891 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006892 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006893
6894 // Mark it referenced in the new context regardless.
6895 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006896 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006897
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006898 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006899 }
John McCallce546572009-12-08 09:08:17 +00006900
Craig Topperc3ec1492014-05-26 06:22:03 +00006901 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006902 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006903 TemplateArgs = &TransArgs;
6904 TransArgs.setLAngleLoc(E->getLAngleLoc());
6905 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006906 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6907 E->getNumTemplateArgs(),
6908 TransArgs))
6909 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006910 }
6911
Chad Rosier1dcde962012-08-08 18:46:20 +00006912 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006913 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006914}
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregora16548e2009-08-11 05:31:07 +00006916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006918TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006919 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006920}
Mike Stump11289f42009-09-09 15:08:12 +00006921
Douglas Gregora16548e2009-08-11 05:31:07 +00006922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006924TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006925 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006926}
Mike Stump11289f42009-09-09 15:08:12 +00006927
Douglas Gregora16548e2009-08-11 05:31:07 +00006928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006930TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006931 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006932}
Mike Stump11289f42009-09-09 15:08:12 +00006933
Douglas Gregora16548e2009-08-11 05:31:07 +00006934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006936TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006937 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006938}
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006943 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006944}
6945
6946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006947ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006948TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006949 if (FunctionDecl *FD = E->getDirectCallee())
6950 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006951 return SemaRef.MaybeBindToTemporary(E);
6952}
6953
6954template<typename Derived>
6955ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006956TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6957 ExprResult ControllingExpr =
6958 getDerived().TransformExpr(E->getControllingExpr());
6959 if (ControllingExpr.isInvalid())
6960 return ExprError();
6961
Chris Lattner01cf8db2011-07-20 06:58:45 +00006962 SmallVector<Expr *, 4> AssocExprs;
6963 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006964 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6965 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6966 if (TS) {
6967 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6968 if (!AssocType)
6969 return ExprError();
6970 AssocTypes.push_back(AssocType);
6971 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006972 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006973 }
6974
6975 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6976 if (AssocExpr.isInvalid())
6977 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006978 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006979 }
6980
6981 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6982 E->getDefaultLoc(),
6983 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006984 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006985 AssocTypes,
6986 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006987}
6988
6989template<typename Derived>
6990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006991TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006992 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006997 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006998
John McCallb268a282010-08-23 23:25:46 +00006999 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007000 E->getRParen());
7001}
7002
Richard Smithdb2630f2012-10-21 03:28:35 +00007003/// \brief The operand of a unary address-of operator has special rules: it's
7004/// allowed to refer to a non-static member of a class even if there's no 'this'
7005/// object available.
7006template<typename Derived>
7007ExprResult
7008TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7009 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007010 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007011 else
7012 return getDerived().TransformExpr(E);
7013}
7014
Mike Stump11289f42009-09-09 15:08:12 +00007015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007017TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007018 ExprResult SubExpr;
7019 if (E->getOpcode() == UO_AddrOf)
7020 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7021 else
7022 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007025
Douglas Gregora16548e2009-08-11 05:31:07 +00007026 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007027 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7030 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007031 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007032}
Mike Stump11289f42009-09-09 15:08:12 +00007033
Douglas Gregora16548e2009-08-11 05:31:07 +00007034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007035ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007036TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7037 // Transform the type.
7038 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7039 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007040 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007041
Douglas Gregor882211c2010-04-28 22:16:22 +00007042 // Transform all of the components into components similar to what the
7043 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007044 // FIXME: It would be slightly more efficient in the non-dependent case to
7045 // just map FieldDecls, rather than requiring the rebuilder to look for
7046 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007047 // template code that we don't care.
7048 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007049 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007050 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007051 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007052 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7053 const Node &ON = E->getComponent(I);
7054 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007055 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007056 Comp.LocStart = ON.getSourceRange().getBegin();
7057 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007058 switch (ON.getKind()) {
7059 case Node::Array: {
7060 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007061 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007062 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007063 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007064
Douglas Gregor882211c2010-04-28 22:16:22 +00007065 ExprChanged = ExprChanged || Index.get() != FromIndex;
7066 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007067 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007068 break;
7069 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007070
Douglas Gregor882211c2010-04-28 22:16:22 +00007071 case Node::Field:
7072 case Node::Identifier:
7073 Comp.isBrackets = false;
7074 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007075 if (!Comp.U.IdentInfo)
7076 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007077
Douglas Gregor882211c2010-04-28 22:16:22 +00007078 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007079
Douglas Gregord1702062010-04-29 00:18:15 +00007080 case Node::Base:
7081 // Will be recomputed during the rebuild.
7082 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
Douglas Gregor882211c2010-04-28 22:16:22 +00007085 Components.push_back(Comp);
7086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007087
Douglas Gregor882211c2010-04-28 22:16:22 +00007088 // If nothing changed, retain the existing expression.
7089 if (!getDerived().AlwaysRebuild() &&
7090 Type == E->getTypeSourceInfo() &&
7091 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007092 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007093
Douglas Gregor882211c2010-04-28 22:16:22 +00007094 // Build a new offsetof expression.
7095 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7096 Components.data(), Components.size(),
7097 E->getRParenLoc());
7098}
7099
7100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007101ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007102TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7103 assert(getDerived().AlreadyTransformed(E->getType()) &&
7104 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007105 return E;
John McCall8d69a212010-11-15 23:31:06 +00007106}
7107
7108template<typename Derived>
7109ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007110TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007111 // Rebuild the syntactic form. The original syntactic form has
7112 // opaque-value expressions in it, so strip those away and rebuild
7113 // the result. This is a really awful way of doing this, but the
7114 // better solution (rebuilding the semantic expressions and
7115 // rebinding OVEs as necessary) doesn't work; we'd need
7116 // TreeTransform to not strip away implicit conversions.
7117 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7118 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007119 if (result.isInvalid()) return ExprError();
7120
7121 // If that gives us a pseudo-object result back, the pseudo-object
7122 // expression must have been an lvalue-to-rvalue conversion which we
7123 // should reapply.
7124 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007125 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007126
7127 return result;
7128}
7129
7130template<typename Derived>
7131ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007132TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7133 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007135 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007136
John McCallbcd03502009-12-07 02:54:59 +00007137 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007138 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007140
John McCall4c98fd82009-11-04 07:28:41 +00007141 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007142 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007143
Peter Collingbournee190dee2011-03-11 19:24:49 +00007144 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7145 E->getKind(),
7146 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 }
Mike Stump11289f42009-09-09 15:08:12 +00007148
Eli Friedmane4f22df2012-02-29 04:03:55 +00007149 // C++0x [expr.sizeof]p1:
7150 // The operand is either an expression, which is an unevaluated operand
7151 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007152 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7153 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007154
Reid Kleckner32506ed2014-06-12 23:03:48 +00007155 // Try to recover if we have something like sizeof(T::X) where X is a type.
7156 // Notably, there must be *exactly* one set of parens if X is a type.
7157 TypeSourceInfo *RecoveryTSI = nullptr;
7158 ExprResult SubExpr;
7159 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7160 if (auto *DRE =
7161 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7162 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7163 PE, DRE, false, &RecoveryTSI);
7164 else
7165 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7166
7167 if (RecoveryTSI) {
7168 return getDerived().RebuildUnaryExprOrTypeTrait(
7169 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7170 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007172
Eli Friedmane4f22df2012-02-29 04:03:55 +00007173 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007175
Peter Collingbournee190dee2011-03-11 19:24:49 +00007176 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7177 E->getOperatorLoc(),
7178 E->getKind(),
7179 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007180}
Mike Stump11289f42009-09-09 15:08:12 +00007181
Douglas Gregora16548e2009-08-11 05:31:07 +00007182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007184TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007185 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007188
John McCalldadc5752010-08-24 06:29:42 +00007189 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007192
7193
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (!getDerived().AlwaysRebuild() &&
7195 LHS.get() == E->getLHS() &&
7196 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007197 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007198
John McCallb268a282010-08-23 23:25:46 +00007199 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007201 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007202 E->getRBracketLoc());
7203}
Mike Stump11289f42009-09-09 15:08:12 +00007204
7205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007209 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007211 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007212
7213 // Transform arguments.
7214 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007215 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007216 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007217 &ArgChanged))
7218 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007219
Douglas Gregora16548e2009-08-11 05:31:07 +00007220 if (!getDerived().AlwaysRebuild() &&
7221 Callee.get() == E->getCallee() &&
7222 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007223 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007224
Douglas Gregora16548e2009-08-11 05:31:07 +00007225 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007226 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007228 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007229 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 E->getRParenLoc());
7231}
Mike Stump11289f42009-09-09 15:08:12 +00007232
7233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007235TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007236 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
Douglas Gregorea972d32011-02-28 21:54:11 +00007240 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007241 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007242 QualifierLoc
7243 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007244
Douglas Gregorea972d32011-02-28 21:54:11 +00007245 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007246 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007247 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007248 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007249
Eli Friedman2cfcef62009-12-04 06:40:45 +00007250 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007251 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7252 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007253 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007255
John McCall16df1e52010-03-30 21:47:33 +00007256 NamedDecl *FoundDecl = E->getFoundDecl();
7257 if (FoundDecl == E->getMemberDecl()) {
7258 FoundDecl = Member;
7259 } else {
7260 FoundDecl = cast_or_null<NamedDecl>(
7261 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7262 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007263 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007264 }
7265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266 if (!getDerived().AlwaysRebuild() &&
7267 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007268 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007269 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007270 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007271 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007272
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007273 // Mark it referenced in the new context regardless.
7274 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007275 SemaRef.MarkMemberReferenced(E);
7276
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007277 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007278 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007279
John McCall6b51f282009-11-23 01:53:49 +00007280 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007281 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007282 TransArgs.setLAngleLoc(E->getLAngleLoc());
7283 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007284 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7285 E->getNumTemplateArgs(),
7286 TransArgs))
7287 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007289
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007291 SourceLocation FakeOperatorLoc =
7292 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007293
John McCall38836f02010-01-15 08:34:02 +00007294 // FIXME: to do this check properly, we will need to preserve the
7295 // first-qualifier-in-scope here, just in case we had a dependent
7296 // base (and therefore couldn't do the check) and a
7297 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007298 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007299
John McCallb268a282010-08-23 23:25:46 +00007300 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007301 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007302 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007303 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007304 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007305 Member,
John McCall16df1e52010-03-30 21:47:33 +00007306 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007307 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007308 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007309 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007310}
Mike Stump11289f42009-09-09 15:08:12 +00007311
Douglas Gregora16548e2009-08-11 05:31:07 +00007312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007314TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007315 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007318
John McCalldadc5752010-08-24 06:29:42 +00007319 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007320 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora16548e2009-08-11 05:31:07 +00007323 if (!getDerived().AlwaysRebuild() &&
7324 LHS.get() == E->getLHS() &&
7325 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007326 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007327
Lang Hames5de91cc2012-10-02 04:45:10 +00007328 Sema::FPContractStateRAII FPContractState(getSema());
7329 getSema().FPFeatures.fp_contract = E->isFPContractable();
7330
Douglas Gregora16548e2009-08-11 05:31:07 +00007331 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007332 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007333}
7334
Mike Stump11289f42009-09-09 15:08:12 +00007335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007336ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007337TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007338 CompoundAssignOperator *E) {
7339 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007340}
Mike Stump11289f42009-09-09 15:08:12 +00007341
Douglas Gregora16548e2009-08-11 05:31:07 +00007342template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007343ExprResult TreeTransform<Derived>::
7344TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7345 // Just rebuild the common and RHS expressions and see whether we
7346 // get any changes.
7347
7348 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7349 if (commonExpr.isInvalid())
7350 return ExprError();
7351
7352 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7353 if (rhs.isInvalid())
7354 return ExprError();
7355
7356 if (!getDerived().AlwaysRebuild() &&
7357 commonExpr.get() == e->getCommon() &&
7358 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007359 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007360
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007361 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007362 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007363 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007364 e->getColonLoc(),
7365 rhs.get());
7366}
7367
7368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007370TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007371 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007374
John McCalldadc5752010-08-24 06:29:42 +00007375 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007378
John McCalldadc5752010-08-24 06:29:42 +00007379 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007380 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 if (!getDerived().AlwaysRebuild() &&
7384 Cond.get() == E->getCond() &&
7385 LHS.get() == E->getLHS() &&
7386 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007387 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007388
John McCallb268a282010-08-23 23:25:46 +00007389 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007390 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007391 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007392 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007393 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007394}
Mike Stump11289f42009-09-09 15:08:12 +00007395
7396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007399 // Implicit casts are eliminated during transformation, since they
7400 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007401 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregora16548e2009-08-11 05:31:07 +00007404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007406TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007407 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7408 if (!Type)
7409 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007410
John McCalldadc5752010-08-24 06:29:42 +00007411 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007412 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007414 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007415
Douglas Gregora16548e2009-08-11 05:31:07 +00007416 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007417 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007418 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007419 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007420
John McCall97513962010-01-15 18:39:57 +00007421 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007422 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007424 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007425}
Mike Stump11289f42009-09-09 15:08:12 +00007426
Douglas Gregora16548e2009-08-11 05:31:07 +00007427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007429TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007430 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7431 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7432 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007434
John McCalldadc5752010-08-24 06:29:42 +00007435 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007437 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregora16548e2009-08-11 05:31:07 +00007439 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007440 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007441 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007442 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007443
John McCall5d7aa7f2010-01-19 22:33:45 +00007444 // Note: the expression type doesn't necessarily match the
7445 // type-as-written, but that's okay, because it should always be
7446 // derivable from the initializer.
7447
John McCalle15bbff2010-01-18 19:35:47 +00007448 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007449 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007450 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007451}
Mike Stump11289f42009-09-09 15:08:12 +00007452
Douglas Gregora16548e2009-08-11 05:31:07 +00007453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007455TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007456 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007457 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregora16548e2009-08-11 05:31:07 +00007460 if (!getDerived().AlwaysRebuild() &&
7461 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007462 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007463
Douglas Gregora16548e2009-08-11 05:31:07 +00007464 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007465 SourceLocation FakeOperatorLoc =
7466 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007467 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007468 E->getAccessorLoc(),
7469 E->getAccessor());
7470}
Mike Stump11289f42009-09-09 15:08:12 +00007471
Douglas Gregora16548e2009-08-11 05:31:07 +00007472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007473ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007474TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007475 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007476
Benjamin Kramerf0623432012-08-23 22:51:59 +00007477 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007478 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007479 Inits, &InitChanged))
7480 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007481
Douglas Gregora16548e2009-08-11 05:31:07 +00007482 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007483 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007484
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007485 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007486 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007487}
Mike Stump11289f42009-09-09 15:08:12 +00007488
Douglas Gregora16548e2009-08-11 05:31:07 +00007489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007491TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007492 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregorebe10102009-08-20 07:17:43 +00007494 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007495 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007498
Douglas Gregorebe10102009-08-20 07:17:43 +00007499 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007500 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007501 bool ExprChanged = false;
7502 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7503 DEnd = E->designators_end();
7504 D != DEnd; ++D) {
7505 if (D->isFieldDesignator()) {
7506 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7507 D->getDotLoc(),
7508 D->getFieldLoc()));
7509 continue;
7510 }
Mike Stump11289f42009-09-09 15:08:12 +00007511
Douglas Gregora16548e2009-08-11 05:31:07 +00007512 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007513 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007514 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007516
7517 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007519
Douglas Gregora16548e2009-08-11 05:31:07 +00007520 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007521 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007522 continue;
7523 }
Mike Stump11289f42009-09-09 15:08:12 +00007524
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007526 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7528 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007530
John McCalldadc5752010-08-24 06:29:42 +00007531 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007532 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007534
7535 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 End.get(),
7537 D->getLBracketLoc(),
7538 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007539
Douglas Gregora16548e2009-08-11 05:31:07 +00007540 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7541 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007542
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007543 ArrayExprs.push_back(Start.get());
7544 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 }
Mike Stump11289f42009-09-09 15:08:12 +00007546
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 if (!getDerived().AlwaysRebuild() &&
7548 Init.get() == E->getInit() &&
7549 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007550 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007551
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007552 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007554 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007555}
Mike Stump11289f42009-09-09 15:08:12 +00007556
Douglas Gregora16548e2009-08-11 05:31:07 +00007557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007558ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007559TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007560 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007561 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007562
Douglas Gregor3da3c062009-10-28 00:29:27 +00007563 // FIXME: Will we ever have proper type location here? Will we actually
7564 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007565 QualType T = getDerived().TransformType(E->getType());
7566 if (T.isNull())
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 T == E->getType())
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 return getDerived().RebuildImplicitValueInitExpr(T);
7574}
Mike Stump11289f42009-09-09 15:08:12 +00007575
Douglas Gregora16548e2009-08-11 05:31:07 +00007576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007578TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007579 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7580 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007582
John McCalldadc5752010-08-24 06:29:42 +00007583 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007584 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007588 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007591
John McCallb268a282010-08-23 23:25:46 +00007592 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007593 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007594}
7595
7596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007598TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007600 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007601 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7602 &ArgumentChanged))
7603 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007604
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007606 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 E->getRParenLoc());
7608}
Mike Stump11289f42009-09-09 15:08:12 +00007609
Douglas Gregora16548e2009-08-11 05:31:07 +00007610/// \brief Transform an address-of-label expression.
7611///
7612/// By default, the transformation of an address-of-label expression always
7613/// rebuilds the expression, so that the label identifier can be resolved to
7614/// the corresponding label statement by semantic analysis.
7615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007617TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007618 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7619 E->getLabel());
7620 if (!LD)
7621 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007622
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007624 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007625}
Mike Stump11289f42009-09-09 15:08:12 +00007626
7627template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007629TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007630 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007631 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007633 if (SubStmt.isInvalid()) {
7634 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007635 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007636 }
Mike Stump11289f42009-09-09 15:08:12 +00007637
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007639 SubStmt.get() == E->getSubStmt()) {
7640 // Calling this an 'error' is unintuitive, but it does the right thing.
7641 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007642 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007643 }
Mike Stump11289f42009-09-09 15:08:12 +00007644
7645 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007646 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007647 E->getRParenLoc());
7648}
Mike Stump11289f42009-09-09 15:08:12 +00007649
Douglas Gregora16548e2009-08-11 05:31:07 +00007650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007652TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007653 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007654 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007656
John McCalldadc5752010-08-24 06:29:42 +00007657 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007659 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007660
John McCalldadc5752010-08-24 06:29:42 +00007661 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007663 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregora16548e2009-08-11 05:31:07 +00007665 if (!getDerived().AlwaysRebuild() &&
7666 Cond.get() == E->getCond() &&
7667 LHS.get() == E->getLHS() &&
7668 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007669 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007670
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007672 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007673 E->getRParenLoc());
7674}
Mike Stump11289f42009-09-09 15:08:12 +00007675
Douglas Gregora16548e2009-08-11 05:31:07 +00007676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007678TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007679 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007680}
7681
7682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007684TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007685 switch (E->getOperator()) {
7686 case OO_New:
7687 case OO_Delete:
7688 case OO_Array_New:
7689 case OO_Array_Delete:
7690 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007691
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007692 case OO_Call: {
7693 // This is a call to an object's operator().
7694 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7695
7696 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007697 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007698 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007699 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007700
7701 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007702 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7703 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007704
7705 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007706 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007707 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007708 Args))
7709 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007710
John McCallb268a282010-08-23 23:25:46 +00007711 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007712 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007713 E->getLocEnd());
7714 }
7715
7716#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7717 case OO_##Name:
7718#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7719#include "clang/Basic/OperatorKinds.def"
7720 case OO_Subscript:
7721 // Handled below.
7722 break;
7723
7724 case OO_Conditional:
7725 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007726
7727 case OO_None:
7728 case NUM_OVERLOADED_OPERATORS:
7729 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007730 }
7731
John McCalldadc5752010-08-24 06:29:42 +00007732 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007733 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007735
Richard Smithdb2630f2012-10-21 03:28:35 +00007736 ExprResult First;
7737 if (E->getOperator() == OO_Amp)
7738 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7739 else
7740 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007741 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007742 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007743
John McCalldadc5752010-08-24 06:29:42 +00007744 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007745 if (E->getNumArgs() == 2) {
7746 Second = getDerived().TransformExpr(E->getArg(1));
7747 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007748 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007749 }
Mike Stump11289f42009-09-09 15:08:12 +00007750
Douglas Gregora16548e2009-08-11 05:31:07 +00007751 if (!getDerived().AlwaysRebuild() &&
7752 Callee.get() == E->getCallee() &&
7753 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007754 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007755 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007756
Lang Hames5de91cc2012-10-02 04:45:10 +00007757 Sema::FPContractStateRAII FPContractState(getSema());
7758 getSema().FPFeatures.fp_contract = E->isFPContractable();
7759
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7761 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007762 Callee.get(),
7763 First.get(),
7764 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007765}
Mike Stump11289f42009-09-09 15:08:12 +00007766
Douglas Gregora16548e2009-08-11 05:31:07 +00007767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007769TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7770 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007771}
Mike Stump11289f42009-09-09 15:08:12 +00007772
Douglas Gregora16548e2009-08-11 05:31:07 +00007773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007774ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007775TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7776 // Transform the callee.
7777 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7778 if (Callee.isInvalid())
7779 return ExprError();
7780
7781 // Transform exec config.
7782 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7783 if (EC.isInvalid())
7784 return ExprError();
7785
7786 // Transform arguments.
7787 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007788 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007789 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007790 &ArgChanged))
7791 return ExprError();
7792
7793 if (!getDerived().AlwaysRebuild() &&
7794 Callee.get() == E->getCallee() &&
7795 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007796 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007797
7798 // FIXME: Wrong source location information for the '('.
7799 SourceLocation FakeLParenLoc
7800 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7801 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007802 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007803 E->getRParenLoc(), EC.get());
7804}
7805
7806template<typename Derived>
7807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007808TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007809 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7810 if (!Type)
7811 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007812
John McCalldadc5752010-08-24 06:29:42 +00007813 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007814 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007815 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007817
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007819 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007821 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007823 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007824 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007825 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007826 E->getAngleBrackets().getEnd(),
7827 // FIXME. this should be '(' location
7828 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007829 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007830 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007831}
Mike Stump11289f42009-09-09 15:08:12 +00007832
Douglas Gregora16548e2009-08-11 05:31:07 +00007833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007835TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7836 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007837}
Mike Stump11289f42009-09-09 15:08:12 +00007838
7839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7842 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007843}
7844
Douglas Gregora16548e2009-08-11 05:31:07 +00007845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007846ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007847TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007848 CXXReinterpretCastExpr *E) {
7849 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007850}
Mike Stump11289f42009-09-09 15:08:12 +00007851
Douglas Gregora16548e2009-08-11 05:31:07 +00007852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007854TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7855 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007856}
Mike Stump11289f42009-09-09 15:08:12 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007859ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007860TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007861 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007862 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7863 if (!Type)
7864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007865
John McCalldadc5752010-08-24 06:29:42 +00007866 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007867 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007870
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007872 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007874 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007876 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007877 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007878 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007879 E->getRParenLoc());
7880}
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
John McCall47f29ea2009-12-08 09:21:05 +00007884TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007885 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007886 TypeSourceInfo *TInfo
7887 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7888 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007890
Douglas Gregora16548e2009-08-11 05:31:07 +00007891 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007892 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007893 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007894
Douglas Gregor9da64192010-04-26 22:37:10 +00007895 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7896 E->getLocStart(),
7897 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 E->getLocEnd());
7899 }
Mike Stump11289f42009-09-09 15:08:12 +00007900
Eli Friedman456f0182012-01-20 01:26:23 +00007901 // We don't know whether the subexpression is potentially evaluated until
7902 // after we perform semantic analysis. We speculatively assume it is
7903 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007904 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007905 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7906 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007907
John McCalldadc5752010-08-24 06:29:42 +00007908 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007909 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007910 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007911
Douglas Gregora16548e2009-08-11 05:31:07 +00007912 if (!getDerived().AlwaysRebuild() &&
7913 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007914 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007915
Douglas Gregor9da64192010-04-26 22:37:10 +00007916 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7917 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007918 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 E->getLocEnd());
7920}
7921
7922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007923ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007924TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7925 if (E->isTypeOperand()) {
7926 TypeSourceInfo *TInfo
7927 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7928 if (!TInfo)
7929 return ExprError();
7930
7931 if (!getDerived().AlwaysRebuild() &&
7932 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007933 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007934
Douglas Gregor69735112011-03-06 17:40:41 +00007935 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007936 E->getLocStart(),
7937 TInfo,
7938 E->getLocEnd());
7939 }
7940
Francois Pichet9f4f2072010-09-08 12:20:18 +00007941 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7942
7943 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7944 if (SubExpr.isInvalid())
7945 return ExprError();
7946
7947 if (!getDerived().AlwaysRebuild() &&
7948 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007949 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007950
7951 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7952 E->getLocStart(),
7953 SubExpr.get(),
7954 E->getLocEnd());
7955}
7956
7957template<typename Derived>
7958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007959TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007960 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007961}
Mike Stump11289f42009-09-09 15:08:12 +00007962
Douglas Gregora16548e2009-08-11 05:31:07 +00007963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007964ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007965TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007966 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007967 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007968}
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregora16548e2009-08-11 05:31:07 +00007970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007972TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007973 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007974
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007975 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7976 // Make sure that we capture 'this'.
7977 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007978 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007980
Douglas Gregorb15af892010-01-07 23:12:05 +00007981 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007982}
Mike Stump11289f42009-09-09 15:08:12 +00007983
Douglas Gregora16548e2009-08-11 05:31:07 +00007984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007986TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007987 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007988 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007990
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (!getDerived().AlwaysRebuild() &&
7992 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007993 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007994
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007995 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7996 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007997}
Mike Stump11289f42009-09-09 15:08:12 +00007998
Douglas Gregora16548e2009-08-11 05:31:07 +00007999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008001TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008002 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008003 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8004 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008007
Chandler Carruth794da4c2010-02-08 06:42:49 +00008008 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008009 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008010 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008011
Douglas Gregor033f6752009-12-23 23:03:06 +00008012 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008013}
Mike Stump11289f42009-09-09 15:08:12 +00008014
Douglas Gregora16548e2009-08-11 05:31:07 +00008015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008016ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008017TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8018 FieldDecl *Field
8019 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8020 E->getField()));
8021 if (!Field)
8022 return ExprError();
8023
8024 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008025 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008026
8027 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8028}
8029
8030template<typename Derived>
8031ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008032TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8033 CXXScalarValueInitExpr *E) {
8034 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8035 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008037
Douglas Gregora16548e2009-08-11 05:31:07 +00008038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008039 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008040 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008041
Chad Rosier1dcde962012-08-08 18:46:20 +00008042 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008043 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008044 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008045}
Mike Stump11289f42009-09-09 15:08:12 +00008046
Douglas Gregora16548e2009-08-11 05:31:07 +00008047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008048ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008049TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008050 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008051 TypeSourceInfo *AllocTypeInfo
8052 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8053 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008055
Douglas Gregora16548e2009-08-11 05:31:07 +00008056 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008057 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008060
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 // Transform the placement arguments (if any).
8062 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008063 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008064 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008065 E->getNumPlacementArgs(), true,
8066 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008067 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008068
Sebastian Redl6047f072012-02-16 12:22:20 +00008069 // Transform the initializer (if any).
8070 Expr *OldInit = E->getInitializer();
8071 ExprResult NewInit;
8072 if (OldInit)
8073 NewInit = getDerived().TransformExpr(OldInit);
8074 if (NewInit.isInvalid())
8075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008076
Sebastian Redl6047f072012-02-16 12:22:20 +00008077 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008078 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008079 if (E->getOperatorNew()) {
8080 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008081 getDerived().TransformDecl(E->getLocStart(),
8082 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008083 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008084 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008085 }
8086
Craig Topperc3ec1492014-05-26 06:22:03 +00008087 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008088 if (E->getOperatorDelete()) {
8089 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008090 getDerived().TransformDecl(E->getLocStart(),
8091 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008092 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008093 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008094 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008095
Douglas Gregora16548e2009-08-11 05:31:07 +00008096 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008097 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008098 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008099 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008100 OperatorNew == E->getOperatorNew() &&
8101 OperatorDelete == E->getOperatorDelete() &&
8102 !ArgumentChanged) {
8103 // Mark any declarations we need as referenced.
8104 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008105 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008106 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008107 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008108 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008109
Sebastian Redl6047f072012-02-16 12:22:20 +00008110 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008111 QualType ElementType
8112 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8113 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8114 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8115 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008116 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008117 }
8118 }
8119 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008120
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008121 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008122 }
Mike Stump11289f42009-09-09 15:08:12 +00008123
Douglas Gregor0744ef62010-09-07 21:49:58 +00008124 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008125 if (!ArraySize.get()) {
8126 // If no array size was specified, but the new expression was
8127 // instantiated with an array type (e.g., "new T" where T is
8128 // instantiated with "int[4]"), extract the outer bound from the
8129 // array type as our array size. We do this with constant and
8130 // dependently-sized array types.
8131 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8132 if (!ArrayT) {
8133 // Do nothing
8134 } else if (const ConstantArrayType *ConsArrayT
8135 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008136 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8137 SemaRef.Context.getSizeType(),
8138 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008139 AllocType = ConsArrayT->getElementType();
8140 } else if (const DependentSizedArrayType *DepArrayT
8141 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8142 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008143 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008144 AllocType = DepArrayT->getElementType();
8145 }
8146 }
8147 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008148
Douglas Gregora16548e2009-08-11 05:31:07 +00008149 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8150 E->isGlobalNew(),
8151 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008152 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008153 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008154 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008156 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008157 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008158 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008159 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008160}
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008164TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008165 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008166 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008168
Douglas Gregord2d9da02010-02-26 00:38:10 +00008169 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008170 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008171 if (E->getOperatorDelete()) {
8172 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008173 getDerived().TransformDecl(E->getLocStart(),
8174 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008175 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008176 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008177 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008178
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008180 Operand.get() == E->getArgument() &&
8181 OperatorDelete == E->getOperatorDelete()) {
8182 // Mark any declarations we need as referenced.
8183 // FIXME: instantiation-specific.
8184 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008185 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008186
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008187 if (!E->getArgument()->isTypeDependent()) {
8188 QualType Destroyed = SemaRef.Context.getBaseElementType(
8189 E->getDestroyedType());
8190 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8191 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008192 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008193 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008194 }
8195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008196
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008197 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008198 }
Mike Stump11289f42009-09-09 15:08:12 +00008199
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8201 E->isGlobalDelete(),
8202 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008203 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008204}
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregora16548e2009-08-11 05:31:07 +00008206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008207ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008208TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008209 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008210 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008211 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008213
John McCallba7bf592010-08-24 05:47:05 +00008214 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008215 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008216 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008217 E->getOperatorLoc(),
8218 E->isArrow()? tok::arrow : tok::period,
8219 ObjectTypePtr,
8220 MayBePseudoDestructor);
8221 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008222 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008223
John McCallba7bf592010-08-24 05:47:05 +00008224 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008225 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8226 if (QualifierLoc) {
8227 QualifierLoc
8228 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8229 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008230 return ExprError();
8231 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008232 CXXScopeSpec SS;
8233 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008234
Douglas Gregor678f90d2010-02-25 01:56:36 +00008235 PseudoDestructorTypeStorage Destroyed;
8236 if (E->getDestroyedTypeInfo()) {
8237 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008238 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008239 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008240 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008241 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008242 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008243 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008244 // We aren't likely to be able to resolve the identifier down to a type
8245 // now anyway, so just retain the identifier.
8246 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8247 E->getDestroyedTypeLoc());
8248 } else {
8249 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008250 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008251 *E->getDestroyedTypeIdentifier(),
8252 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008253 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008254 SS, ObjectTypePtr,
8255 false);
8256 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008257 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008258
Douglas Gregor678f90d2010-02-25 01:56:36 +00008259 Destroyed
8260 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8261 E->getDestroyedTypeLoc());
8262 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008263
Craig Topperc3ec1492014-05-26 06:22:03 +00008264 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008265 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008266 CXXScopeSpec EmptySS;
8267 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008268 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008269 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008270 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008271 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008272
John McCallb268a282010-08-23 23:25:46 +00008273 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008274 E->getOperatorLoc(),
8275 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008276 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008277 ScopeTypeInfo,
8278 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008279 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008280 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008281}
Mike Stump11289f42009-09-09 15:08:12 +00008282
Douglas Gregorad8a3362009-09-04 17:36:40 +00008283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008284ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008285TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008286 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008287 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8288 Sema::LookupOrdinaryName);
8289
8290 // Transform all the decls.
8291 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8292 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008293 NamedDecl *InstD = static_cast<NamedDecl*>(
8294 getDerived().TransformDecl(Old->getNameLoc(),
8295 *I));
John McCall84d87672009-12-10 09:41:52 +00008296 if (!InstD) {
8297 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8298 // This can happen because of dependent hiding.
8299 if (isa<UsingShadowDecl>(*I))
8300 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008301 else {
8302 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008303 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008304 }
John McCall84d87672009-12-10 09:41:52 +00008305 }
John McCalle66edc12009-11-24 19:00:30 +00008306
8307 // Expand using declarations.
8308 if (isa<UsingDecl>(InstD)) {
8309 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008310 for (auto *I : UD->shadows())
8311 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008312 continue;
8313 }
8314
8315 R.addDecl(InstD);
8316 }
8317
8318 // Resolve a kind, but don't do any further analysis. If it's
8319 // ambiguous, the callee needs to deal with it.
8320 R.resolveKind();
8321
8322 // Rebuild the nested-name qualifier, if present.
8323 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008324 if (Old->getQualifierLoc()) {
8325 NestedNameSpecifierLoc QualifierLoc
8326 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8327 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008329
Douglas Gregor0da1d432011-02-28 20:01:57 +00008330 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008331 }
8332
Douglas Gregor9262f472010-04-27 18:19:34 +00008333 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008334 CXXRecordDecl *NamingClass
8335 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8336 Old->getNameLoc(),
8337 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008338 if (!NamingClass) {
8339 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008340 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008342
Douglas Gregorda7be082010-04-27 16:10:10 +00008343 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008344 }
8345
Abramo Bagnara7945c982012-01-27 09:46:47 +00008346 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8347
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008348 // If we have neither explicit template arguments, nor the template keyword,
8349 // it's a normal declaration name.
8350 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008351 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8352
8353 // If we have template arguments, rebuild them, then rebuild the
8354 // templateid expression.
8355 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008356 if (Old->hasExplicitTemplateArgs() &&
8357 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008358 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008359 TransArgs)) {
8360 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008361 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008362 }
John McCalle66edc12009-11-24 19:00:30 +00008363
Abramo Bagnara7945c982012-01-27 09:46:47 +00008364 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008365 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008366}
Mike Stump11289f42009-09-09 15:08:12 +00008367
Douglas Gregora16548e2009-08-11 05:31:07 +00008368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008369ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008370TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8371 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008372 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008373 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8374 TypeSourceInfo *From = E->getArg(I);
8375 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008376 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008377 TypeLocBuilder TLB;
8378 TLB.reserve(FromTL.getFullDataSize());
8379 QualType To = getDerived().TransformType(TLB, FromTL);
8380 if (To.isNull())
8381 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008382
Douglas Gregor29c42f22012-02-24 07:38:34 +00008383 if (To == From->getType())
8384 Args.push_back(From);
8385 else {
8386 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8387 ArgChanged = true;
8388 }
8389 continue;
8390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008391
Douglas Gregor29c42f22012-02-24 07:38:34 +00008392 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008393
Douglas Gregor29c42f22012-02-24 07:38:34 +00008394 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008395 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008396 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8397 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8398 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008399
Douglas Gregor29c42f22012-02-24 07:38:34 +00008400 // Determine whether the set of unexpanded parameter packs can and should
8401 // be expanded.
8402 bool Expand = true;
8403 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008404 Optional<unsigned> OrigNumExpansions =
8405 ExpansionTL.getTypePtr()->getNumExpansions();
8406 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008407 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8408 PatternTL.getSourceRange(),
8409 Unexpanded,
8410 Expand, RetainExpansion,
8411 NumExpansions))
8412 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008413
Douglas Gregor29c42f22012-02-24 07:38:34 +00008414 if (!Expand) {
8415 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008416 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008417 // expansion.
8418 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008419
Douglas Gregor29c42f22012-02-24 07:38:34 +00008420 TypeLocBuilder TLB;
8421 TLB.reserve(From->getTypeLoc().getFullDataSize());
8422
8423 QualType To = getDerived().TransformType(TLB, PatternTL);
8424 if (To.isNull())
8425 return ExprError();
8426
Chad Rosier1dcde962012-08-08 18:46:20 +00008427 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008428 PatternTL.getSourceRange(),
8429 ExpansionTL.getEllipsisLoc(),
8430 NumExpansions);
8431 if (To.isNull())
8432 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008433
Douglas Gregor29c42f22012-02-24 07:38:34 +00008434 PackExpansionTypeLoc ToExpansionTL
8435 = TLB.push<PackExpansionTypeLoc>(To);
8436 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8437 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8438 continue;
8439 }
8440
8441 // Expand the pack expansion by substituting for each argument in the
8442 // pack(s).
8443 for (unsigned I = 0; I != *NumExpansions; ++I) {
8444 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8445 TypeLocBuilder TLB;
8446 TLB.reserve(PatternTL.getFullDataSize());
8447 QualType To = getDerived().TransformType(TLB, PatternTL);
8448 if (To.isNull())
8449 return ExprError();
8450
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008451 if (To->containsUnexpandedParameterPack()) {
8452 To = getDerived().RebuildPackExpansionType(To,
8453 PatternTL.getSourceRange(),
8454 ExpansionTL.getEllipsisLoc(),
8455 NumExpansions);
8456 if (To.isNull())
8457 return ExprError();
8458
8459 PackExpansionTypeLoc ToExpansionTL
8460 = TLB.push<PackExpansionTypeLoc>(To);
8461 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8462 }
8463
Douglas Gregor29c42f22012-02-24 07:38:34 +00008464 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008466
Douglas Gregor29c42f22012-02-24 07:38:34 +00008467 if (!RetainExpansion)
8468 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008469
Douglas Gregor29c42f22012-02-24 07:38:34 +00008470 // If we're supposed to retain a pack expansion, do so by temporarily
8471 // forgetting the partially-substituted parameter pack.
8472 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8473
8474 TypeLocBuilder TLB;
8475 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
Douglas Gregor29c42f22012-02-24 07:38:34 +00008477 QualType To = getDerived().TransformType(TLB, PatternTL);
8478 if (To.isNull())
8479 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008480
8481 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008482 PatternTL.getSourceRange(),
8483 ExpansionTL.getEllipsisLoc(),
8484 NumExpansions);
8485 if (To.isNull())
8486 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008487
Douglas Gregor29c42f22012-02-24 07:38:34 +00008488 PackExpansionTypeLoc ToExpansionTL
8489 = TLB.push<PackExpansionTypeLoc>(To);
8490 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8491 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008493
Douglas Gregor29c42f22012-02-24 07:38:34 +00008494 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008495 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008496
8497 return getDerived().RebuildTypeTrait(E->getTrait(),
8498 E->getLocStart(),
8499 Args,
8500 E->getLocEnd());
8501}
8502
8503template<typename Derived>
8504ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008505TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8506 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8507 if (!T)
8508 return ExprError();
8509
8510 if (!getDerived().AlwaysRebuild() &&
8511 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008512 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008513
8514 ExprResult SubExpr;
8515 {
8516 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8517 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8518 if (SubExpr.isInvalid())
8519 return ExprError();
8520
8521 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008522 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008523 }
8524
8525 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8526 E->getLocStart(),
8527 T,
8528 SubExpr.get(),
8529 E->getLocEnd());
8530}
8531
8532template<typename Derived>
8533ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008534TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8535 ExprResult SubExpr;
8536 {
8537 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8538 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8539 if (SubExpr.isInvalid())
8540 return ExprError();
8541
8542 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008543 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008544 }
8545
8546 return getDerived().RebuildExpressionTrait(
8547 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8548}
8549
Reid Kleckner32506ed2014-06-12 23:03:48 +00008550template <typename Derived>
8551ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8552 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8553 TypeSourceInfo **RecoveryTSI) {
8554 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8555 DRE, AddrTaken, RecoveryTSI);
8556
8557 // Propagate both errors and recovered types, which return ExprEmpty.
8558 if (!NewDRE.isUsable())
8559 return NewDRE;
8560
8561 // We got an expr, wrap it up in parens.
8562 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8563 return PE;
8564 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8565 PE->getRParen());
8566}
8567
8568template <typename Derived>
8569ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8570 DependentScopeDeclRefExpr *E) {
8571 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8572 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008573}
8574
8575template<typename Derived>
8576ExprResult
8577TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8578 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008579 bool IsAddressOfOperand,
8580 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008581 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008582 NestedNameSpecifierLoc QualifierLoc
8583 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8584 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008585 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008586 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008587
John McCall31f82722010-11-12 08:19:04 +00008588 // TODO: If this is a conversion-function-id, verify that the
8589 // destination type name (if present) resolves the same way after
8590 // instantiation as it did in the local scope.
8591
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008592 DeclarationNameInfo NameInfo
8593 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8594 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008596
John McCalle66edc12009-11-24 19:00:30 +00008597 if (!E->hasExplicitTemplateArgs()) {
8598 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008599 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008600 // Note: it is sufficient to compare the Name component of NameInfo:
8601 // if name has not changed, DNLoc has not changed either.
8602 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008603 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008604
Reid Kleckner32506ed2014-06-12 23:03:48 +00008605 return getDerived().RebuildDependentScopeDeclRefExpr(
8606 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8607 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008608 }
John McCall6b51f282009-11-23 01:53:49 +00008609
8610 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008611 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8612 E->getNumTemplateArgs(),
8613 TransArgs))
8614 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008615
Reid Kleckner32506ed2014-06-12 23:03:48 +00008616 return getDerived().RebuildDependentScopeDeclRefExpr(
8617 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8618 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008619}
8620
8621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008622ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008623TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008624 // CXXConstructExprs other than for list-initialization and
8625 // CXXTemporaryObjectExpr are always implicit, so when we have
8626 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008627 if ((E->getNumArgs() == 1 ||
8628 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008629 (!getDerived().DropCallArgument(E->getArg(0))) &&
8630 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008631 return getDerived().TransformExpr(E->getArg(0));
8632
Douglas Gregora16548e2009-08-11 05:31:07 +00008633 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8634
8635 QualType T = getDerived().TransformType(E->getType());
8636 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008637 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008638
8639 CXXConstructorDecl *Constructor
8640 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008641 getDerived().TransformDecl(E->getLocStart(),
8642 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008643 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008647 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008648 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008649 &ArgumentChanged))
8650 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008651
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 if (!getDerived().AlwaysRebuild() &&
8653 T == E->getType() &&
8654 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008655 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008656 // Mark the constructor as referenced.
8657 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008658 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008659 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008660 }
Mike Stump11289f42009-09-09 15:08:12 +00008661
Douglas Gregordb121ba2009-12-14 16:27:04 +00008662 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8663 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008664 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008665 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008666 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008667 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008668 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008669 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008670 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008671}
Mike Stump11289f42009-09-09 15:08:12 +00008672
Douglas Gregora16548e2009-08-11 05:31:07 +00008673/// \brief Transform a C++ temporary-binding expression.
8674///
Douglas Gregor363b1512009-12-24 18:51:59 +00008675/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8676/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008679TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008680 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008681}
Mike Stump11289f42009-09-09 15:08:12 +00008682
John McCall5d413782010-12-06 08:20:24 +00008683/// \brief Transform a C++ expression that contains cleanups that should
8684/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008685///
John McCall5d413782010-12-06 08:20:24 +00008686/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008687/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008689ExprResult
John McCall5d413782010-12-06 08:20:24 +00008690TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008691 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008692}
Mike Stump11289f42009-09-09 15:08:12 +00008693
Douglas Gregora16548e2009-08-11 05:31:07 +00008694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008695ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008696TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008697 CXXTemporaryObjectExpr *E) {
8698 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8699 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008701
Douglas Gregora16548e2009-08-11 05:31:07 +00008702 CXXConstructorDecl *Constructor
8703 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008704 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008705 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008706 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008708
Douglas Gregora16548e2009-08-11 05:31:07 +00008709 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008710 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008711 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008712 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008713 &ArgumentChanged))
8714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008715
Douglas Gregora16548e2009-08-11 05:31:07 +00008716 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008717 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008718 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008719 !ArgumentChanged) {
8720 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008721 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008722 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008724
Richard Smithd59b8322012-12-19 01:39:02 +00008725 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008726 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8727 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008728 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008729 E->getLocEnd());
8730}
Mike Stump11289f42009-09-09 15:08:12 +00008731
Douglas Gregora16548e2009-08-11 05:31:07 +00008732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008733ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008734TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008735
8736 // Transform any init-capture expressions before entering the scope of the
8737 // lambda body, because they are not semantically within that scope.
8738 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8739 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8740 E->explicit_capture_begin());
8741
8742 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8743 CEnd = E->capture_end();
8744 C != CEnd; ++C) {
8745 if (!C->isInitCapture())
8746 continue;
8747 EnterExpressionEvaluationContext EEEC(getSema(),
8748 Sema::PotentiallyEvaluated);
8749 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8750 C->getCapturedVar()->getInit(),
8751 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8752
8753 if (NewExprInitResult.isInvalid())
8754 return ExprError();
8755 Expr *NewExprInit = NewExprInitResult.get();
8756
8757 VarDecl *OldVD = C->getCapturedVar();
8758 QualType NewInitCaptureType =
8759 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8760 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8761 NewExprInit);
8762 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008763 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8764 std::make_pair(NewExprInitResult, NewInitCaptureType);
8765
8766 }
8767
Faisal Vali524ca282013-11-12 01:40:44 +00008768 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008769 // Transform the template parameters, and add them to the current
8770 // instantiation scope. The null case is handled correctly.
8771 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8772 E->getTemplateParameterList());
8773
8774 // Check to see if the TypeSourceInfo of the call operator needs to
8775 // be transformed, and if so do the transformation in the
8776 // CurrentInstantiationScope.
8777
8778 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8779 FunctionProtoTypeLoc OldCallOpFPTL =
8780 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008781 TypeSourceInfo *NewCallOpTSI = nullptr;
8782
Faisal Vali2cba1332013-10-23 06:44:28 +00008783 const bool CallOpWasAlreadyTransformed =
8784 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8785
8786 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8787 if (CallOpWasAlreadyTransformed)
8788 NewCallOpTSI = OldCallOpTSI;
8789 else {
8790 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8791 // The transformation MUST be done in the CurrentInstantiationScope since
8792 // it introduces a mapping of the original to the newly created
8793 // transformed parameters.
8794
8795 TypeLocBuilder NewCallOpTLBuilder;
8796 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8797 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008798 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008799 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8800 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008801 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008802 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8803 // the vector below - this will be used to synthesize the
8804 // NewCallOperator. Additionally, add the parameters of the untransformed
8805 // lambda call operator to the CurrentInstantiationScope.
8806 SmallVector<ParmVarDecl *, 4> Params;
8807 {
8808 FunctionProtoTypeLoc NewCallOpFPTL =
8809 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8810 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008811 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008812
8813 for (unsigned I = 0; I < NewNumArgs; ++I) {
8814 // If this call operator's type does not require transformation,
8815 // the parameters do not get added to the current instantiation scope,
8816 // - so ADD them! This allows the following to compile when the enclosing
8817 // template is specialized and the entire lambda expression has to be
8818 // transformed.
8819 // template<class T> void foo(T t) {
8820 // auto L = [](auto a) {
8821 // auto M = [](char b) { <-- note: non-generic lambda
8822 // auto N = [](auto c) {
8823 // int x = sizeof(a);
8824 // x = sizeof(b); <-- specifically this line
8825 // x = sizeof(c);
8826 // };
8827 // };
8828 // };
8829 // }
8830 // foo('a')
8831 if (CallOpWasAlreadyTransformed)
8832 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8833 NewParamDeclArray[I]);
8834 // Add to Params array, so these parameters can be used to create
8835 // the newly transformed call operator.
8836 Params.push_back(NewParamDeclArray[I]);
8837 }
8838 }
8839
8840 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008841 return ExprError();
8842
Eli Friedmand564afb2012-09-19 01:18:11 +00008843 // Create the local class that will describe the lambda.
8844 CXXRecordDecl *Class
8845 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008846 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008847 /*KnownDependent=*/false,
8848 E->getCaptureDefault());
8849
Eli Friedmand564afb2012-09-19 01:18:11 +00008850 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8851
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008852 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008853 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008854 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008855 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008856 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008857 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008858 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008859
Faisal Vali2cba1332013-10-23 06:44:28 +00008860 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8861
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008862 return getDerived().TransformLambdaScope(E, NewCallOperator,
8863 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008864}
8865
8866template<typename Derived>
8867ExprResult
8868TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008869 CXXMethodDecl *CallOperator,
8870 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008871 bool Invalid = false;
8872
Douglas Gregorb4328232012-02-14 00:00:48 +00008873 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008874 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8875 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008876
Faisal Vali2b391ab2013-09-26 19:54:12 +00008877 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008878 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008879 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008880 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008881 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008882 E->hasExplicitParameters(),
8883 E->hasExplicitResultType(),
8884 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008885
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008886 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008887 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008888 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008889 CEnd = E->capture_end();
8890 C != CEnd; ++C) {
8891 // When we hit the first implicit capture, tell Sema that we've finished
8892 // the list of explicit captures.
8893 if (!FinishedExplicitCaptures && C->isImplicit()) {
8894 getSema().finishLambdaExplicitCaptures(LSI);
8895 FinishedExplicitCaptures = true;
8896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008897
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008898 // Capturing 'this' is trivial.
8899 if (C->capturesThis()) {
8900 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8901 continue;
8902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008903
Richard Smithba71c082013-05-16 06:20:58 +00008904 // Rebuild init-captures, including the implied field declaration.
8905 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008906
8907 InitCaptureInfoTy InitExprTypePair =
8908 InitCaptureExprsAndTypes[C - E->capture_begin()];
8909 ExprResult Init = InitExprTypePair.first;
8910 QualType InitQualType = InitExprTypePair.second;
8911 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008912 Invalid = true;
8913 continue;
8914 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008915 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008916 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8917 OldVD->getLocation(), InitExprTypePair.second,
8918 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008919 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008920 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008921 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008922 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008923 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008924 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008925 continue;
8926 }
8927
8928 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8929
Douglas Gregor3e308b12012-02-14 19:27:52 +00008930 // Determine the capture kind for Sema.
8931 Sema::TryCaptureKind Kind
8932 = C->isImplicit()? Sema::TryCapture_Implicit
8933 : C->getCaptureKind() == LCK_ByCopy
8934 ? Sema::TryCapture_ExplicitByVal
8935 : Sema::TryCapture_ExplicitByRef;
8936 SourceLocation EllipsisLoc;
8937 if (C->isPackExpansion()) {
8938 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8939 bool ShouldExpand = false;
8940 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008941 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008942 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8943 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008944 Unexpanded,
8945 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008946 NumExpansions)) {
8947 Invalid = true;
8948 continue;
8949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008950
Douglas Gregor3e308b12012-02-14 19:27:52 +00008951 if (ShouldExpand) {
8952 // The transform has determined that we should perform an expansion;
8953 // transform and capture each of the arguments.
8954 // expansion of the pattern. Do so.
8955 VarDecl *Pack = C->getCapturedVar();
8956 for (unsigned I = 0; I != *NumExpansions; ++I) {
8957 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8958 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008959 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008960 Pack));
8961 if (!CapturedVar) {
8962 Invalid = true;
8963 continue;
8964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008965
Douglas Gregor3e308b12012-02-14 19:27:52 +00008966 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008967 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8968 }
Richard Smith9467be42014-06-06 17:33:35 +00008969
8970 // FIXME: Retain a pack expansion if RetainExpansion is true.
8971
Douglas Gregor3e308b12012-02-14 19:27:52 +00008972 continue;
8973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008974
Douglas Gregor3e308b12012-02-14 19:27:52 +00008975 EllipsisLoc = C->getEllipsisLoc();
8976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008978 // Transform the captured variable.
8979 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008980 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008981 C->getCapturedVar()));
8982 if (!CapturedVar) {
8983 Invalid = true;
8984 continue;
8985 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008986
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008987 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008988 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008989 }
8990 if (!FinishedExplicitCaptures)
8991 getSema().finishLambdaExplicitCaptures(LSI);
8992
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008993
8994 // Enter a new evaluation context to insulate the lambda from any
8995 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008996 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008997
8998 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008999 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009000 /*IsInstantiation=*/true);
9001 return ExprError();
9002 }
9003
9004 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009005 StmtResult Body = getDerived().TransformStmt(E->getBody());
9006 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009007 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009008 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009009 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009010 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009011
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009012 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009013 /*CurScope=*/nullptr,
9014 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009015}
9016
9017template<typename Derived>
9018ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009019TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009020 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009021 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9022 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009023 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009024
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009026 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009027 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009028 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009029 &ArgumentChanged))
9030 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009031
Douglas Gregora16548e2009-08-11 05:31:07 +00009032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009033 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009035 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009036
Douglas Gregora16548e2009-08-11 05:31:07 +00009037 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009038 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009039 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009040 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 E->getRParenLoc());
9042}
Mike Stump11289f42009-09-09 15:08:12 +00009043
Douglas Gregora16548e2009-08-11 05:31:07 +00009044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009045ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009046TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009047 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009048 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009049 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009050 Expr *OldBase;
9051 QualType BaseType;
9052 QualType ObjectType;
9053 if (!E->isImplicitAccess()) {
9054 OldBase = E->getBase();
9055 Base = getDerived().TransformExpr(OldBase);
9056 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009058
John McCall2d74de92009-12-01 22:10:20 +00009059 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009060 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009061 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009062 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009063 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009064 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009065 ObjectTy,
9066 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009067 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009068 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009069
John McCallba7bf592010-08-24 05:47:05 +00009070 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009071 BaseType = ((Expr*) Base.get())->getType();
9072 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009073 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009074 BaseType = getDerived().TransformType(E->getBaseType());
9075 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9076 }
Mike Stump11289f42009-09-09 15:08:12 +00009077
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009078 // Transform the first part of the nested-name-specifier that qualifies
9079 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009080 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009081 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009082 E->getFirstQualifierFoundInScope(),
9083 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009084
Douglas Gregore16af532011-02-28 18:50:33 +00009085 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009086 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009087 QualifierLoc
9088 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9089 ObjectType,
9090 FirstQualifierInScope);
9091 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009092 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009093 }
Mike Stump11289f42009-09-09 15:08:12 +00009094
Abramo Bagnara7945c982012-01-27 09:46:47 +00009095 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9096
John McCall31f82722010-11-12 08:19:04 +00009097 // TODO: If this is a conversion-function-id, verify that the
9098 // destination type name (if present) resolves the same way after
9099 // instantiation as it did in the local scope.
9100
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009101 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009102 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009103 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009105
John McCall2d74de92009-12-01 22:10:20 +00009106 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009107 // This is a reference to a member without an explicitly-specified
9108 // template argument list. Optimize for this common case.
9109 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009110 Base.get() == OldBase &&
9111 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009112 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009113 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009114 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009115 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009116
John McCallb268a282010-08-23 23:25:46 +00009117 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009118 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009119 E->isArrow(),
9120 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009121 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009122 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009123 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009124 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009125 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009126 }
9127
John McCall6b51f282009-11-23 01:53:49 +00009128 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009129 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9130 E->getNumTemplateArgs(),
9131 TransArgs))
9132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009133
John McCallb268a282010-08-23 23:25:46 +00009134 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009135 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 E->isArrow(),
9137 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009138 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009139 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009140 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009141 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009142 &TransArgs);
9143}
9144
9145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009147TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009148 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009149 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009150 QualType BaseType;
9151 if (!Old->isImplicitAccess()) {
9152 Base = getDerived().TransformExpr(Old->getBase());
9153 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009154 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009155 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009156 Old->isArrow());
9157 if (Base.isInvalid())
9158 return ExprError();
9159 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009160 } else {
9161 BaseType = getDerived().TransformType(Old->getBaseType());
9162 }
John McCall10eae182009-11-30 22:42:35 +00009163
Douglas Gregor0da1d432011-02-28 20:01:57 +00009164 NestedNameSpecifierLoc QualifierLoc;
9165 if (Old->getQualifierLoc()) {
9166 QualifierLoc
9167 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9168 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009169 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009170 }
9171
Abramo Bagnara7945c982012-01-27 09:46:47 +00009172 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9173
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009174 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009175 Sema::LookupOrdinaryName);
9176
9177 // Transform all the decls.
9178 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9179 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009180 NamedDecl *InstD = static_cast<NamedDecl*>(
9181 getDerived().TransformDecl(Old->getMemberLoc(),
9182 *I));
John McCall84d87672009-12-10 09:41:52 +00009183 if (!InstD) {
9184 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9185 // This can happen because of dependent hiding.
9186 if (isa<UsingShadowDecl>(*I))
9187 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009188 else {
9189 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009190 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009191 }
John McCall84d87672009-12-10 09:41:52 +00009192 }
John McCall10eae182009-11-30 22:42:35 +00009193
9194 // Expand using declarations.
9195 if (isa<UsingDecl>(InstD)) {
9196 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009197 for (auto *I : UD->shadows())
9198 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009199 continue;
9200 }
9201
9202 R.addDecl(InstD);
9203 }
9204
9205 R.resolveKind();
9206
Douglas Gregor9262f472010-04-27 18:19:34 +00009207 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009208 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009209 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009210 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009211 Old->getMemberLoc(),
9212 Old->getNamingClass()));
9213 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009214 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009215
Douglas Gregorda7be082010-04-27 16:10:10 +00009216 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009217 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009218
John McCall10eae182009-11-30 22:42:35 +00009219 TemplateArgumentListInfo TransArgs;
9220 if (Old->hasExplicitTemplateArgs()) {
9221 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9222 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009223 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9224 Old->getNumTemplateArgs(),
9225 TransArgs))
9226 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009227 }
John McCall38836f02010-01-15 08:34:02 +00009228
9229 // FIXME: to do this check properly, we will need to preserve the
9230 // first-qualifier-in-scope here, just in case we had a dependent
9231 // base (and therefore couldn't do the check) and a
9232 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009233 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009234
John McCallb268a282010-08-23 23:25:46 +00009235 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009236 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009237 Old->getOperatorLoc(),
9238 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009239 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009240 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009241 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009242 R,
9243 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009244 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009245}
9246
9247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009248ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009249TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009250 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009251 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9252 if (SubExpr.isInvalid())
9253 return ExprError();
9254
9255 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009256 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009257
9258 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9259}
9260
9261template<typename Derived>
9262ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009263TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009264 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9265 if (Pattern.isInvalid())
9266 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009267
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009268 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009269 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009270
Douglas Gregorb8840002011-01-14 21:20:45 +00009271 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9272 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009273}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009274
9275template<typename Derived>
9276ExprResult
9277TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9278 // If E is not value-dependent, then nothing will change when we transform it.
9279 // Note: This is an instantiation-centric view.
9280 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009281 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009282
9283 // Note: None of the implementations of TryExpandParameterPacks can ever
9284 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009285 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009286 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9287 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009288 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009289 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009290 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009291 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009292 ShouldExpand, RetainExpansion,
9293 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009294 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009295
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009296 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009297 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009298
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009299 NamedDecl *Pack = E->getPack();
9300 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009301 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009302 Pack));
9303 if (!Pack)
9304 return ExprError();
9305 }
9306
Chad Rosier1dcde962012-08-08 18:46:20 +00009307
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009308 // We now know the length of the parameter pack, so build a new expression
9309 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009310 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9311 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009312 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009313}
9314
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009315template<typename Derived>
9316ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009317TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9318 SubstNonTypeTemplateParmPackExpr *E) {
9319 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009320 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009321}
9322
9323template<typename Derived>
9324ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009325TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9326 SubstNonTypeTemplateParmExpr *E) {
9327 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009328 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009329}
9330
9331template<typename Derived>
9332ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009333TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9334 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009335 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009336}
9337
9338template<typename Derived>
9339ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009340TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9341 MaterializeTemporaryExpr *E) {
9342 return getDerived().TransformExpr(E->GetTemporaryExpr());
9343}
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregorfe314812011-06-21 17:03:29 +00009345template<typename Derived>
9346ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009347TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9348 CXXStdInitializerListExpr *E) {
9349 return getDerived().TransformExpr(E->getSubExpr());
9350}
9351
9352template<typename Derived>
9353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009354TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009355 return SemaRef.MaybeBindToTemporary(E);
9356}
9357
9358template<typename Derived>
9359ExprResult
9360TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009361 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009362}
9363
9364template<typename Derived>
9365ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009366TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9367 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9368 if (SubExpr.isInvalid())
9369 return ExprError();
9370
9371 if (!getDerived().AlwaysRebuild() &&
9372 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009373 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009374
9375 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009376}
9377
9378template<typename Derived>
9379ExprResult
9380TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9381 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009382 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009383 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009384 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009385 /*IsCall=*/false, Elements, &ArgChanged))
9386 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009387
Ted Kremeneke65b0862012-03-06 20:05:56 +00009388 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9389 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009390
Ted Kremeneke65b0862012-03-06 20:05:56 +00009391 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9392 Elements.data(),
9393 Elements.size());
9394}
9395
9396template<typename Derived>
9397ExprResult
9398TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009399 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009400 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009401 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009402 bool ArgChanged = false;
9403 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9404 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009405
Ted Kremeneke65b0862012-03-06 20:05:56 +00009406 if (OrigElement.isPackExpansion()) {
9407 // This key/value element is a pack expansion.
9408 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9409 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9410 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9411 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9412
9413 // Determine whether the set of unexpanded parameter packs can
9414 // and should be expanded.
9415 bool Expand = true;
9416 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009417 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9418 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009419 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9420 OrigElement.Value->getLocEnd());
9421 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9422 PatternRange,
9423 Unexpanded,
9424 Expand, RetainExpansion,
9425 NumExpansions))
9426 return ExprError();
9427
9428 if (!Expand) {
9429 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009430 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009431 // expansion.
9432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9433 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9434 if (Key.isInvalid())
9435 return ExprError();
9436
9437 if (Key.get() != OrigElement.Key)
9438 ArgChanged = true;
9439
9440 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9441 if (Value.isInvalid())
9442 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009443
Ted Kremeneke65b0862012-03-06 20:05:56 +00009444 if (Value.get() != OrigElement.Value)
9445 ArgChanged = true;
9446
Chad Rosier1dcde962012-08-08 18:46:20 +00009447 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009448 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9449 };
9450 Elements.push_back(Expansion);
9451 continue;
9452 }
9453
9454 // Record right away that the argument was changed. This needs
9455 // to happen even if the array expands to nothing.
9456 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009457
Ted Kremeneke65b0862012-03-06 20:05:56 +00009458 // The transform has determined that we should perform an elementwise
9459 // expansion of the pattern. Do so.
9460 for (unsigned I = 0; I != *NumExpansions; ++I) {
9461 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9462 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9463 if (Key.isInvalid())
9464 return ExprError();
9465
9466 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9467 if (Value.isInvalid())
9468 return ExprError();
9469
Chad Rosier1dcde962012-08-08 18:46:20 +00009470 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009471 Key.get(), Value.get(), SourceLocation(), NumExpansions
9472 };
9473
9474 // If any unexpanded parameter packs remain, we still have a
9475 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009476 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009477 if (Key.get()->containsUnexpandedParameterPack() ||
9478 Value.get()->containsUnexpandedParameterPack())
9479 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009480
Ted Kremeneke65b0862012-03-06 20:05:56 +00009481 Elements.push_back(Element);
9482 }
9483
Richard Smith9467be42014-06-06 17:33:35 +00009484 // FIXME: Retain a pack expansion if RetainExpansion is true.
9485
Ted Kremeneke65b0862012-03-06 20:05:56 +00009486 // We've finished with this pack expansion.
9487 continue;
9488 }
9489
9490 // Transform and check key.
9491 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9492 if (Key.isInvalid())
9493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009494
Ted Kremeneke65b0862012-03-06 20:05:56 +00009495 if (Key.get() != OrigElement.Key)
9496 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009497
Ted Kremeneke65b0862012-03-06 20:05:56 +00009498 // Transform and check value.
9499 ExprResult Value
9500 = getDerived().TransformExpr(OrigElement.Value);
9501 if (Value.isInvalid())
9502 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009503
Ted Kremeneke65b0862012-03-06 20:05:56 +00009504 if (Value.get() != OrigElement.Value)
9505 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009506
9507 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009508 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009509 };
9510 Elements.push_back(Element);
9511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009512
Ted Kremeneke65b0862012-03-06 20:05:56 +00009513 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9514 return SemaRef.MaybeBindToTemporary(E);
9515
9516 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9517 Elements.data(),
9518 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009519}
9520
Mike Stump11289f42009-09-09 15:08:12 +00009521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009523TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009524 TypeSourceInfo *EncodedTypeInfo
9525 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9526 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009528
Douglas Gregora16548e2009-08-11 05:31:07 +00009529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009530 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009531 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009532
9533 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009534 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009535 E->getRParenLoc());
9536}
Mike Stump11289f42009-09-09 15:08:12 +00009537
Douglas Gregora16548e2009-08-11 05:31:07 +00009538template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009539ExprResult TreeTransform<Derived>::
9540TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009541 // This is a kind of implicit conversion, and it needs to get dropped
9542 // and recomputed for the same general reasons that ImplicitCastExprs
9543 // do, as well a more specific one: this expression is only valid when
9544 // it appears *immediately* as an argument expression.
9545 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009546}
9547
9548template<typename Derived>
9549ExprResult TreeTransform<Derived>::
9550TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009551 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009552 = getDerived().TransformType(E->getTypeInfoAsWritten());
9553 if (!TSInfo)
9554 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009555
John McCall31168b02011-06-15 23:02:42 +00009556 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009557 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009558 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009559
John McCall31168b02011-06-15 23:02:42 +00009560 if (!getDerived().AlwaysRebuild() &&
9561 TSInfo == E->getTypeInfoAsWritten() &&
9562 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009563 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009564
John McCall31168b02011-06-15 23:02:42 +00009565 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009566 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009567 Result.get());
9568}
9569
9570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009571ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009572TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009573 // Transform arguments.
9574 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009575 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009576 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009577 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009578 &ArgChanged))
9579 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009580
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009581 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9582 // Class message: transform the receiver type.
9583 TypeSourceInfo *ReceiverTypeInfo
9584 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9585 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009586 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009588 // If nothing changed, just retain the existing message send.
9589 if (!getDerived().AlwaysRebuild() &&
9590 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009591 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009592
9593 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009594 SmallVector<SourceLocation, 16> SelLocs;
9595 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009596 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9597 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009598 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009599 E->getMethodDecl(),
9600 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009601 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009602 E->getRightLoc());
9603 }
9604
9605 // Instance message: transform the receiver
9606 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9607 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009608 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009609 = getDerived().TransformExpr(E->getInstanceReceiver());
9610 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009611 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009612
9613 // If nothing changed, just retain the existing message send.
9614 if (!getDerived().AlwaysRebuild() &&
9615 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009616 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009617
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009618 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009619 SmallVector<SourceLocation, 16> SelLocs;
9620 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009621 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009622 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009623 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009624 E->getMethodDecl(),
9625 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009626 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009627 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009633 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009634}
9635
Mike Stump11289f42009-09-09 15:08:12 +00009636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009638TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009639 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009640}
9641
Mike Stump11289f42009-09-09 15:08:12 +00009642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009644TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009645 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009646 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009647 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009648 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009649
9650 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009651
Douglas Gregord51d90d2010-04-26 20:11:03 +00009652 // If nothing changed, just retain the existing expression.
9653 if (!getDerived().AlwaysRebuild() &&
9654 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009655 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009656
John McCallb268a282010-08-23 23:25:46 +00009657 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009658 E->getLocation(),
9659 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009660}
9661
Mike Stump11289f42009-09-09 15:08:12 +00009662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009664TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009665 // 'super' and types never change. Property never changes. Just
9666 // retain the existing expression.
9667 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009668 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009669
Douglas Gregor9faee212010-04-26 20:47:02 +00009670 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009671 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009672 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009673 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009674
Douglas Gregor9faee212010-04-26 20:47:02 +00009675 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009676
Douglas Gregor9faee212010-04-26 20:47:02 +00009677 // If nothing changed, just retain the existing expression.
9678 if (!getDerived().AlwaysRebuild() &&
9679 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009680 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009681
John McCallb7bd14f2010-12-02 01:19:52 +00009682 if (E->isExplicitProperty())
9683 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9684 E->getExplicitProperty(),
9685 E->getLocation());
9686
9687 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009688 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009689 E->getImplicitPropertyGetter(),
9690 E->getImplicitPropertySetter(),
9691 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009692}
9693
Mike Stump11289f42009-09-09 15:08:12 +00009694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009695ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009696TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9697 // Transform the base expression.
9698 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9699 if (Base.isInvalid())
9700 return ExprError();
9701
9702 // Transform the key expression.
9703 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9704 if (Key.isInvalid())
9705 return ExprError();
9706
9707 // If nothing changed, just retain the existing expression.
9708 if (!getDerived().AlwaysRebuild() &&
9709 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009710 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009711
Chad Rosier1dcde962012-08-08 18:46:20 +00009712 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009713 Base.get(), Key.get(),
9714 E->getAtIndexMethodDecl(),
9715 E->setAtIndexMethodDecl());
9716}
9717
9718template<typename Derived>
9719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009720TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009721 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009722 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009723 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009724 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009725
Douglas Gregord51d90d2010-04-26 20:11:03 +00009726 // If nothing changed, just retain the existing expression.
9727 if (!getDerived().AlwaysRebuild() &&
9728 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009729 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009730
John McCallb268a282010-08-23 23:25:46 +00009731 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009732 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009733 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009734}
9735
Mike Stump11289f42009-09-09 15:08:12 +00009736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009738TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009739 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009740 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009741 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009742 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009743 SubExprs, &ArgumentChanged))
9744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009745
Douglas Gregora16548e2009-08-11 05:31:07 +00009746 if (!getDerived().AlwaysRebuild() &&
9747 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009748 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009749
Douglas Gregora16548e2009-08-11 05:31:07 +00009750 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009751 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009752 E->getRParenLoc());
9753}
9754
Mike Stump11289f42009-09-09 15:08:12 +00009755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009756ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009757TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9758 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9759 if (SrcExpr.isInvalid())
9760 return ExprError();
9761
9762 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9763 if (!Type)
9764 return ExprError();
9765
9766 if (!getDerived().AlwaysRebuild() &&
9767 Type == E->getTypeSourceInfo() &&
9768 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009769 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009770
9771 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9772 SrcExpr.get(), Type,
9773 E->getRParenLoc());
9774}
9775
9776template<typename Derived>
9777ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009778TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009779 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009780
Craig Topperc3ec1492014-05-26 06:22:03 +00009781 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009782 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9783
9784 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009785 blockScope->TheDecl->setBlockMissingReturnType(
9786 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009787
Chris Lattner01cf8db2011-07-20 06:58:45 +00009788 SmallVector<ParmVarDecl*, 4> params;
9789 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009790
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009791 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009792 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9793 oldBlock->param_begin(),
9794 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009795 nullptr, paramTypes, &params)) {
9796 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009797 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009798 }
John McCall490112f2011-02-04 18:33:18 +00009799
Jordan Rosea0a86be2013-03-08 22:25:36 +00009800 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009801 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009802 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009803
Jordan Rose5c382722013-03-08 21:51:21 +00009804 QualType functionType =
9805 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009806 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009807 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009808
9809 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009810 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009811 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009812
9813 if (!oldBlock->blockMissingReturnType()) {
9814 blockScope->HasImplicitReturnType = false;
9815 blockScope->ReturnType = exprResultType;
9816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009817
John McCall3882ace2011-01-05 12:14:39 +00009818 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009819 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009820 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009821 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009822 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009823 }
John McCall3882ace2011-01-05 12:14:39 +00009824
John McCall490112f2011-02-04 18:33:18 +00009825#ifndef NDEBUG
9826 // In builds with assertions, make sure that we captured everything we
9827 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009828 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009829 for (const auto &I : oldBlock->captures()) {
9830 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009831
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009832 // Ignore parameter packs.
9833 if (isa<ParmVarDecl>(oldCapture) &&
9834 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9835 continue;
John McCall490112f2011-02-04 18:33:18 +00009836
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009837 VarDecl *newCapture =
9838 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9839 oldCapture));
9840 assert(blockScope->CaptureMap.count(newCapture));
9841 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009842 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009843 }
9844#endif
9845
9846 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009847 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009848}
9849
Mike Stump11289f42009-09-09 15:08:12 +00009850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009851ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009852TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009853 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009854}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009855
9856template<typename Derived>
9857ExprResult
9858TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009859 QualType RetTy = getDerived().TransformType(E->getType());
9860 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009861 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009862 SubExprs.reserve(E->getNumSubExprs());
9863 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9864 SubExprs, &ArgumentChanged))
9865 return ExprError();
9866
9867 if (!getDerived().AlwaysRebuild() &&
9868 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009869 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009870
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009871 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009872 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009873}
Chad Rosier1dcde962012-08-08 18:46:20 +00009874
Douglas Gregora16548e2009-08-11 05:31:07 +00009875//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009876// Type reconstruction
9877//===----------------------------------------------------------------------===//
9878
Mike Stump11289f42009-09-09 15:08:12 +00009879template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009880QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9881 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009882 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009883 getDerived().getBaseEntity());
9884}
9885
Mike Stump11289f42009-09-09 15:08:12 +00009886template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009887QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9888 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009889 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009890 getDerived().getBaseEntity());
9891}
9892
Mike Stump11289f42009-09-09 15:08:12 +00009893template<typename Derived>
9894QualType
John McCall70dd5f62009-10-30 00:06:24 +00009895TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9896 bool WrittenAsLValue,
9897 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009898 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009899 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009900}
9901
9902template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009903QualType
John McCall70dd5f62009-10-30 00:06:24 +00009904TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9905 QualType ClassType,
9906 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009907 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9908 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009909}
9910
9911template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009912QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009913TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9914 ArrayType::ArraySizeModifier SizeMod,
9915 const llvm::APInt *Size,
9916 Expr *SizeExpr,
9917 unsigned IndexTypeQuals,
9918 SourceRange BracketsRange) {
9919 if (SizeExpr || !Size)
9920 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9921 IndexTypeQuals, BracketsRange,
9922 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009923
9924 QualType Types[] = {
9925 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9926 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9927 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009928 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009929 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009930 QualType SizeType;
9931 for (unsigned I = 0; I != NumTypes; ++I)
9932 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9933 SizeType = Types[I];
9934 break;
9935 }
Mike Stump11289f42009-09-09 15:08:12 +00009936
Eli Friedman9562f392012-01-25 23:20:27 +00009937 // Note that we can return a VariableArrayType here in the case where
9938 // the element type was a dependent VariableArrayType.
9939 IntegerLiteral *ArraySize
9940 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9941 /*FIXME*/BracketsRange.getBegin());
9942 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009943 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009944 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009945}
Mike Stump11289f42009-09-09 15:08:12 +00009946
Douglas Gregord6ff3322009-08-04 16:50:30 +00009947template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009948QualType
9949TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009950 ArrayType::ArraySizeModifier SizeMod,
9951 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009952 unsigned IndexTypeQuals,
9953 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009954 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009955 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009956}
9957
9958template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009959QualType
Mike Stump11289f42009-09-09 15:08:12 +00009960TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009961 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009962 unsigned IndexTypeQuals,
9963 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009964 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009965 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009966}
Mike Stump11289f42009-09-09 15:08:12 +00009967
Douglas Gregord6ff3322009-08-04 16:50:30 +00009968template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009969QualType
9970TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009971 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009972 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009973 unsigned IndexTypeQuals,
9974 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009975 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009976 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009977 IndexTypeQuals, BracketsRange);
9978}
9979
9980template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009981QualType
9982TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009983 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009984 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009985 unsigned IndexTypeQuals,
9986 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009987 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009988 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009989 IndexTypeQuals, BracketsRange);
9990}
9991
9992template<typename Derived>
9993QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009994 unsigned NumElements,
9995 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009996 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009997 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009998}
Mike Stump11289f42009-09-09 15:08:12 +00009999
Douglas Gregord6ff3322009-08-04 16:50:30 +000010000template<typename Derived>
10001QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10002 unsigned NumElements,
10003 SourceLocation AttributeLoc) {
10004 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10005 NumElements, true);
10006 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010007 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10008 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010009 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010010}
Mike Stump11289f42009-09-09 15:08:12 +000010011
Douglas Gregord6ff3322009-08-04 16:50:30 +000010012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010013QualType
10014TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010015 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010016 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010017 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010018}
Mike Stump11289f42009-09-09 15:08:12 +000010019
Douglas Gregord6ff3322009-08-04 16:50:30 +000010020template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010021QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10022 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010023 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010024 const FunctionProtoType::ExtProtoInfo &EPI) {
10025 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010026 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010027 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010028 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010029}
Mike Stump11289f42009-09-09 15:08:12 +000010030
Douglas Gregord6ff3322009-08-04 16:50:30 +000010031template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010032QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10033 return SemaRef.Context.getFunctionNoProtoType(T);
10034}
10035
10036template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010037QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10038 assert(D && "no decl found");
10039 if (D->isInvalidDecl()) return QualType();
10040
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010041 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010042 TypeDecl *Ty;
10043 if (isa<UsingDecl>(D)) {
10044 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010045 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010046 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10047
10048 // A valid resolved using typename decl points to exactly one type decl.
10049 assert(++Using->shadow_begin() == Using->shadow_end());
10050 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010051
John McCallb96ec562009-12-04 22:46:56 +000010052 } else {
10053 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10054 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10055 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10056 }
10057
10058 return SemaRef.Context.getTypeDeclType(Ty);
10059}
10060
10061template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010062QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10063 SourceLocation Loc) {
10064 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010065}
10066
10067template<typename Derived>
10068QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10069 return SemaRef.Context.getTypeOfType(Underlying);
10070}
10071
10072template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010073QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10074 SourceLocation Loc) {
10075 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010076}
10077
10078template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010079QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10080 UnaryTransformType::UTTKind UKind,
10081 SourceLocation Loc) {
10082 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10083}
10084
10085template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010086QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010087 TemplateName Template,
10088 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010089 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010090 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010091}
Mike Stump11289f42009-09-09 15:08:12 +000010092
Douglas Gregor1135c352009-08-06 05:28:30 +000010093template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010094QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10095 SourceLocation KWLoc) {
10096 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10097}
10098
10099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010100TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010101TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010102 bool TemplateKW,
10103 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010104 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010105 Template);
10106}
10107
10108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010109TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010110TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10111 const IdentifierInfo &Name,
10112 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010113 QualType ObjectType,
10114 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010115 UnqualifiedId TemplateName;
10116 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010117 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010118 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010119 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010120 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010121 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010122 /*EnteringContext=*/false,
10123 Template);
John McCall31f82722010-11-12 08:19:04 +000010124 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010125}
Mike Stump11289f42009-09-09 15:08:12 +000010126
Douglas Gregora16548e2009-08-11 05:31:07 +000010127template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010128TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010129TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010130 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010131 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010132 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010133 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010134 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010135 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010136 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010137 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010138 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010139 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010140 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010141 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010142 /*EnteringContext=*/false,
10143 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010144 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010145}
Chad Rosier1dcde962012-08-08 18:46:20 +000010146
Douglas Gregor71395fa2009-11-04 00:56:37 +000010147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010148ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010149TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10150 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010151 Expr *OrigCallee,
10152 Expr *First,
10153 Expr *Second) {
10154 Expr *Callee = OrigCallee->IgnoreParenCasts();
10155 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010156
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010157 if (First->getObjectKind() == OK_ObjCProperty) {
10158 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10159 if (BinaryOperator::isAssignmentOp(Opc))
10160 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10161 First, Second);
10162 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10163 if (Result.isInvalid())
10164 return ExprError();
10165 First = Result.get();
10166 }
10167
10168 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10169 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10170 if (Result.isInvalid())
10171 return ExprError();
10172 Second = Result.get();
10173 }
10174
Douglas Gregora16548e2009-08-11 05:31:07 +000010175 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010176 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010177 if (!First->getType()->isOverloadableType() &&
10178 !Second->getType()->isOverloadableType())
10179 return getSema().CreateBuiltinArraySubscriptExpr(First,
10180 Callee->getLocStart(),
10181 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010182 } else if (Op == OO_Arrow) {
10183 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010184 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10185 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010186 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010187 // The argument is not of overloadable type, so try to create a
10188 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010189 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010190 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010191
John McCallb268a282010-08-23 23:25:46 +000010192 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010193 }
10194 } else {
John McCallb268a282010-08-23 23:25:46 +000010195 if (!First->getType()->isOverloadableType() &&
10196 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010197 // Neither of the arguments is an overloadable type, so try to
10198 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010199 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010200 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010201 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010202 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010203 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010204
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010205 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010206 }
10207 }
Mike Stump11289f42009-09-09 15:08:12 +000010208
10209 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010210 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010211 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010212
John McCallb268a282010-08-23 23:25:46 +000010213 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010214 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010215 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010216 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010217 // If we've resolved this to a particular non-member function, just call
10218 // that function. If we resolved it to a member function,
10219 // CreateOverloaded* will find that function for us.
10220 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10221 if (!isa<CXXMethodDecl>(ND))
10222 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010223 }
Mike Stump11289f42009-09-09 15:08:12 +000010224
Douglas Gregora16548e2009-08-11 05:31:07 +000010225 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010226 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010227 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010228
Douglas Gregora16548e2009-08-11 05:31:07 +000010229 // Create the overloaded operator invocation for unary operators.
10230 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010231 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010232 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010233 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010234 }
Mike Stump11289f42009-09-09 15:08:12 +000010235
Douglas Gregore9d62932011-07-15 16:25:15 +000010236 if (Op == OO_Subscript) {
10237 SourceLocation LBrace;
10238 SourceLocation RBrace;
10239
10240 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10241 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10242 LBrace = SourceLocation::getFromRawEncoding(
10243 NameLoc.CXXOperatorName.BeginOpNameLoc);
10244 RBrace = SourceLocation::getFromRawEncoding(
10245 NameLoc.CXXOperatorName.EndOpNameLoc);
10246 } else {
10247 LBrace = Callee->getLocStart();
10248 RBrace = OpLoc;
10249 }
10250
10251 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10252 First, Second);
10253 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010254
Douglas Gregora16548e2009-08-11 05:31:07 +000010255 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010256 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010257 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010258 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10259 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010261
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010262 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010263}
Mike Stump11289f42009-09-09 15:08:12 +000010264
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010265template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010266ExprResult
John McCallb268a282010-08-23 23:25:46 +000010267TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010268 SourceLocation OperatorLoc,
10269 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010270 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010271 TypeSourceInfo *ScopeType,
10272 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010273 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010274 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010275 QualType BaseType = Base->getType();
10276 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010277 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010278 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010279 !BaseType->getAs<PointerType>()->getPointeeType()
10280 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010281 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010282 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010283 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010284 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010285 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010286 /*FIXME?*/true);
10287 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010288
Douglas Gregor678f90d2010-02-25 01:56:36 +000010289 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010290 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10291 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10292 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10293 NameInfo.setNamedTypeInfo(DestroyedType);
10294
Richard Smith8e4a3862012-05-15 06:15:11 +000010295 // The scope type is now known to be a valid nested name specifier
10296 // component. Tack it on to the end of the nested name specifier.
10297 if (ScopeType)
10298 SS.Extend(SemaRef.Context, SourceLocation(),
10299 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010300
Abramo Bagnara7945c982012-01-27 09:46:47 +000010301 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010302 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010303 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010304 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010305 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010306 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010307 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010308}
10309
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010310template<typename Derived>
10311StmtResult
10312TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010313 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010314 CapturedDecl *CD = S->getCapturedDecl();
10315 unsigned NumParams = CD->getNumParams();
10316 unsigned ContextParamPos = CD->getContextParamPosition();
10317 SmallVector<Sema::CapturedParamNameType, 4> Params;
10318 for (unsigned I = 0; I < NumParams; ++I) {
10319 if (I != ContextParamPos) {
10320 Params.push_back(
10321 std::make_pair(
10322 CD->getParam(I)->getName(),
10323 getDerived().TransformType(CD->getParam(I)->getType())));
10324 } else {
10325 Params.push_back(std::make_pair(StringRef(), QualType()));
10326 }
10327 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010328 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010329 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010330 StmtResult Body;
10331 {
10332 Sema::CompoundScopeRAII CompoundScope(getSema());
10333 Body = getDerived().TransformStmt(S->getCapturedStmt());
10334 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010335
10336 if (Body.isInvalid()) {
10337 getSema().ActOnCapturedRegionError();
10338 return StmtError();
10339 }
10340
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010341 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010342}
10343
Douglas Gregord6ff3322009-08-04 16:50:30 +000010344} // end namespace clang
10345
10346#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H