blob: 94b2e959df95317bb2762ca4c48b03df9f70d2ee [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000609 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
852 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Craig Topperc3ec1492014-05-26 06:22:03 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Craig Topperc3ec1492014-05-26 06:22:03 +0000916 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001083 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001190 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001304 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001316 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev62c87d22014-03-21 04:51:18 +00001326 /// \brief Build a new OpenMP 'safelen' clause.
1327 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001328 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1331 SourceLocation LParenLoc,
1332 SourceLocation EndLoc) {
1333 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1334 }
1335
Alexander Musman8bd31e62014-05-27 15:12:19 +00001336 /// \brief Build a new OpenMP 'collapse' clause.
1337 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001338 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1341 SourceLocation LParenLoc,
1342 SourceLocation EndLoc) {
1343 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1344 EndLoc);
1345 }
1346
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001347 /// \brief Build a new OpenMP 'default' clause.
1348 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001349 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001350 /// Subclasses may override this routine to provide different behavior.
1351 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1352 SourceLocation KindKwLoc,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1357 StartLoc, LParenLoc, EndLoc);
1358 }
1359
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001360 /// \brief Build a new OpenMP 'proc_bind' clause.
1361 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001362 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001363 /// Subclasses may override this routine to provide different behavior.
1364 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1365 SourceLocation KindKwLoc,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1370 StartLoc, LParenLoc, EndLoc);
1371 }
1372
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 /// \brief Build a new OpenMP 'private' clause.
1374 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001375 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001385 /// \brief Build a new OpenMP 'firstprivate' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexander Musman1bb328c2014-06-04 13:06:39 +00001397 /// \brief Build a new OpenMP 'lastprivate' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001409 /// \brief Build a new OpenMP 'shared' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001412 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001413 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1414 SourceLocation StartLoc,
1415 SourceLocation LParenLoc,
1416 SourceLocation EndLoc) {
1417 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1418 EndLoc);
1419 }
1420
Alexander Musman8dba6642014-04-22 13:09:42 +00001421 /// \brief Build a new OpenMP 'linear' clause.
1422 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001423 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001424 /// Subclasses may override this routine to provide different behavior.
1425 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1426 SourceLocation StartLoc,
1427 SourceLocation LParenLoc,
1428 SourceLocation ColonLoc,
1429 SourceLocation EndLoc) {
1430 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1431 ColonLoc, EndLoc);
1432 }
1433
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001434 /// \brief Build a new OpenMP 'aligned' clause.
1435 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001436 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001437 /// Subclasses may override this routine to provide different behavior.
1438 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1439 SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 SourceLocation ColonLoc,
1442 SourceLocation EndLoc) {
1443 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1444 LParenLoc, ColonLoc, EndLoc);
1445 }
1446
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001447 /// \brief Build a new OpenMP 'copyin' clause.
1448 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001449 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001450 /// Subclasses may override this routine to provide different behavior.
1451 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1452 SourceLocation StartLoc,
1453 SourceLocation LParenLoc,
1454 SourceLocation EndLoc) {
1455 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1456 EndLoc);
1457 }
1458
James Dennett2a4d13c2012-06-15 07:13:21 +00001459 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001460 ///
1461 /// By default, performs semantic analysis to build the new statement.
1462 /// Subclasses may override this routine to provide different behavior.
1463 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1464 Expr *object) {
1465 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1466 }
1467
James Dennett2a4d13c2012-06-15 07:13:21 +00001468 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001469 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001473 Expr *Object, Stmt *Body) {
1474 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001475 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001476
James Dennett2a4d13c2012-06-15 07:13:21 +00001477 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1481 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1482 Stmt *Body) {
1483 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1484 }
John McCall53848232011-07-27 01:07:15 +00001485
Douglas Gregorf68a5082010-04-22 23:10:45 +00001486 /// \brief Build a new Objective-C fast enumeration statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001490 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001491 Stmt *Element,
1492 Expr *Collection,
1493 SourceLocation RParenLoc,
1494 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001495 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001496 Element,
John McCallb268a282010-08-23 23:25:46 +00001497 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001498 RParenLoc);
1499 if (ForEachStmt.isInvalid())
1500 return StmtError();
1501
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001502 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001504
Douglas Gregorebe10102009-08-20 07:17:43 +00001505 /// \brief Build a new C++ exception declaration.
1506 ///
1507 /// By default, performs semantic analysis to build the new decaration.
1508 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001509 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001510 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001511 SourceLocation StartLoc,
1512 SourceLocation IdLoc,
1513 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001514 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001515 StartLoc, IdLoc, Id);
1516 if (Var)
1517 getSema().CurContext->addDecl(Var);
1518 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001519 }
1520
1521 /// \brief Build a new C++ catch statement.
1522 ///
1523 /// By default, performs semantic analysis to build the new statement.
1524 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001525 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001526 VarDecl *ExceptionDecl,
1527 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001528 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1529 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001530 }
Mike Stump11289f42009-09-09 15:08:12 +00001531
Douglas Gregorebe10102009-08-20 07:17:43 +00001532 /// \brief Build a new C++ try statement.
1533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001536 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1537 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001538 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001539 }
Mike Stump11289f42009-09-09 15:08:12 +00001540
Richard Smith02e85f32011-04-14 22:09:26 +00001541 /// \brief Build a new C++0x range-based for statement.
1542 ///
1543 /// By default, performs semantic analysis to build the new statement.
1544 /// Subclasses may override this routine to provide different behavior.
1545 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1546 SourceLocation ColonLoc,
1547 Stmt *Range, Stmt *BeginEnd,
1548 Expr *Cond, Expr *Inc,
1549 Stmt *LoopVar,
1550 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001551 // If we've just learned that the range is actually an Objective-C
1552 // collection, treat this as an Objective-C fast enumeration loop.
1553 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1554 if (RangeStmt->isSingleDecl()) {
1555 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001556 if (RangeVar->isInvalidDecl())
1557 return StmtError();
1558
Douglas Gregorf7106af2013-04-08 18:40:13 +00001559 Expr *RangeExpr = RangeVar->getInit();
1560 if (!RangeExpr->isTypeDependent() &&
1561 RangeExpr->getType()->isObjCObjectPointerType())
1562 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1563 RParenLoc);
1564 }
1565 }
1566 }
1567
Richard Smith02e85f32011-04-14 22:09:26 +00001568 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001569 Cond, Inc, LoopVar, RParenLoc,
1570 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001571 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001572
1573 /// \brief Build a new C++0x range-based for statement.
1574 ///
1575 /// By default, performs semantic analysis to build the new statement.
1576 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001577 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001578 bool IsIfExists,
1579 NestedNameSpecifierLoc QualifierLoc,
1580 DeclarationNameInfo NameInfo,
1581 Stmt *Nested) {
1582 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1583 QualifierLoc, NameInfo, Nested);
1584 }
1585
Richard Smith02e85f32011-04-14 22:09:26 +00001586 /// \brief Attach body to a C++0x range-based for statement.
1587 ///
1588 /// By default, performs semantic analysis to finish the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
1590 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1591 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001593
David Majnemerfad8f482013-10-15 09:33:02 +00001594 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1595 Stmt *TryBlock, Stmt *Handler) {
1596 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001597 }
1598
David Majnemerfad8f482013-10-15 09:33:02 +00001599 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001600 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001601 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001602 }
1603
David Majnemerfad8f482013-10-15 09:33:02 +00001604 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1605 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001606 }
1607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new expression that references a declaration.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001613 LookupResult &R,
1614 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001615 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1616 }
1617
1618
1619 /// \brief Build a new expression that references a declaration.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001623 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001624 ValueDecl *VD,
1625 const DeclarationNameInfo &NameInfo,
1626 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001627 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001628 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001629
1630 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001631
1632 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001636 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001641 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 }
1643
Douglas Gregorad8a3362009-09-04 17:36:40 +00001644 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001645 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001648 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001649 SourceLocation OperatorLoc,
1650 bool isArrow,
1651 CXXScopeSpec &SS,
1652 TypeSourceInfo *ScopeType,
1653 SourceLocation CCLoc,
1654 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001655 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001658 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001661 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001662 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001664 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
Mike Stump11289f42009-09-09 15:08:12 +00001666
Douglas Gregor882211c2010-04-28 22:16:22 +00001667 /// \brief Build a new builtin offsetof expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001671 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001672 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001673 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001674 unsigned NumComponents,
1675 SourceLocation RParenLoc) {
1676 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1677 NumComponents, RParenLoc);
1678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001679
1680 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001681 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001682 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001685 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1686 SourceLocation OpLoc,
1687 UnaryExprOrTypeTrait ExprKind,
1688 SourceRange R) {
1689 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 }
1691
Peter Collingbournee190dee2011-03-11 19:24:49 +00001692 /// \brief Build a new sizeof, alignof or vec step expression with an
1693 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001694 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001697 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1698 UnaryExprOrTypeTrait ExprKind,
1699 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001701 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001704
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001705 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001709 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001716 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001717 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 RBracketLoc);
1719 }
1720
1721 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001722 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001727 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001728 Expr *ExecConfig = nullptr) {
1729 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001730 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 }
1732
1733 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001734 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001737 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001738 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001739 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001740 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001741 const DeclarationNameInfo &MemberNameInfo,
1742 ValueDecl *Member,
1743 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001744 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001745 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001746 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1747 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001748 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001749 // We have a reference to an unnamed field. This is always the
1750 // base of an anonymous struct/union member access, i.e. the
1751 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001752 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001753 assert(Member->getType()->isRecordType() &&
1754 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001755
Richard Smithcab9a7d2011-10-26 19:06:56 +00001756 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001757 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001758 QualifierLoc.getNestedNameSpecifier(),
1759 FoundDecl, Member);
1760 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001761 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001762 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001763 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001764 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001765 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001766 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001767 cast<FieldDecl>(Member)->getType(),
1768 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001769 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001772 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001773 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001774
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001775 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001776 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001777
John McCall16df1e52010-03-30 21:47:33 +00001778 // FIXME: this involves duplicating earlier analysis in a lot of
1779 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001780 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001781 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001782 R.resolveKind();
1783
John McCallb268a282010-08-23 23:25:46 +00001784 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001785 SS, TemplateKWLoc,
1786 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001787 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001791 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001795 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001796 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001797 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001801 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001805 SourceLocation QuestionLoc,
1806 Expr *LHS,
1807 SourceLocation ColonLoc,
1808 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001809 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1810 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 }
1812
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001814 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001820 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001821 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001822 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001830 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001832 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001833 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001834 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 }
Mike Stump11289f42009-09-09 15:08:12 +00001836
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001838 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 SourceLocation OpLoc,
1843 SourceLocation AccessorLoc,
1844 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001845
John McCall10eae182009-11-30 22:42:35 +00001846 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001847 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001848 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001849 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001850 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001851 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001852 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001853 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001857 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001861 MultiExprArg Inits,
1862 SourceLocation RBraceLoc,
1863 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001865 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001866 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001867 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001868
Douglas Gregord3d93062009-11-09 17:16:50 +00001869 // Patch in the result type we were given, which may have been computed
1870 // when the initial InitListExpr was built.
1871 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1872 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001873 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001877 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 MultiExprArg ArrayExprs,
1882 SourceLocation EqualOrColonLoc,
1883 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001884 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001887 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001890
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001891 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
Mike Stump11289f42009-09-09 15:08:12 +00001893
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001895 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// By default, builds the implicit value initialization without performing
1897 /// any semantic analysis. Subclasses may override this routine to provide
1898 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001900 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 }
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001908 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001909 SourceLocation RParenLoc) {
1910 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001911 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001912 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
1915 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001920 MultiExprArg SubExprs,
1921 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001922 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001926 ///
1927 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// rather than attempting to map the label statement itself.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001931 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001932 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 }
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001936 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001940 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001942 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 }
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 /// \brief Build a new __builtin_choose_expr expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001950 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 SourceLocation RParenLoc) {
1952 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001953 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Peter Collingbourne91147592011-04-15 00:35:48 +00001957 /// \brief Build a new generic selection expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
1961 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1962 SourceLocation DefaultLoc,
1963 SourceLocation RParenLoc,
1964 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001965 ArrayRef<TypeSourceInfo *> Types,
1966 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001967 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001968 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001969 }
1970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new overloaded operator call expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// The semantic analysis provides the behavior of template instantiation,
1975 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001976 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// argument-dependent lookup, etc. Subclasses may override this routine to
1978 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001981 Expr *Callee,
1982 Expr *First,
1983 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001984
1985 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// reinterpret_cast.
1987 ///
1988 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001989 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 Stmt::StmtClass Class,
1993 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001994 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 SourceLocation RAngleLoc,
1996 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001997 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation RParenLoc) {
1999 switch (Class) {
2000 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002001 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002002 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002003 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004
2005 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002006 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002007 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002008 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002011 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002012 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002017 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002018 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002019 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002022 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 }
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 /// \brief Build a new C++ static_cast expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002032 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation RAngleLoc,
2034 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002035 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002037 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002038 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002039 SourceRange(LAngleLoc, RAngleLoc),
2040 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 }
2042
2043 /// \brief Build a new C++ dynamic_cast expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002047 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002049 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RAngleLoc,
2051 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002054 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002055 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002056 SourceRange(LAngleLoc, RAngleLoc),
2057 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new C++ reinterpret_cast expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002066 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RAngleLoc,
2068 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002071 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002072 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002073 SourceRange(LAngleLoc, RAngleLoc),
2074 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 }
2076
2077 /// \brief Build a new C++ const_cast expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002083 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 SourceLocation RAngleLoc,
2085 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002086 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002088 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002089 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002090 SourceRange(LAngleLoc, RAngleLoc),
2091 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 /// \brief Build a new C++ functional-style cast expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002098 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2099 SourceLocation LParenLoc,
2100 Expr *Sub,
2101 SourceLocation RParenLoc) {
2102 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002103 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 RParenLoc);
2105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 /// \brief Build a new C++ typeid(type) expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002112 SourceLocation TypeidLoc,
2113 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002115 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002116 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Francois Pichet9f4f2072010-09-08 12:20:18 +00002119
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 /// \brief Build a new C++ typeid(expr) expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002124 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002125 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002126 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002128 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002129 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002130 }
2131
Francois Pichet9f4f2072010-09-08 12:20:18 +00002132 /// \brief Build a new C++ __uuidof(type) expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
2136 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2137 SourceLocation TypeidLoc,
2138 TypeSourceInfo *Operand,
2139 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002140 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002141 RParenLoc);
2142 }
2143
2144 /// \brief Build a new C++ __uuidof(expr) expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
2148 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2149 SourceLocation TypeidLoc,
2150 Expr *Operand,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2153 RParenLoc);
2154 }
2155
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 /// \brief Build a new C++ "this" expression.
2157 ///
2158 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002159 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002162 QualType ThisType,
2163 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002164 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002165 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 }
2167
2168 /// \brief Build a new C++ throw expression.
2169 ///
2170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002172 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2173 bool IsThrownVariableInScope) {
2174 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 }
2176
2177 /// \brief Build a new C++ default-argument expression.
2178 ///
2179 /// By default, builds a new default-argument expression, which does not
2180 /// require any semantic analysis. Subclasses may override this routine to
2181 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002182 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002183 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002184 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
2186
Richard Smith852c9db2013-04-20 22:23:05 +00002187 /// \brief Build a new C++11 default-initialization expression.
2188 ///
2189 /// By default, builds a new default field initialization expression, which
2190 /// does not require any semantic analysis. Subclasses may override this
2191 /// routine to provide different behavior.
2192 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2193 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002194 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002195 }
2196
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 /// \brief Build a new C++ zero-initialization expression.
2198 ///
2199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002201 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2202 SourceLocation LParenLoc,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002205 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 }
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 /// \brief Build a new C++ "new" expression.
2209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002212 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002213 bool UseGlobal,
2214 SourceLocation PlacementLParen,
2215 MultiExprArg PlacementArgs,
2216 SourceLocation PlacementRParen,
2217 SourceRange TypeIdParens,
2218 QualType AllocatedType,
2219 TypeSourceInfo *AllocatedTypeInfo,
2220 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002221 SourceRange DirectInitRange,
2222 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002223 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002225 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002227 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002228 AllocatedType,
2229 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002230 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002231 DirectInitRange,
2232 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// \brief Build a new C++ "delete" expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 bool IsGlobalDelete,
2241 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002242 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002244 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregor29c42f22012-02-24 07:38:34 +00002247 /// \brief Build a new type trait expression.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildTypeTrait(TypeTrait Trait,
2252 SourceLocation StartLoc,
2253 ArrayRef<TypeSourceInfo *> Args,
2254 SourceLocation RParenLoc) {
2255 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002257
John Wiegley6242b6a2011-04-28 00:16:57 +00002258 /// \brief Build a new array type trait expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
2262 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2263 SourceLocation StartLoc,
2264 TypeSourceInfo *TSInfo,
2265 Expr *DimExpr,
2266 SourceLocation RParenLoc) {
2267 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2268 }
2269
John Wiegleyf9f65842011-04-25 06:54:41 +00002270 /// \brief Build a new expression trait expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
2274 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2275 SourceLocation StartLoc,
2276 Expr *Queried,
2277 SourceLocation RParenLoc) {
2278 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2279 }
2280
Mike Stump11289f42009-09-09 15:08:12 +00002281 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// expression.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002286 ExprResult RebuildDependentScopeDeclRefExpr(
2287 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002288 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002289 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002290 const TemplateArgumentListInfo *TemplateArgs,
2291 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002293 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002294
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002295 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002296 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002297 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002298
Richard Smithdb2630f2012-10-21 03:28:35 +00002299 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2300 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
2302
2303 /// \brief Build a new template-id expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002308 SourceLocation TemplateKWLoc,
2309 LookupResult &R,
2310 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002311 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002312 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2313 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 }
2315
2316 /// \brief Build a new object-construction expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002320 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002321 SourceLocation Loc,
2322 CXXConstructorDecl *Constructor,
2323 bool IsElidable,
2324 MultiExprArg Args,
2325 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002326 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002327 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002328 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002329 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002330 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002331 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002332 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002333 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002334
Douglas Gregordb121ba2009-12-14 16:27:04 +00002335 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002336 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002337 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002338 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002339 RequiresZeroInit, ConstructKind,
2340 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
2342
2343 /// \brief Build a new object-construction expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002347 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2348 SourceLocation LParenLoc,
2349 MultiExprArg Args,
2350 SourceLocation RParenLoc) {
2351 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002353 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 RParenLoc);
2355 }
2356
2357 /// \brief Build a new object-construction expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002361 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2362 SourceLocation LParenLoc,
2363 MultiExprArg Args,
2364 SourceLocation RParenLoc) {
2365 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002367 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 RParenLoc);
2369 }
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 /// \brief Build a new member reference expression.
2372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002375 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002376 QualType BaseType,
2377 bool IsArrow,
2378 SourceLocation OperatorLoc,
2379 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002380 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002381 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002382 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002383 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002385 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002386
John McCallb268a282010-08-23 23:25:46 +00002387 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002388 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002389 SS, TemplateKWLoc,
2390 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 MemberNameInfo,
2392 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 }
2394
John McCall10eae182009-11-30 22:42:35 +00002395 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002399 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2400 SourceLocation OperatorLoc,
2401 bool IsArrow,
2402 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002403 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002404 NamedDecl *FirstQualifierInScope,
2405 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002406 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002407 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002408 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002409
John McCallb268a282010-08-23 23:25:46 +00002410 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002411 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002412 SS, TemplateKWLoc,
2413 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002414 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002417 /// \brief Build a new noexcept expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
2421 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2422 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2423 }
2424
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002425 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002426 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2427 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002428 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002429 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002430 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002431 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2432 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002433 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002434
2435 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2436 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002437 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002438 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002439
Patrick Beard0caa3942012-04-19 00:25:12 +00002440 /// \brief Build a new Objective-C boxed expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
2444 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2445 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002447
Ted Kremeneke65b0862012-03-06 20:05:56 +00002448 /// \brief Build a new Objective-C array literal.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
2452 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2453 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002454 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002455 MultiExprArg(Elements, NumElements));
2456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002457
2458 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002459 Expr *Base, Expr *Key,
2460 ObjCMethodDecl *getterMethod,
2461 ObjCMethodDecl *setterMethod) {
2462 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2463 getterMethod, setterMethod);
2464 }
2465
2466 /// \brief Build a new Objective-C dictionary literal.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
2470 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2471 ObjCDictionaryElement *Elements,
2472 unsigned NumElements) {
2473 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002475
James Dennett2a4d13c2012-06-15 07:13:21 +00002476 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002481 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002482 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002483 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002484 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002488 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002489 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002490 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002491 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002492 MultiExprArg Args,
2493 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002494 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2495 ReceiverTypeInfo->getType(),
2496 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002497 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002498 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002499 }
2500
2501 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002502 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002503 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002504 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002505 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002506 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002507 MultiExprArg Args,
2508 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002509 return SemaRef.BuildInstanceMessage(Receiver,
2510 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002511 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002512 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002513 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002514 }
2515
Douglas Gregord51d90d2010-04-26 20:11:03 +00002516 /// \brief Build a new Objective-C ivar reference expression.
2517 ///
2518 /// By default, performs semantic analysis to build the new expression.
2519 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002520 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002521 SourceLocation IvarLoc,
2522 bool IsArrow, bool IsFreeIvar) {
2523 // FIXME: We lose track of the IsFreeIvar bit.
2524 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002525 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2526 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002527 /*FIXME:*/IvarLoc, IsArrow,
2528 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002529 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002530 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002531 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002532 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002533
2534 /// \brief Build a new Objective-C property reference expression.
2535 ///
2536 /// By default, performs semantic analysis to build the new expression.
2537 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002538 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002539 ObjCPropertyDecl *Property,
2540 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002541 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002542 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2543 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2544 /*FIXME:*/PropertyLoc,
2545 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002546 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002547 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002548 NameInfo,
2549 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002551
John McCallb7bd14f2010-12-02 01:19:52 +00002552 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002553 ///
2554 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002555 /// Subclasses may override this routine to provide different behavior.
2556 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2557 ObjCMethodDecl *Getter,
2558 ObjCMethodDecl *Setter,
2559 SourceLocation PropertyLoc) {
2560 // Since these expressions can only be value-dependent, we do not
2561 // need to perform semantic analysis again.
2562 return Owned(
2563 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2564 VK_LValue, OK_ObjCProperty,
2565 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002566 }
2567
Douglas Gregord51d90d2010-04-26 20:11:03 +00002568 /// \brief Build a new Objective-C "isa" expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002572 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002573 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002574 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002575 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2576 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002577 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002578 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002579 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002580 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002581 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002583
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 /// \brief Build a new shuffle vector expression.
2585 ///
2586 /// By default, performs semantic analysis to build the new expression.
2587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002588 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002589 MultiExprArg SubExprs,
2590 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002592 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002593 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2594 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2595 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002596 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002599 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002600 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2601 SemaRef.Context.BuiltinFnTy,
2602 VK_RValue, BuiltinLoc);
2603 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2604 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002605 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002606
2607 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002608 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002609 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002610 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002611
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002613 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 }
John McCall31f82722010-11-12 08:19:04 +00002615
Hal Finkelc4d7c822013-09-18 03:29:45 +00002616 /// \brief Build a new convert vector expression.
2617 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2618 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2619 SourceLocation RParenLoc) {
2620 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2621 BuiltinLoc, RParenLoc);
2622 }
2623
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002624 /// \brief Build a new template argument pack expansion.
2625 ///
2626 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002627 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002628 /// different behavior.
2629 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002630 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002631 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002632 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002633 case TemplateArgument::Expression: {
2634 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002635 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2636 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002637 if (Result.isInvalid())
2638 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002639
Douglas Gregor98318c22011-01-03 21:37:45 +00002640 return TemplateArgumentLoc(Result.get(), Result.get());
2641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002642
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002643 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002644 return TemplateArgumentLoc(TemplateArgument(
2645 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002646 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002647 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002648 Pattern.getTemplateNameLoc(),
2649 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002650
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002651 case TemplateArgument::Null:
2652 case TemplateArgument::Integral:
2653 case TemplateArgument::Declaration:
2654 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002655 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002656 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002657 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002659 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002660 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002661 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002662 EllipsisLoc,
2663 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002664 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2665 Expansion);
2666 break;
2667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002668
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002669 return TemplateArgumentLoc();
2670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002671
Douglas Gregor968f23a2011-01-03 19:31:53 +00002672 /// \brief Build a new expression pack expansion.
2673 ///
2674 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002675 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002676 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002677 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002678 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002679 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002680 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002681
2682 /// \brief Build a new atomic operation expression.
2683 ///
2684 /// By default, performs semantic analysis to build the new expression.
2685 /// Subclasses may override this routine to provide different behavior.
2686 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2687 MultiExprArg SubExprs,
2688 QualType RetTy,
2689 AtomicExpr::AtomicOp Op,
2690 SourceLocation RParenLoc) {
2691 // Just create the expression; there is not any interesting semantic
2692 // analysis here because we can't actually build an AtomicExpr until
2693 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002694 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002695 RParenLoc);
2696 }
2697
John McCall31f82722010-11-12 08:19:04 +00002698private:
Douglas Gregor14454802011-02-25 02:25:35 +00002699 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2700 QualType ObjectType,
2701 NamedDecl *FirstQualifierInScope,
2702 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002703
2704 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2705 QualType ObjectType,
2706 NamedDecl *FirstQualifierInScope,
2707 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002708
2709 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2710 NamedDecl *FirstQualifierInScope,
2711 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002712};
Douglas Gregora16548e2009-08-11 05:31:07 +00002713
Douglas Gregorebe10102009-08-20 07:17:43 +00002714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002715StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002716 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002717 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002718
Douglas Gregorebe10102009-08-20 07:17:43 +00002719 switch (S->getStmtClass()) {
2720 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregorebe10102009-08-20 07:17:43 +00002722 // Transform individual statement nodes
2723#define STMT(Node, Parent) \
2724 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002725#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002726#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002727#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002728
Douglas Gregorebe10102009-08-20 07:17:43 +00002729 // Transform expressions by calling TransformExpr.
2730#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002731#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002732#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002733#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002734 {
John McCalldadc5752010-08-24 06:29:42 +00002735 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002736 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002737 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002738
Richard Smith945f8d32013-01-14 22:39:08 +00002739 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002740 }
Mike Stump11289f42009-09-09 15:08:12 +00002741 }
2742
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002743 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002744}
Mike Stump11289f42009-09-09 15:08:12 +00002745
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002746template<typename Derived>
2747OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2748 if (!S)
2749 return S;
2750
2751 switch (S->getClauseKind()) {
2752 default: break;
2753 // Transform individual clause nodes
2754#define OPENMP_CLAUSE(Name, Class) \
2755 case OMPC_ ## Name : \
2756 return getDerived().Transform ## Class(cast<Class>(S));
2757#include "clang/Basic/OpenMPKinds.def"
2758 }
2759
2760 return S;
2761}
2762
Mike Stump11289f42009-09-09 15:08:12 +00002763
Douglas Gregore922c772009-08-04 22:27:00 +00002764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002765ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002766 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002767 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002768
2769 switch (E->getStmtClass()) {
2770 case Stmt::NoStmtClass: break;
2771#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002772#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002773#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002774 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002775#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002776 }
2777
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002778 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002779}
2780
2781template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002782ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2783 bool CXXDirectInit) {
2784 // Initializers are instantiated like expressions, except that various outer
2785 // layers are stripped.
2786 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002787 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002788
2789 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2790 Init = ExprTemp->getSubExpr();
2791
Richard Smithe6ca4752013-05-30 22:40:16 +00002792 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2793 Init = MTE->GetTemporaryExpr();
2794
Richard Smithd59b8322012-12-19 01:39:02 +00002795 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2796 Init = Binder->getSubExpr();
2797
2798 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2799 Init = ICE->getSubExprAsWritten();
2800
Richard Smithcc1b96d2013-06-12 22:31:48 +00002801 if (CXXStdInitializerListExpr *ILE =
2802 dyn_cast<CXXStdInitializerListExpr>(Init))
2803 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2804
Richard Smith38a549b2012-12-21 08:13:35 +00002805 // If this is not a direct-initializer, we only need to reconstruct
2806 // InitListExprs. Other forms of copy-initialization will be a no-op if
2807 // the initializer is already the right type.
2808 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2809 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2810 return getDerived().TransformExpr(Init);
2811
2812 // Revert value-initialization back to empty parens.
2813 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2814 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002815 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002816 Parens.getEnd());
2817 }
2818
2819 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2820 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002821 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002822 SourceLocation());
2823
2824 // Revert initialization by constructor back to a parenthesized or braced list
2825 // of expressions. Any other form of initializer can just be reused directly.
2826 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002827 return getDerived().TransformExpr(Init);
2828
2829 SmallVector<Expr*, 8> NewArgs;
2830 bool ArgChanged = false;
2831 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2832 /*IsCall*/true, NewArgs, &ArgChanged))
2833 return ExprError();
2834
2835 // If this was list initialization, revert to list form.
2836 if (Construct->isListInitialization())
2837 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2838 Construct->getLocEnd(),
2839 Construct->getType());
2840
Richard Smithd59b8322012-12-19 01:39:02 +00002841 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002842 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002843 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2844 Parens.getEnd());
2845}
2846
2847template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002848bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2849 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002850 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002851 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002852 bool *ArgChanged) {
2853 for (unsigned I = 0; I != NumInputs; ++I) {
2854 // If requested, drop call arguments that need to be dropped.
2855 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2856 if (ArgChanged)
2857 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
Douglas Gregora3efea12011-01-03 19:04:46 +00002859 break;
2860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002861
Douglas Gregor968f23a2011-01-03 19:31:53 +00002862 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2863 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002864
Chris Lattner01cf8db2011-07-20 06:58:45 +00002865 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2867 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Douglas Gregor968f23a2011-01-03 19:31:53 +00002869 // Determine whether the set of unexpanded parameter packs can and should
2870 // be expanded.
2871 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002872 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002873 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2874 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2876 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002877 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002878 Expand, RetainExpansion,
2879 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002880 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
Douglas Gregor968f23a2011-01-03 19:31:53 +00002882 if (!Expand) {
2883 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002884 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002885 // expansion.
2886 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2887 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2888 if (OutPattern.isInvalid())
2889 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
2891 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002892 Expansion->getEllipsisLoc(),
2893 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002894 if (Out.isInvalid())
2895 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002896
Douglas Gregor968f23a2011-01-03 19:31:53 +00002897 if (ArgChanged)
2898 *ArgChanged = true;
2899 Outputs.push_back(Out.get());
2900 continue;
2901 }
John McCall542e7c62011-07-06 07:30:07 +00002902
2903 // Record right away that the argument was changed. This needs
2904 // to happen even if the array expands to nothing.
2905 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002906
Douglas Gregor968f23a2011-01-03 19:31:53 +00002907 // The transform has determined that we should perform an elementwise
2908 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002909 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2911 ExprResult Out = getDerived().TransformExpr(Pattern);
2912 if (Out.isInvalid())
2913 return true;
2914
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002915 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002916 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2917 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002918 if (Out.isInvalid())
2919 return true;
2920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
Douglas Gregor968f23a2011-01-03 19:31:53 +00002922 Outputs.push_back(Out.get());
2923 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregor968f23a2011-01-03 19:31:53 +00002925 continue;
2926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002927
Richard Smithd59b8322012-12-19 01:39:02 +00002928 ExprResult Result =
2929 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2930 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002931 if (Result.isInvalid())
2932 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregora3efea12011-01-03 19:04:46 +00002934 if (Result.get() != Inputs[I] && ArgChanged)
2935 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
2937 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
Douglas Gregora3efea12011-01-03 19:04:46 +00002940 return false;
2941}
2942
2943template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002944NestedNameSpecifierLoc
2945TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2946 NestedNameSpecifierLoc NNS,
2947 QualType ObjectType,
2948 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002949 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002950 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002951 Qualifier = Qualifier.getPrefix())
2952 Qualifiers.push_back(Qualifier);
2953
2954 CXXScopeSpec SS;
2955 while (!Qualifiers.empty()) {
2956 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2957 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregor14454802011-02-25 02:25:35 +00002959 switch (QNNS->getKind()) {
2960 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002961 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002962 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002963 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002964 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002965 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002966 FirstQualifierInScope, false))
2967 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
Douglas Gregor14454802011-02-25 02:25:35 +00002969 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002970
Douglas Gregor14454802011-02-25 02:25:35 +00002971 case NestedNameSpecifier::Namespace: {
2972 NamespaceDecl *NS
2973 = cast_or_null<NamespaceDecl>(
2974 getDerived().TransformDecl(
2975 Q.getLocalBeginLoc(),
2976 QNNS->getAsNamespace()));
2977 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2978 break;
2979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002980
Douglas Gregor14454802011-02-25 02:25:35 +00002981 case NestedNameSpecifier::NamespaceAlias: {
2982 NamespaceAliasDecl *Alias
2983 = cast_or_null<NamespaceAliasDecl>(
2984 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2985 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002986 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002987 Q.getLocalEndLoc());
2988 break;
2989 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002990
Douglas Gregor14454802011-02-25 02:25:35 +00002991 case NestedNameSpecifier::Global:
2992 // There is no meaningful transformation that one could perform on the
2993 // global scope.
2994 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2995 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002996
Douglas Gregor14454802011-02-25 02:25:35 +00002997 case NestedNameSpecifier::TypeSpecWithTemplate:
2998 case NestedNameSpecifier::TypeSpec: {
2999 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3000 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003001
Douglas Gregor14454802011-02-25 02:25:35 +00003002 if (!TL)
3003 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Douglas Gregor14454802011-02-25 02:25:35 +00003005 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003006 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003007 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003008 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003009 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003010 if (TL.getType()->isEnumeralType())
3011 SemaRef.Diag(TL.getBeginLoc(),
3012 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003013 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3014 Q.getLocalEndLoc());
3015 break;
3016 }
Richard Trieude756fb2011-05-07 01:36:37 +00003017 // If the nested-name-specifier is an invalid type def, don't emit an
3018 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003019 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3020 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003021 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003022 << TL.getType() << SS.getRange();
3023 }
Douglas Gregor14454802011-02-25 02:25:35 +00003024 return NestedNameSpecifierLoc();
3025 }
Douglas Gregore16af532011-02-28 18:50:33 +00003026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003027
Douglas Gregore16af532011-02-28 18:50:33 +00003028 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003029 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003030 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003032
Douglas Gregor14454802011-02-25 02:25:35 +00003033 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003034 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003035 !getDerived().AlwaysRebuild())
3036 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003037
3038 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003039 // nested-name-specifier, do so.
3040 if (SS.location_size() == NNS.getDataLength() &&
3041 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3042 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3043
3044 // Allocate new nested-name-specifier location information.
3045 return SS.getWithLocInContext(SemaRef.Context);
3046}
3047
3048template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003049DeclarationNameInfo
3050TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003051::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003052 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003053 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003054 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003055
3056 switch (Name.getNameKind()) {
3057 case DeclarationName::Identifier:
3058 case DeclarationName::ObjCZeroArgSelector:
3059 case DeclarationName::ObjCOneArgSelector:
3060 case DeclarationName::ObjCMultiArgSelector:
3061 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003062 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003063 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003064 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003065
Douglas Gregorf816bd72009-09-03 22:13:48 +00003066 case DeclarationName::CXXConstructorName:
3067 case DeclarationName::CXXDestructorName:
3068 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003069 TypeSourceInfo *NewTInfo;
3070 CanQualType NewCanTy;
3071 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003072 NewTInfo = getDerived().TransformType(OldTInfo);
3073 if (!NewTInfo)
3074 return DeclarationNameInfo();
3075 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003076 }
3077 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003078 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003079 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003080 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003081 if (NewT.isNull())
3082 return DeclarationNameInfo();
3083 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003086 DeclarationName NewName
3087 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3088 NewCanTy);
3089 DeclarationNameInfo NewNameInfo(NameInfo);
3090 NewNameInfo.setName(NewName);
3091 NewNameInfo.setNamedTypeInfo(NewTInfo);
3092 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003093 }
Mike Stump11289f42009-09-09 15:08:12 +00003094 }
3095
David Blaikie83d382b2011-09-23 05:06:16 +00003096 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003097}
3098
3099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003100TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003101TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3102 TemplateName Name,
3103 SourceLocation NameLoc,
3104 QualType ObjectType,
3105 NamedDecl *FirstQualifierInScope) {
3106 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3107 TemplateDecl *Template = QTN->getTemplateDecl();
3108 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Douglas Gregor9db53502011-03-02 18:07:45 +00003110 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003111 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003112 Template));
3113 if (!TransTemplate)
3114 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor9db53502011-03-02 18:07:45 +00003116 if (!getDerived().AlwaysRebuild() &&
3117 SS.getScopeRep() == QTN->getQualifier() &&
3118 TransTemplate == Template)
3119 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003120
Douglas Gregor9db53502011-03-02 18:07:45 +00003121 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3122 TransTemplate);
3123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor9db53502011-03-02 18:07:45 +00003125 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3126 if (SS.getScopeRep()) {
3127 // These apply to the scope specifier, not the template.
3128 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003129 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003130 }
3131
Douglas Gregor9db53502011-03-02 18:07:45 +00003132 if (!getDerived().AlwaysRebuild() &&
3133 SS.getScopeRep() == DTN->getQualifier() &&
3134 ObjectType.isNull())
3135 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregor9db53502011-03-02 18:07:45 +00003137 if (DTN->isIdentifier()) {
3138 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003139 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003140 NameLoc,
3141 ObjectType,
3142 FirstQualifierInScope);
3143 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Douglas Gregor9db53502011-03-02 18:07:45 +00003145 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3146 ObjectType);
3147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003148
Douglas Gregor9db53502011-03-02 18:07:45 +00003149 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3150 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003151 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003152 Template));
3153 if (!TransTemplate)
3154 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003155
Douglas Gregor9db53502011-03-02 18:07:45 +00003156 if (!getDerived().AlwaysRebuild() &&
3157 TransTemplate == Template)
3158 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003159
Douglas Gregor9db53502011-03-02 18:07:45 +00003160 return TemplateName(TransTemplate);
3161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor9db53502011-03-02 18:07:45 +00003163 if (SubstTemplateTemplateParmPackStorage *SubstPack
3164 = Name.getAsSubstTemplateTemplateParmPack()) {
3165 TemplateTemplateParmDecl *TransParam
3166 = cast_or_null<TemplateTemplateParmDecl>(
3167 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3168 if (!TransParam)
3169 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003170
Douglas Gregor9db53502011-03-02 18:07:45 +00003171 if (!getDerived().AlwaysRebuild() &&
3172 TransParam == SubstPack->getParameterPack())
3173 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003174
3175 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003176 SubstPack->getArgumentPack());
3177 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Douglas Gregor9db53502011-03-02 18:07:45 +00003179 // These should be getting filtered out before they reach the AST.
3180 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003181}
3182
3183template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003184void TreeTransform<Derived>::InventTemplateArgumentLoc(
3185 const TemplateArgument &Arg,
3186 TemplateArgumentLoc &Output) {
3187 SourceLocation Loc = getDerived().getBaseLocation();
3188 switch (Arg.getKind()) {
3189 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003190 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003191 break;
3192
3193 case TemplateArgument::Type:
3194 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003195 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003196
John McCall0ad16662009-10-29 08:12:44 +00003197 break;
3198
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003199 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003200 case TemplateArgument::TemplateExpansion: {
3201 NestedNameSpecifierLocBuilder Builder;
3202 TemplateName Template = Arg.getAsTemplate();
3203 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3204 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3205 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3206 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor9d802122011-03-02 17:09:35 +00003208 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003209 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003210 Builder.getWithLocInContext(SemaRef.Context),
3211 Loc);
3212 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003213 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003214 Builder.getWithLocInContext(SemaRef.Context),
3215 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003216
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003217 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003218 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003219
John McCall0ad16662009-10-29 08:12:44 +00003220 case TemplateArgument::Expression:
3221 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3222 break;
3223
3224 case TemplateArgument::Declaration:
3225 case TemplateArgument::Integral:
3226 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003227 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003228 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003229 break;
3230 }
3231}
3232
3233template<typename Derived>
3234bool TreeTransform<Derived>::TransformTemplateArgument(
3235 const TemplateArgumentLoc &Input,
3236 TemplateArgumentLoc &Output) {
3237 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003238 switch (Arg.getKind()) {
3239 case TemplateArgument::Null:
3240 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003241 case TemplateArgument::Pack:
3242 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003243 case TemplateArgument::NullPtr:
3244 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003245
Douglas Gregore922c772009-08-04 22:27:00 +00003246 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003247 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003248 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003249 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003250
3251 DI = getDerived().TransformType(DI);
3252 if (!DI) return true;
3253
3254 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3255 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003256 }
Mike Stump11289f42009-09-09 15:08:12 +00003257
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003258 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003259 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3260 if (QualifierLoc) {
3261 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3262 if (!QualifierLoc)
3263 return true;
3264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregordf846d12011-03-02 18:46:51 +00003266 CXXScopeSpec SS;
3267 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003268 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003269 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3270 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003271 if (Template.isNull())
3272 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregor9d802122011-03-02 17:09:35 +00003274 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003275 Input.getTemplateNameLoc());
3276 return false;
3277 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003278
3279 case TemplateArgument::TemplateExpansion:
3280 llvm_unreachable("Caller should expand pack expansions");
3281
Douglas Gregore922c772009-08-04 22:27:00 +00003282 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003283 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003284 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003285 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003286
John McCall0ad16662009-10-29 08:12:44 +00003287 Expr *InputExpr = Input.getSourceExpression();
3288 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3289
Chris Lattnercdb591a2011-04-25 20:37:58 +00003290 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003291 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003292 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003293 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003294 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003295 }
Douglas Gregore922c772009-08-04 22:27:00 +00003296 }
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregore922c772009-08-04 22:27:00 +00003298 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003299 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003300}
3301
Douglas Gregorfe921a72010-12-20 23:36:19 +00003302/// \brief Iterator adaptor that invents template argument location information
3303/// for each of the template arguments in its underlying iterator.
3304template<typename Derived, typename InputIterator>
3305class TemplateArgumentLocInventIterator {
3306 TreeTransform<Derived> &Self;
3307 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregorfe921a72010-12-20 23:36:19 +00003309public:
3310 typedef TemplateArgumentLoc value_type;
3311 typedef TemplateArgumentLoc reference;
3312 typedef typename std::iterator_traits<InputIterator>::difference_type
3313 difference_type;
3314 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316 class pointer {
3317 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003318
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319 public:
3320 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregorfe921a72010-12-20 23:36:19 +00003322 const TemplateArgumentLoc *operator->() const { return &Arg; }
3323 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregorfe921a72010-12-20 23:36:19 +00003325 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregorfe921a72010-12-20 23:36:19 +00003327 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3328 InputIterator Iter)
3329 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregorfe921a72010-12-20 23:36:19 +00003331 TemplateArgumentLocInventIterator &operator++() {
3332 ++Iter;
3333 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003334 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 TemplateArgumentLocInventIterator operator++(int) {
3337 TemplateArgumentLocInventIterator Old(*this);
3338 ++(*this);
3339 return Old;
3340 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Douglas Gregorfe921a72010-12-20 23:36:19 +00003342 reference operator*() const {
3343 TemplateArgumentLoc Result;
3344 Self.InventTemplateArgumentLoc(*Iter, Result);
3345 return Result;
3346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003347
Douglas Gregorfe921a72010-12-20 23:36:19 +00003348 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregorfe921a72010-12-20 23:36:19 +00003350 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3351 const TemplateArgumentLocInventIterator &Y) {
3352 return X.Iter == Y.Iter;
3353 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003354
Douglas Gregorfe921a72010-12-20 23:36:19 +00003355 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3356 const TemplateArgumentLocInventIterator &Y) {
3357 return X.Iter != Y.Iter;
3358 }
3359};
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor42cafa82010-12-20 17:42:22 +00003361template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003362template<typename InputIterator>
3363bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3364 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003365 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003366 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003367 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003368 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003370 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3371 // Unpack argument packs, which we translate them into separate
3372 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003373 // FIXME: We could do much better if we could guarantee that the
3374 // TemplateArgumentLocInfo for the pack expansion would be usable for
3375 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003376 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003377 TemplateArgument::pack_iterator>
3378 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003379 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003380 In.getArgument().pack_begin()),
3381 PackLocIterator(*this,
3382 In.getArgument().pack_end()),
3383 Outputs))
3384 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003386 continue;
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 if (In.getArgument().isPackExpansion()) {
3390 // We have a pack expansion, for which we will be substituting into
3391 // the pattern.
3392 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003393 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003394 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003395 = getSema().getTemplateArgumentPackExpansionPattern(
3396 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Chris Lattner01cf8db2011-07-20 06:58:45 +00003398 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003399 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3400 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003401
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003402 // Determine whether the set of unexpanded parameter packs can and should
3403 // be expanded.
3404 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003405 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003406 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003407 if (getDerived().TryExpandParameterPacks(Ellipsis,
3408 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003409 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003410 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003411 RetainExpansion,
3412 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003413 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003415 if (!Expand) {
3416 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003417 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003418 // expansion.
3419 TemplateArgumentLoc OutPattern;
3420 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3421 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3422 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003424 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3425 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003426 if (Out.getArgument().isNull())
3427 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003429 Outputs.addArgument(Out);
3430 continue;
3431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003433 // The transform has determined that we should perform an elementwise
3434 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003435 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003436 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3437
3438 if (getDerived().TransformTemplateArgument(Pattern, Out))
3439 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003441 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003442 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3443 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003444 if (Out.getArgument().isNull())
3445 return true;
3446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003448 Outputs.addArgument(Out);
3449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregor48d24112011-01-10 20:53:55 +00003451 // If we're supposed to retain a pack expansion, do so by temporarily
3452 // forgetting the partially-substituted parameter pack.
3453 if (RetainExpansion) {
3454 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregor48d24112011-01-10 20:53:55 +00003456 if (getDerived().TransformTemplateArgument(Pattern, Out))
3457 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003458
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003459 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3460 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003461 if (Out.getArgument().isNull())
3462 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor48d24112011-01-10 20:53:55 +00003464 Outputs.addArgument(Out);
3465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003467 continue;
3468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
3470 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003471 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003472 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregor42cafa82010-12-20 17:42:22 +00003474 Outputs.addArgument(Out);
3475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
Douglas Gregor42cafa82010-12-20 17:42:22 +00003477 return false;
3478
3479}
3480
Douglas Gregord6ff3322009-08-04 16:50:30 +00003481//===----------------------------------------------------------------------===//
3482// Type transformation
3483//===----------------------------------------------------------------------===//
3484
3485template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003486QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003487 if (getDerived().AlreadyTransformed(T))
3488 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003489
John McCall550e0c22009-10-21 00:40:46 +00003490 // Temporary workaround. All of these transformations should
3491 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003492 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3493 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
John McCall31f82722010-11-12 08:19:04 +00003495 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 if (!NewDI)
3498 return QualType();
3499
3500 return NewDI->getType();
3501}
3502
3503template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003504TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003505 // Refine the base location to the type's location.
3506 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3507 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003508 if (getDerived().AlreadyTransformed(DI->getType()))
3509 return DI;
3510
3511 TypeLocBuilder TLB;
3512
3513 TypeLoc TL = DI->getTypeLoc();
3514 TLB.reserve(TL.getFullDataSize());
3515
John McCall31f82722010-11-12 08:19:04 +00003516 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003517 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003518 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003519
John McCallbcd03502009-12-07 02:54:59 +00003520 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003521}
3522
3523template<typename Derived>
3524QualType
John McCall31f82722010-11-12 08:19:04 +00003525TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003526 switch (T.getTypeLocClass()) {
3527#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003528#define TYPELOC(CLASS, PARENT) \
3529 case TypeLoc::CLASS: \
3530 return getDerived().Transform##CLASS##Type(TLB, \
3531 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003532#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003533 }
Mike Stump11289f42009-09-09 15:08:12 +00003534
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003535 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003536}
3537
3538/// FIXME: By default, this routine adds type qualifiers only to types
3539/// that can have qualifiers, and silently suppresses those qualifiers
3540/// that are not permitted (e.g., qualifiers on reference or function
3541/// types). This is the right thing for template instantiation, but
3542/// probably not for other clients.
3543template<typename Derived>
3544QualType
3545TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003546 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003547 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003548
John McCall31f82722010-11-12 08:19:04 +00003549 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003550 if (Result.isNull())
3551 return QualType();
3552
3553 // Silently suppress qualifiers if the result type can't be qualified.
3554 // FIXME: this is the right thing for template instantiation, but
3555 // probably not for other clients.
3556 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003557 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003558
John McCall31168b02011-06-15 23:02:42 +00003559 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003560 // resulting type.
3561 if (Quals.hasObjCLifetime()) {
3562 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3563 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003564 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003565 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003566 // A lifetime qualifier applied to a substituted template parameter
3567 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003568 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003569 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003570 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3571 QualType Replacement = SubstTypeParam->getReplacementType();
3572 Qualifiers Qs = Replacement.getQualifiers();
3573 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003574 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003575 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3576 Qs);
3577 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003578 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003579 Replacement);
3580 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003581 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3582 // 'auto' types behave the same way as template parameters.
3583 QualType Deduced = AutoTy->getDeducedType();
3584 Qualifiers Qs = Deduced.getQualifiers();
3585 Qs.removeObjCLifetime();
3586 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3587 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003588 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3589 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003590 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003591 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003592 // Otherwise, complain about the addition of a qualifier to an
3593 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003594 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003595 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003596 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
Douglas Gregore46db902011-06-17 22:11:49 +00003598 Quals.removeObjCLifetime();
3599 }
3600 }
3601 }
John McCallcb0f89a2010-06-05 06:41:15 +00003602 if (!Quals.empty()) {
3603 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003604 // BuildQualifiedType might not add qualifiers if they are invalid.
3605 if (Result.hasLocalQualifiers())
3606 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003607 // No location information to preserve.
3608 }
John McCall550e0c22009-10-21 00:40:46 +00003609
3610 return Result;
3611}
3612
Douglas Gregor14454802011-02-25 02:25:35 +00003613template<typename Derived>
3614TypeLoc
3615TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3616 QualType ObjectType,
3617 NamedDecl *UnqualLookup,
3618 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003619 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003620 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003622 TypeSourceInfo *TSI =
3623 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3624 if (TSI)
3625 return TSI->getTypeLoc();
3626 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003627}
3628
Douglas Gregor579c15f2011-03-02 18:32:08 +00003629template<typename Derived>
3630TypeSourceInfo *
3631TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3632 QualType ObjectType,
3633 NamedDecl *UnqualLookup,
3634 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003635 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003636 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003638 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3639 UnqualLookup, SS);
3640}
3641
3642template <typename Derived>
3643TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3644 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3645 CXXScopeSpec &SS) {
3646 QualType T = TL.getType();
3647 assert(!getDerived().AlreadyTransformed(T));
3648
Douglas Gregor579c15f2011-03-02 18:32:08 +00003649 TypeLocBuilder TLB;
3650 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
Douglas Gregor579c15f2011-03-02 18:32:08 +00003652 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003653 TemplateSpecializationTypeLoc SpecTL =
3654 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003655
Douglas Gregor579c15f2011-03-02 18:32:08 +00003656 TemplateName Template
3657 = getDerived().TransformTemplateName(SS,
3658 SpecTL.getTypePtr()->getTemplateName(),
3659 SpecTL.getTemplateNameLoc(),
3660 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003661 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003662 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
3664 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003665 Template);
3666 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003667 DependentTemplateSpecializationTypeLoc SpecTL =
3668 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor579c15f2011-03-02 18:32:08 +00003670 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003671 = getDerived().RebuildTemplateName(SS,
3672 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003673 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003674 ObjectType, UnqualLookup);
3675 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003676 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
3678 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003680 Template,
3681 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003682 } else {
3683 // Nothing special needs to be done for these.
3684 Result = getDerived().TransformType(TLB, TL);
3685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003686
3687 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003688 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
Douglas Gregor579c15f2011-03-02 18:32:08 +00003690 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3691}
3692
John McCall550e0c22009-10-21 00:40:46 +00003693template <class TyLoc> static inline
3694QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3695 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3696 NewT.setNameLoc(T.getNameLoc());
3697 return T.getType();
3698}
3699
John McCall550e0c22009-10-21 00:40:46 +00003700template<typename Derived>
3701QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003702 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003703 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3704 NewT.setBuiltinLoc(T.getBuiltinLoc());
3705 if (T.needsExtraLocalData())
3706 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3707 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003708}
Mike Stump11289f42009-09-09 15:08:12 +00003709
Douglas Gregord6ff3322009-08-04 16:50:30 +00003710template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003711QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003712 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003713 // FIXME: recurse?
3714 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003715}
Mike Stump11289f42009-09-09 15:08:12 +00003716
Reid Kleckner0503a872013-12-05 01:23:43 +00003717template <typename Derived>
3718QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3719 AdjustedTypeLoc TL) {
3720 // Adjustments applied during transformation are handled elsewhere.
3721 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3722}
3723
Douglas Gregord6ff3322009-08-04 16:50:30 +00003724template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003725QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3726 DecayedTypeLoc TL) {
3727 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3728 if (OriginalType.isNull())
3729 return QualType();
3730
3731 QualType Result = TL.getType();
3732 if (getDerived().AlwaysRebuild() ||
3733 OriginalType != TL.getOriginalLoc().getType())
3734 Result = SemaRef.Context.getDecayedType(OriginalType);
3735 TLB.push<DecayedTypeLoc>(Result);
3736 // Nothing to set for DecayedTypeLoc.
3737 return Result;
3738}
3739
3740template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003741QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003742 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003743 QualType PointeeType
3744 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003745 if (PointeeType.isNull())
3746 return QualType();
3747
3748 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003749 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003750 // A dependent pointer type 'T *' has is being transformed such
3751 // that an Objective-C class type is being replaced for 'T'. The
3752 // resulting pointer type is an ObjCObjectPointerType, not a
3753 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003754 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
John McCall8b07ec22010-05-15 11:32:37 +00003756 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3757 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003758 return Result;
3759 }
John McCall31f82722010-11-12 08:19:04 +00003760
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003761 if (getDerived().AlwaysRebuild() ||
3762 PointeeType != TL.getPointeeLoc().getType()) {
3763 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3764 if (Result.isNull())
3765 return QualType();
3766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003767
John McCall31168b02011-06-15 23:02:42 +00003768 // Objective-C ARC can add lifetime qualifiers to the type that we're
3769 // pointing to.
3770 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003771
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003772 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3773 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003774 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003775}
Mike Stump11289f42009-09-09 15:08:12 +00003776
3777template<typename Derived>
3778QualType
John McCall550e0c22009-10-21 00:40:46 +00003779TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003780 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003781 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003782 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3783 if (PointeeType.isNull())
3784 return QualType();
3785
3786 QualType Result = TL.getType();
3787 if (getDerived().AlwaysRebuild() ||
3788 PointeeType != TL.getPointeeLoc().getType()) {
3789 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003790 TL.getSigilLoc());
3791 if (Result.isNull())
3792 return QualType();
3793 }
3794
Douglas Gregor049211a2010-04-22 16:50:51 +00003795 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003796 NewT.setSigilLoc(TL.getSigilLoc());
3797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003798}
3799
John McCall70dd5f62009-10-30 00:06:24 +00003800/// Transforms a reference type. Note that somewhat paradoxically we
3801/// don't care whether the type itself is an l-value type or an r-value
3802/// type; we only care if the type was *written* as an l-value type
3803/// or an r-value type.
3804template<typename Derived>
3805QualType
3806TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003807 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003808 const ReferenceType *T = TL.getTypePtr();
3809
3810 // Note that this works with the pointee-as-written.
3811 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3812 if (PointeeType.isNull())
3813 return QualType();
3814
3815 QualType Result = TL.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 PointeeType != T->getPointeeTypeAsWritten()) {
3818 Result = getDerived().RebuildReferenceType(PointeeType,
3819 T->isSpelledAsLValue(),
3820 TL.getSigilLoc());
3821 if (Result.isNull())
3822 return QualType();
3823 }
3824
John McCall31168b02011-06-15 23:02:42 +00003825 // Objective-C ARC can add lifetime qualifiers to the type that we're
3826 // referring to.
3827 TLB.TypeWasModifiedSafely(
3828 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3829
John McCall70dd5f62009-10-30 00:06:24 +00003830 // r-value references can be rebuilt as l-value references.
3831 ReferenceTypeLoc NewTL;
3832 if (isa<LValueReferenceType>(Result))
3833 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3834 else
3835 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3836 NewTL.setSigilLoc(TL.getSigilLoc());
3837
3838 return Result;
3839}
3840
Mike Stump11289f42009-09-09 15:08:12 +00003841template<typename Derived>
3842QualType
John McCall550e0c22009-10-21 00:40:46 +00003843TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003844 LValueReferenceTypeLoc TL) {
3845 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003846}
3847
Mike Stump11289f42009-09-09 15:08:12 +00003848template<typename Derived>
3849QualType
John McCall550e0c22009-10-21 00:40:46 +00003850TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003851 RValueReferenceTypeLoc TL) {
3852 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003853}
Mike Stump11289f42009-09-09 15:08:12 +00003854
Douglas Gregord6ff3322009-08-04 16:50:30 +00003855template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003856QualType
John McCall550e0c22009-10-21 00:40:46 +00003857TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003858 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003859 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003860 if (PointeeType.isNull())
3861 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003862
Abramo Bagnara509357842011-03-05 14:42:21 +00003863 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003864 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003865 if (OldClsTInfo) {
3866 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3867 if (!NewClsTInfo)
3868 return QualType();
3869 }
3870
3871 const MemberPointerType *T = TL.getTypePtr();
3872 QualType OldClsType = QualType(T->getClass(), 0);
3873 QualType NewClsType;
3874 if (NewClsTInfo)
3875 NewClsType = NewClsTInfo->getType();
3876 else {
3877 NewClsType = getDerived().TransformType(OldClsType);
3878 if (NewClsType.isNull())
3879 return QualType();
3880 }
Mike Stump11289f42009-09-09 15:08:12 +00003881
John McCall550e0c22009-10-21 00:40:46 +00003882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003885 NewClsType != OldClsType) {
3886 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003887 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003888 if (Result.isNull())
3889 return QualType();
3890 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003891
Reid Kleckner0503a872013-12-05 01:23:43 +00003892 // If we had to adjust the pointee type when building a member pointer, make
3893 // sure to push TypeLoc info for it.
3894 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3895 if (MPT && PointeeType != MPT->getPointeeType()) {
3896 assert(isa<AdjustedType>(MPT->getPointeeType()));
3897 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3898 }
3899
John McCall550e0c22009-10-21 00:40:46 +00003900 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3901 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003902 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003903
3904 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905}
3906
Mike Stump11289f42009-09-09 15:08:12 +00003907template<typename Derived>
3908QualType
John McCall550e0c22009-10-21 00:40:46 +00003909TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003910 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003911 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003912 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003913 if (ElementType.isNull())
3914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003915
John McCall550e0c22009-10-21 00:40:46 +00003916 QualType Result = TL.getType();
3917 if (getDerived().AlwaysRebuild() ||
3918 ElementType != T->getElementType()) {
3919 Result = getDerived().RebuildConstantArrayType(ElementType,
3920 T->getSizeModifier(),
3921 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003922 T->getIndexTypeCVRQualifiers(),
3923 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003924 if (Result.isNull())
3925 return QualType();
3926 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003927
3928 // We might have either a ConstantArrayType or a VariableArrayType now:
3929 // a ConstantArrayType is allowed to have an element type which is a
3930 // VariableArrayType if the type is dependent. Fortunately, all array
3931 // types have the same location layout.
3932 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003933 NewTL.setLBracketLoc(TL.getLBracketLoc());
3934 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003935
John McCall550e0c22009-10-21 00:40:46 +00003936 Expr *Size = TL.getSizeExpr();
3937 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003938 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3939 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003940 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3941 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003942 }
3943 NewTL.setSizeExpr(Size);
3944
3945 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003946}
Mike Stump11289f42009-09-09 15:08:12 +00003947
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003949QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003950 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003951 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003952 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003953 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954 if (ElementType.isNull())
3955 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003956
John McCall550e0c22009-10-21 00:40:46 +00003957 QualType Result = TL.getType();
3958 if (getDerived().AlwaysRebuild() ||
3959 ElementType != T->getElementType()) {
3960 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003961 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003962 T->getIndexTypeCVRQualifiers(),
3963 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003964 if (Result.isNull())
3965 return QualType();
3966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003967
John McCall550e0c22009-10-21 00:40:46 +00003968 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3969 NewTL.setLBracketLoc(TL.getLBracketLoc());
3970 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003971 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003972
3973 return Result;
3974}
3975
3976template<typename Derived>
3977QualType
3978TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003979 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003980 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003981 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3982 if (ElementType.isNull())
3983 return QualType();
3984
John McCalldadc5752010-08-24 06:29:42 +00003985 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003986 = getDerived().TransformExpr(T->getSizeExpr());
3987 if (SizeResult.isInvalid())
3988 return QualType();
3989
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003990 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003991
3992 QualType Result = TL.getType();
3993 if (getDerived().AlwaysRebuild() ||
3994 ElementType != T->getElementType() ||
3995 Size != T->getSizeExpr()) {
3996 Result = getDerived().RebuildVariableArrayType(ElementType,
3997 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003998 Size,
John McCall550e0c22009-10-21 00:40:46 +00003999 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004000 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004001 if (Result.isNull())
4002 return QualType();
4003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004004
Serge Pavlov774c6d02014-02-06 03:49:11 +00004005 // We might have constant size array now, but fortunately it has the same
4006 // location layout.
4007 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004008 NewTL.setLBracketLoc(TL.getLBracketLoc());
4009 NewTL.setRBracketLoc(TL.getRBracketLoc());
4010 NewTL.setSizeExpr(Size);
4011
4012 return Result;
4013}
4014
4015template<typename Derived>
4016QualType
4017TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004018 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004019 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004020 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4021 if (ElementType.isNull())
4022 return QualType();
4023
Richard Smith764d2fe2011-12-20 02:08:33 +00004024 // Array bounds are constant expressions.
4025 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4026 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004027
John McCall33ddac02011-01-19 10:06:00 +00004028 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4029 Expr *origSize = TL.getSizeExpr();
4030 if (!origSize) origSize = T->getSizeExpr();
4031
4032 ExprResult sizeResult
4033 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004034 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004035 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004036 return QualType();
4037
John McCall33ddac02011-01-19 10:06:00 +00004038 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004039
4040 QualType Result = TL.getType();
4041 if (getDerived().AlwaysRebuild() ||
4042 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004043 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004044 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4045 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004046 size,
John McCall550e0c22009-10-21 00:40:46 +00004047 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004048 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004049 if (Result.isNull())
4050 return QualType();
4051 }
John McCall550e0c22009-10-21 00:40:46 +00004052
4053 // We might have any sort of array type now, but fortunately they
4054 // all have the same location layout.
4055 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4056 NewTL.setLBracketLoc(TL.getLBracketLoc());
4057 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004058 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004059
4060 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
4063template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004065 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004066 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004067 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004068
4069 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070 QualType ElementType = getDerived().TransformType(T->getElementType());
4071 if (ElementType.isNull())
4072 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004073
Richard Smith764d2fe2011-12-20 02:08:33 +00004074 // Vector sizes are constant expressions.
4075 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4076 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004077
John McCalldadc5752010-08-24 06:29:42 +00004078 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004079 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080 if (Size.isInvalid())
4081 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004082
John McCall550e0c22009-10-21 00:40:46 +00004083 QualType Result = TL.getType();
4084 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004085 ElementType != T->getElementType() ||
4086 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004087 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004088 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004090 if (Result.isNull())
4091 return QualType();
4092 }
John McCall550e0c22009-10-21 00:40:46 +00004093
4094 // Result might be dependent or not.
4095 if (isa<DependentSizedExtVectorType>(Result)) {
4096 DependentSizedExtVectorTypeLoc NewTL
4097 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4098 NewTL.setNameLoc(TL.getNameLoc());
4099 } else {
4100 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4101 NewTL.setNameLoc(TL.getNameLoc());
4102 }
4103
4104 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004105}
Mike Stump11289f42009-09-09 15:08:12 +00004106
4107template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004108QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004109 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004110 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004111 QualType ElementType = getDerived().TransformType(T->getElementType());
4112 if (ElementType.isNull())
4113 return QualType();
4114
John McCall550e0c22009-10-21 00:40:46 +00004115 QualType Result = TL.getType();
4116 if (getDerived().AlwaysRebuild() ||
4117 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004118 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004119 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004120 if (Result.isNull())
4121 return QualType();
4122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004123
John McCall550e0c22009-10-21 00:40:46 +00004124 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4125 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004126
John McCall550e0c22009-10-21 00:40:46 +00004127 return Result;
4128}
4129
4130template<typename Derived>
4131QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004132 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004133 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004134 QualType ElementType = getDerived().TransformType(T->getElementType());
4135 if (ElementType.isNull())
4136 return QualType();
4137
4138 QualType Result = TL.getType();
4139 if (getDerived().AlwaysRebuild() ||
4140 ElementType != T->getElementType()) {
4141 Result = getDerived().RebuildExtVectorType(ElementType,
4142 T->getNumElements(),
4143 /*FIXME*/ SourceLocation());
4144 if (Result.isNull())
4145 return QualType();
4146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004147
John McCall550e0c22009-10-21 00:40:46 +00004148 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4149 NewTL.setNameLoc(TL.getNameLoc());
4150
4151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152}
Mike Stump11289f42009-09-09 15:08:12 +00004153
David Blaikie05785d12013-02-20 22:23:23 +00004154template <typename Derived>
4155ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4156 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4157 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004158 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004159 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004160
Douglas Gregor715e4612011-01-14 22:40:04 +00004161 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004162 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004163 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004164 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004165 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004166
Douglas Gregor715e4612011-01-14 22:40:04 +00004167 TypeLocBuilder TLB;
4168 TypeLoc NewTL = OldDI->getTypeLoc();
4169 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004170
4171 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004172 OldExpansionTL.getPatternLoc());
4173 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004174 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004175
4176 Result = RebuildPackExpansionType(Result,
4177 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004178 OldExpansionTL.getEllipsisLoc(),
4179 NumExpansions);
4180 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004181 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004182
Douglas Gregor715e4612011-01-14 22:40:04 +00004183 PackExpansionTypeLoc NewExpansionTL
4184 = TLB.push<PackExpansionTypeLoc>(Result);
4185 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4186 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4187 } else
4188 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004189 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004190 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004191
John McCall8fb0d9d2011-05-01 22:35:37 +00004192 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004193 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004194
4195 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4196 OldParm->getDeclContext(),
4197 OldParm->getInnerLocStart(),
4198 OldParm->getLocation(),
4199 OldParm->getIdentifier(),
4200 NewDI->getType(),
4201 NewDI,
4202 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004203 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004204 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4205 OldParm->getFunctionScopeIndex() + indexAdjustment);
4206 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004207}
4208
4209template<typename Derived>
4210bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004211 TransformFunctionTypeParams(SourceLocation Loc,
4212 ParmVarDecl **Params, unsigned NumParams,
4213 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004214 SmallVectorImpl<QualType> &OutParamTypes,
4215 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004216 int indexAdjustment = 0;
4217
Douglas Gregordd472162011-01-07 00:20:55 +00004218 for (unsigned i = 0; i != NumParams; ++i) {
4219 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004220 assert(OldParm->getFunctionScopeIndex() == i);
4221
David Blaikie05785d12013-02-20 22:23:23 +00004222 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004223 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004224 if (OldParm->isParameterPack()) {
4225 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004226 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004227
Douglas Gregor5499af42011-01-05 23:12:31 +00004228 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004229 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004230 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004231 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4232 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004233 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4234
Douglas Gregor5499af42011-01-05 23:12:31 +00004235 // Determine whether we should expand the parameter packs.
4236 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004237 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004238 Optional<unsigned> OrigNumExpansions =
4239 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004240 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004241 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4242 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004243 Unexpanded,
4244 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004245 RetainExpansion,
4246 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004247 return true;
4248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004249
Douglas Gregor5499af42011-01-05 23:12:31 +00004250 if (ShouldExpand) {
4251 // Expand the function parameter pack into multiple, separate
4252 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004253 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004254 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004255 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004256 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004257 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004258 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004259 OrigNumExpansions,
4260 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004261 if (!NewParm)
4262 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004263
Douglas Gregordd472162011-01-07 00:20:55 +00004264 OutParamTypes.push_back(NewParm->getType());
4265 if (PVars)
4266 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004267 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004268
4269 // If we're supposed to retain a pack expansion, do so by temporarily
4270 // forgetting the partially-substituted parameter pack.
4271 if (RetainExpansion) {
4272 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004273 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004274 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004275 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004276 OrigNumExpansions,
4277 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004278 if (!NewParm)
4279 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004280
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004281 OutParamTypes.push_back(NewParm->getType());
4282 if (PVars)
4283 PVars->push_back(NewParm);
4284 }
4285
John McCall8fb0d9d2011-05-01 22:35:37 +00004286 // The next parameter should have the same adjustment as the
4287 // last thing we pushed, but we post-incremented indexAdjustment
4288 // on every push. Also, if we push nothing, the adjustment should
4289 // go down by one.
4290 indexAdjustment--;
4291
Douglas Gregor5499af42011-01-05 23:12:31 +00004292 // We're done with the pack expansion.
4293 continue;
4294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
4296 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004297 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004298 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4299 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004300 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004301 NumExpansions,
4302 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004303 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004304 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004305 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004306 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004307
John McCall58f10c32010-03-11 09:03:00 +00004308 if (!NewParm)
4309 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregordd472162011-01-07 00:20:55 +00004311 OutParamTypes.push_back(NewParm->getType());
4312 if (PVars)
4313 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004314 continue;
4315 }
John McCall58f10c32010-03-11 09:03:00 +00004316
4317 // Deal with the possibility that we don't have a parameter
4318 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004319 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004320 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004321 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004322 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004323 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004324 = dyn_cast<PackExpansionType>(OldType)) {
4325 // We have a function parameter pack that may need to be expanded.
4326 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004327 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004328 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Douglas Gregor5499af42011-01-05 23:12:31 +00004330 // Determine whether we should expand the parameter packs.
4331 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004332 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004333 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004334 Unexpanded,
4335 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004336 RetainExpansion,
4337 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004338 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004340
Douglas Gregor5499af42011-01-05 23:12:31 +00004341 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004342 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004343 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004344 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004345 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4346 QualType NewType = getDerived().TransformType(Pattern);
4347 if (NewType.isNull())
4348 return true;
John McCall58f10c32010-03-11 09:03:00 +00004349
Douglas Gregordd472162011-01-07 00:20:55 +00004350 OutParamTypes.push_back(NewType);
4351 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004352 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004354
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 // We're done with the pack expansion.
4356 continue;
4357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004358
Douglas Gregor48d24112011-01-10 20:53:55 +00004359 // If we're supposed to retain a pack expansion, do so by temporarily
4360 // forgetting the partially-substituted parameter pack.
4361 if (RetainExpansion) {
4362 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4363 QualType NewType = getDerived().TransformType(Pattern);
4364 if (NewType.isNull())
4365 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004366
Douglas Gregor48d24112011-01-10 20:53:55 +00004367 OutParamTypes.push_back(NewType);
4368 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004369 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004370 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004371
Chad Rosier1dcde962012-08-08 18:46:20 +00004372 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004373 // expansion.
4374 OldType = Expansion->getPattern();
4375 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4377 NewType = getDerived().TransformType(OldType);
4378 } else {
4379 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004381
Douglas Gregor5499af42011-01-05 23:12:31 +00004382 if (NewType.isNull())
4383 return true;
4384
4385 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004386 NewType = getSema().Context.getPackExpansionType(NewType,
4387 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004388
Douglas Gregordd472162011-01-07 00:20:55 +00004389 OutParamTypes.push_back(NewType);
4390 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004391 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004392 }
4393
John McCall8fb0d9d2011-05-01 22:35:37 +00004394#ifndef NDEBUG
4395 if (PVars) {
4396 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4397 if (ParmVarDecl *parm = (*PVars)[i])
4398 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004399 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004400#endif
4401
4402 return false;
4403}
John McCall58f10c32010-03-11 09:03:00 +00004404
4405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004406QualType
John McCall550e0c22009-10-21 00:40:46 +00004407TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004408 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004409 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004410}
4411
4412template<typename Derived>
4413QualType
4414TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4415 FunctionProtoTypeLoc TL,
4416 CXXRecordDecl *ThisContext,
4417 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004418 // Transform the parameters and return type.
4419 //
Richard Smithf623c962012-04-17 00:58:00 +00004420 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004421 // When the function has a trailing return type, we instantiate the
4422 // parameters before the return type, since the return type can then refer
4423 // to the parameters themselves (via decltype, sizeof, etc.).
4424 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004425 SmallVector<QualType, 4> ParamTypes;
4426 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004427 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004428
Douglas Gregor7fb25412010-10-01 18:44:50 +00004429 QualType ResultType;
4430
Richard Smith1226c602012-08-14 22:51:13 +00004431 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004432 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004433 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004434 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004435 return QualType();
4436
Douglas Gregor3024f072012-04-16 07:05:22 +00004437 {
4438 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004439 // If a declaration declares a member function or member function
4440 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004441 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004442 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004443 // declarator.
4444 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004445
Alp Toker42a16a62014-01-25 23:51:36 +00004446 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004447 if (ResultType.isNull())
4448 return QualType();
4449 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004450 }
4451 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004452 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004453 if (ResultType.isNull())
4454 return QualType();
4455
Alp Toker9cacbab2014-01-20 20:26:09 +00004456 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004457 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004458 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004459 return QualType();
4460 }
4461
Richard Smithf623c962012-04-17 00:58:00 +00004462 // FIXME: Need to transform the exception-specification too.
4463
John McCall550e0c22009-10-21 00:40:46 +00004464 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004465 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004466 T->getNumParams() != ParamTypes.size() ||
4467 !std::equal(T->param_type_begin(), T->param_type_end(),
4468 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004469 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004470 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004471 if (Result.isNull())
4472 return QualType();
4473 }
Mike Stump11289f42009-09-09 15:08:12 +00004474
John McCall550e0c22009-10-21 00:40:46 +00004475 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004476 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004477 NewTL.setLParenLoc(TL.getLParenLoc());
4478 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004479 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004480 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4481 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004482
4483 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004484}
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregord6ff3322009-08-04 16:50:30 +00004486template<typename Derived>
4487QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004488 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004489 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004490 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004491 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004492 if (ResultType.isNull())
4493 return QualType();
4494
4495 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004496 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004497 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4498
4499 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004500 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004501 NewTL.setLParenLoc(TL.getLParenLoc());
4502 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004503 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004504
4505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
John McCallb96ec562009-12-04 22:46:56 +00004508template<typename Derived> QualType
4509TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004510 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004511 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004512 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004513 if (!D)
4514 return QualType();
4515
4516 QualType Result = TL.getType();
4517 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4518 Result = getDerived().RebuildUnresolvedUsingType(D);
4519 if (Result.isNull())
4520 return QualType();
4521 }
4522
4523 // We might get an arbitrary type spec type back. We should at
4524 // least always get a type spec type, though.
4525 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4526 NewTL.setNameLoc(TL.getNameLoc());
4527
4528 return Result;
4529}
4530
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004532QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004534 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004535 TypedefNameDecl *Typedef
4536 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4537 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538 if (!Typedef)
4539 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004540
John McCall550e0c22009-10-21 00:40:46 +00004541 QualType Result = TL.getType();
4542 if (getDerived().AlwaysRebuild() ||
4543 Typedef != T->getDecl()) {
4544 Result = getDerived().RebuildTypedefType(Typedef);
4545 if (Result.isNull())
4546 return QualType();
4547 }
Mike Stump11289f42009-09-09 15:08:12 +00004548
John McCall550e0c22009-10-21 00:40:46 +00004549 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4550 NewTL.setNameLoc(TL.getNameLoc());
4551
4552 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregord6ff3322009-08-04 16:50:30 +00004555template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004556QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004557 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004558 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004559 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4560 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004561
John McCalldadc5752010-08-24 06:29:42 +00004562 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563 if (E.isInvalid())
4564 return QualType();
4565
Eli Friedmane4f22df2012-02-29 04:03:55 +00004566 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4567 if (E.isInvalid())
4568 return QualType();
4569
John McCall550e0c22009-10-21 00:40:46 +00004570 QualType Result = TL.getType();
4571 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004572 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004573 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004574 if (Result.isNull())
4575 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004576 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004577 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004578
John McCall550e0c22009-10-21 00:40:46 +00004579 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004580 NewTL.setTypeofLoc(TL.getTypeofLoc());
4581 NewTL.setLParenLoc(TL.getLParenLoc());
4582 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004583
4584 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585}
Mike Stump11289f42009-09-09 15:08:12 +00004586
4587template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004588QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004589 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004590 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4591 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4592 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004594
John McCall550e0c22009-10-21 00:40:46 +00004595 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004596 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4597 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004598 if (Result.isNull())
4599 return QualType();
4600 }
Mike Stump11289f42009-09-09 15:08:12 +00004601
John McCall550e0c22009-10-21 00:40:46 +00004602 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004603 NewTL.setTypeofLoc(TL.getTypeofLoc());
4604 NewTL.setLParenLoc(TL.getLParenLoc());
4605 NewTL.setRParenLoc(TL.getRParenLoc());
4606 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004607
4608 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004609}
Mike Stump11289f42009-09-09 15:08:12 +00004610
4611template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004612QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004613 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004614 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004615
Douglas Gregore922c772009-08-04 22:27:00 +00004616 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4618 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004619
John McCalldadc5752010-08-24 06:29:42 +00004620 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004621 if (E.isInvalid())
4622 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004623
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004624 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004625 if (E.isInvalid())
4626 return QualType();
4627
John McCall550e0c22009-10-21 00:40:46 +00004628 QualType Result = TL.getType();
4629 if (getDerived().AlwaysRebuild() ||
4630 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004631 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004632 if (Result.isNull())
4633 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004635 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004636
John McCall550e0c22009-10-21 00:40:46 +00004637 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4638 NewTL.setNameLoc(TL.getNameLoc());
4639
4640 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004641}
4642
4643template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004644QualType TreeTransform<Derived>::TransformUnaryTransformType(
4645 TypeLocBuilder &TLB,
4646 UnaryTransformTypeLoc TL) {
4647 QualType Result = TL.getType();
4648 if (Result->isDependentType()) {
4649 const UnaryTransformType *T = TL.getTypePtr();
4650 QualType NewBase =
4651 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4652 Result = getDerived().RebuildUnaryTransformType(NewBase,
4653 T->getUTTKind(),
4654 TL.getKWLoc());
4655 if (Result.isNull())
4656 return QualType();
4657 }
4658
4659 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4660 NewTL.setKWLoc(TL.getKWLoc());
4661 NewTL.setParensRange(TL.getParensRange());
4662 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4663 return Result;
4664}
4665
4666template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004667QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4668 AutoTypeLoc TL) {
4669 const AutoType *T = TL.getTypePtr();
4670 QualType OldDeduced = T->getDeducedType();
4671 QualType NewDeduced;
4672 if (!OldDeduced.isNull()) {
4673 NewDeduced = getDerived().TransformType(OldDeduced);
4674 if (NewDeduced.isNull())
4675 return QualType();
4676 }
4677
4678 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004679 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4680 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004681 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004682 if (Result.isNull())
4683 return QualType();
4684 }
4685
4686 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4687 NewTL.setNameLoc(TL.getNameLoc());
4688
4689 return Result;
4690}
4691
4692template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004693QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004694 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004695 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004697 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4698 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699 if (!Record)
4700 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004701
John McCall550e0c22009-10-21 00:40:46 +00004702 QualType Result = TL.getType();
4703 if (getDerived().AlwaysRebuild() ||
4704 Record != T->getDecl()) {
4705 Result = getDerived().RebuildRecordType(Record);
4706 if (Result.isNull())
4707 return QualType();
4708 }
Mike Stump11289f42009-09-09 15:08:12 +00004709
John McCall550e0c22009-10-21 00:40:46 +00004710 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4711 NewTL.setNameLoc(TL.getNameLoc());
4712
4713 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004714}
Mike Stump11289f42009-09-09 15:08:12 +00004715
4716template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004717QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004718 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004719 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004720 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004721 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4722 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723 if (!Enum)
4724 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004725
John McCall550e0c22009-10-21 00:40:46 +00004726 QualType Result = TL.getType();
4727 if (getDerived().AlwaysRebuild() ||
4728 Enum != T->getDecl()) {
4729 Result = getDerived().RebuildEnumType(Enum);
4730 if (Result.isNull())
4731 return QualType();
4732 }
Mike Stump11289f42009-09-09 15:08:12 +00004733
John McCall550e0c22009-10-21 00:40:46 +00004734 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4735 NewTL.setNameLoc(TL.getNameLoc());
4736
4737 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004738}
John McCallfcc33b02009-09-05 00:15:47 +00004739
John McCalle78aac42010-03-10 03:28:59 +00004740template<typename Derived>
4741QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4742 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004743 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004744 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4745 TL.getTypePtr()->getDecl());
4746 if (!D) return QualType();
4747
4748 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4749 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4750 return T;
4751}
4752
Douglas Gregord6ff3322009-08-04 16:50:30 +00004753template<typename Derived>
4754QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004755 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004756 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004757 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004758}
4759
Mike Stump11289f42009-09-09 15:08:12 +00004760template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004761QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004762 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004763 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004764 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004765
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004766 // Substitute into the replacement type, which itself might involve something
4767 // that needs to be transformed. This only tends to occur with default
4768 // template arguments of template template parameters.
4769 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4770 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4771 if (Replacement.isNull())
4772 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004773
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004774 // Always canonicalize the replacement type.
4775 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4776 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004777 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004778 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004779
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004780 // Propagate type-source information.
4781 SubstTemplateTypeParmTypeLoc NewTL
4782 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4783 NewTL.setNameLoc(TL.getNameLoc());
4784 return Result;
4785
John McCallcebee162009-10-18 09:09:24 +00004786}
4787
4788template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004789QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4790 TypeLocBuilder &TLB,
4791 SubstTemplateTypeParmPackTypeLoc TL) {
4792 return TransformTypeSpecType(TLB, TL);
4793}
4794
4795template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004796QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004797 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004798 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004799 const TemplateSpecializationType *T = TL.getTypePtr();
4800
Douglas Gregordf846d12011-03-02 18:46:51 +00004801 // The nested-name-specifier never matters in a TemplateSpecializationType,
4802 // because we can't have a dependent nested-name-specifier anyway.
4803 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004804 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004805 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4806 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004807 if (Template.isNull())
4808 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004809
John McCall31f82722010-11-12 08:19:04 +00004810 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4811}
4812
Eli Friedman0dfb8892011-10-06 23:00:33 +00004813template<typename Derived>
4814QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4815 AtomicTypeLoc TL) {
4816 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4817 if (ValueType.isNull())
4818 return QualType();
4819
4820 QualType Result = TL.getType();
4821 if (getDerived().AlwaysRebuild() ||
4822 ValueType != TL.getValueLoc().getType()) {
4823 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4824 if (Result.isNull())
4825 return QualType();
4826 }
4827
4828 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4829 NewTL.setKWLoc(TL.getKWLoc());
4830 NewTL.setLParenLoc(TL.getLParenLoc());
4831 NewTL.setRParenLoc(TL.getRParenLoc());
4832
4833 return Result;
4834}
4835
Chad Rosier1dcde962012-08-08 18:46:20 +00004836 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 /// container that provides a \c getArgLoc() member function.
4838 ///
4839 /// This iterator is intended to be used with the iterator form of
4840 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4841 template<typename ArgLocContainer>
4842 class TemplateArgumentLocContainerIterator {
4843 ArgLocContainer *Container;
4844 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004845
Douglas Gregorfe921a72010-12-20 23:36:19 +00004846 public:
4847 typedef TemplateArgumentLoc value_type;
4848 typedef TemplateArgumentLoc reference;
4849 typedef int difference_type;
4850 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004851
Douglas Gregorfe921a72010-12-20 23:36:19 +00004852 class pointer {
4853 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004854
Douglas Gregorfe921a72010-12-20 23:36:19 +00004855 public:
4856 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004857
Douglas Gregorfe921a72010-12-20 23:36:19 +00004858 const TemplateArgumentLoc *operator->() const {
4859 return &Arg;
4860 }
4861 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004862
4863
Douglas Gregorfe921a72010-12-20 23:36:19 +00004864 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
Douglas Gregorfe921a72010-12-20 23:36:19 +00004866 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4867 unsigned Index)
4868 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004869
Douglas Gregorfe921a72010-12-20 23:36:19 +00004870 TemplateArgumentLocContainerIterator &operator++() {
4871 ++Index;
4872 return *this;
4873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
Douglas Gregorfe921a72010-12-20 23:36:19 +00004875 TemplateArgumentLocContainerIterator operator++(int) {
4876 TemplateArgumentLocContainerIterator Old(*this);
4877 ++(*this);
4878 return Old;
4879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004880
Douglas Gregorfe921a72010-12-20 23:36:19 +00004881 TemplateArgumentLoc operator*() const {
4882 return Container->getArgLoc(Index);
4883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004884
Douglas Gregorfe921a72010-12-20 23:36:19 +00004885 pointer operator->() const {
4886 return pointer(Container->getArgLoc(Index));
4887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregorfe921a72010-12-20 23:36:19 +00004889 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004890 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004891 return X.Container == Y.Container && X.Index == Y.Index;
4892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
Douglas Gregorfe921a72010-12-20 23:36:19 +00004894 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004895 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004896 return !(X == Y);
4897 }
4898 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004899
4900
John McCall31f82722010-11-12 08:19:04 +00004901template <typename Derived>
4902QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4903 TypeLocBuilder &TLB,
4904 TemplateSpecializationTypeLoc TL,
4905 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004906 TemplateArgumentListInfo NewTemplateArgs;
4907 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4908 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004909 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4910 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004911 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004912 ArgIterator(TL, TL.getNumArgs()),
4913 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall0ad16662009-10-29 08:12:44 +00004916 // FIXME: maybe don't rebuild if all the template arguments are the same.
4917
4918 QualType Result =
4919 getDerived().RebuildTemplateSpecializationType(Template,
4920 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004921 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004922
4923 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004924 // Specializations of template template parameters are represented as
4925 // TemplateSpecializationTypes, and substitution of type alias templates
4926 // within a dependent context can transform them into
4927 // DependentTemplateSpecializationTypes.
4928 if (isa<DependentTemplateSpecializationType>(Result)) {
4929 DependentTemplateSpecializationTypeLoc NewTL
4930 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004931 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004932 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004933 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004934 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004935 NewTL.setLAngleLoc(TL.getLAngleLoc());
4936 NewTL.setRAngleLoc(TL.getRAngleLoc());
4937 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4938 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4939 return Result;
4940 }
4941
John McCall0ad16662009-10-29 08:12:44 +00004942 TemplateSpecializationTypeLoc NewTL
4943 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004944 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004945 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4946 NewTL.setLAngleLoc(TL.getLAngleLoc());
4947 NewTL.setRAngleLoc(TL.getRAngleLoc());
4948 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4949 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004950 }
Mike Stump11289f42009-09-09 15:08:12 +00004951
John McCall0ad16662009-10-29 08:12:44 +00004952 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004953}
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregor5a064722011-02-28 17:23:35 +00004955template <typename Derived>
4956QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4957 TypeLocBuilder &TLB,
4958 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004959 TemplateName Template,
4960 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 TemplateArgumentListInfo NewTemplateArgs;
4962 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4963 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4964 typedef TemplateArgumentLocContainerIterator<
4965 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004966 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004967 ArgIterator(TL, TL.getNumArgs()),
4968 NewTemplateArgs))
4969 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004970
Douglas Gregor5a064722011-02-28 17:23:35 +00004971 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004972
Douglas Gregor5a064722011-02-28 17:23:35 +00004973 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4974 QualType Result
4975 = getSema().Context.getDependentTemplateSpecializationType(
4976 TL.getTypePtr()->getKeyword(),
4977 DTN->getQualifier(),
4978 DTN->getIdentifier(),
4979 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004980
Douglas Gregor5a064722011-02-28 17:23:35 +00004981 DependentTemplateSpecializationTypeLoc NewTL
4982 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004983 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004984 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004985 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004986 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004987 NewTL.setLAngleLoc(TL.getLAngleLoc());
4988 NewTL.setRAngleLoc(TL.getRAngleLoc());
4989 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4990 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4991 return Result;
4992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004993
4994 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004995 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004996 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004997 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004998
Douglas Gregor5a064722011-02-28 17:23:35 +00004999 if (!Result.isNull()) {
5000 /// FIXME: Wrap this in an elaborated-type-specifier?
5001 TemplateSpecializationTypeLoc NewTL
5002 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005003 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005004 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005005 NewTL.setLAngleLoc(TL.getLAngleLoc());
5006 NewTL.setRAngleLoc(TL.getRAngleLoc());
5007 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5008 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005010
Douglas Gregor5a064722011-02-28 17:23:35 +00005011 return Result;
5012}
5013
Mike Stump11289f42009-09-09 15:08:12 +00005014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005015QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005016TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005017 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005018 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005019
Douglas Gregor844cb502011-03-01 18:12:44 +00005020 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005021 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005022 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005023 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005024 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5025 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005026 return QualType();
5027 }
Mike Stump11289f42009-09-09 15:08:12 +00005028
John McCall31f82722010-11-12 08:19:04 +00005029 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5030 if (NamedT.isNull())
5031 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005032
Richard Smith3f1b5d02011-05-05 21:57:07 +00005033 // C++0x [dcl.type.elab]p2:
5034 // If the identifier resolves to a typedef-name or the simple-template-id
5035 // resolves to an alias template specialization, the
5036 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005037 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5038 if (const TemplateSpecializationType *TST =
5039 NamedT->getAs<TemplateSpecializationType>()) {
5040 TemplateName Template = TST->getTemplateName();
5041 if (TypeAliasTemplateDecl *TAT =
5042 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5043 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5044 diag::err_tag_reference_non_tag) << 4;
5045 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5046 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005047 }
5048 }
5049
John McCall550e0c22009-10-21 00:40:46 +00005050 QualType Result = TL.getType();
5051 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005052 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005053 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005054 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005055 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005056 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005057 if (Result.isNull())
5058 return QualType();
5059 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060
Abramo Bagnara6150c882010-05-11 21:36:43 +00005061 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005062 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005063 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
5067template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005068QualType TreeTransform<Derived>::TransformAttributedType(
5069 TypeLocBuilder &TLB,
5070 AttributedTypeLoc TL) {
5071 const AttributedType *oldType = TL.getTypePtr();
5072 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5073 if (modifiedType.isNull())
5074 return QualType();
5075
5076 QualType result = TL.getType();
5077
5078 // FIXME: dependent operand expressions?
5079 if (getDerived().AlwaysRebuild() ||
5080 modifiedType != oldType->getModifiedType()) {
5081 // TODO: this is really lame; we should really be rebuilding the
5082 // equivalent type from first principles.
5083 QualType equivalentType
5084 = getDerived().TransformType(oldType->getEquivalentType());
5085 if (equivalentType.isNull())
5086 return QualType();
5087 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5088 modifiedType,
5089 equivalentType);
5090 }
5091
5092 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5093 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5094 if (TL.hasAttrOperand())
5095 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5096 if (TL.hasAttrExprOperand())
5097 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5098 else if (TL.hasAttrEnumOperand())
5099 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5100
5101 return result;
5102}
5103
5104template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005105QualType
5106TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5107 ParenTypeLoc TL) {
5108 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5109 if (Inner.isNull())
5110 return QualType();
5111
5112 QualType Result = TL.getType();
5113 if (getDerived().AlwaysRebuild() ||
5114 Inner != TL.getInnerLoc().getType()) {
5115 Result = getDerived().RebuildParenType(Inner);
5116 if (Result.isNull())
5117 return QualType();
5118 }
5119
5120 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5121 NewTL.setLParenLoc(TL.getLParenLoc());
5122 NewTL.setRParenLoc(TL.getRParenLoc());
5123 return Result;
5124}
5125
5126template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005127QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005128 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005129 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005130
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005131 NestedNameSpecifierLoc QualifierLoc
5132 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5133 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005134 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005135
John McCallc392f372010-06-11 00:33:02 +00005136 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005137 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005138 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005139 QualifierLoc,
5140 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005141 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005142 if (Result.isNull())
5143 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005144
Abramo Bagnarad7548482010-05-19 21:37:53 +00005145 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5146 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005147 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5148
Abramo Bagnarad7548482010-05-19 21:37:53 +00005149 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005150 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005151 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005152 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005153 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005154 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005155 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005156 NewTL.setNameLoc(TL.getNameLoc());
5157 }
John McCall550e0c22009-10-21 00:40:46 +00005158 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005159}
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005162QualType TreeTransform<Derived>::
5163 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005164 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005165 NestedNameSpecifierLoc QualifierLoc;
5166 if (TL.getQualifierLoc()) {
5167 QualifierLoc
5168 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5169 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005170 return QualType();
5171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
John McCall31f82722010-11-12 08:19:04 +00005173 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005174 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005175}
5176
5177template<typename Derived>
5178QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005179TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5180 DependentTemplateSpecializationTypeLoc TL,
5181 NestedNameSpecifierLoc QualifierLoc) {
5182 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005183
Douglas Gregora7a795b2011-03-01 20:11:18 +00005184 TemplateArgumentListInfo NewTemplateArgs;
5185 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5186 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005187
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188 typedef TemplateArgumentLocContainerIterator<
5189 DependentTemplateSpecializationTypeLoc> ArgIterator;
5190 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5191 ArgIterator(TL, TL.getNumArgs()),
5192 NewTemplateArgs))
5193 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005194
Douglas Gregora7a795b2011-03-01 20:11:18 +00005195 QualType Result
5196 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5197 QualifierLoc,
5198 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005199 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005200 NewTemplateArgs);
5201 if (Result.isNull())
5202 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005203
Douglas Gregora7a795b2011-03-01 20:11:18 +00005204 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5205 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
Douglas Gregora7a795b2011-03-01 20:11:18 +00005207 // Copy information relevant to the template specialization.
5208 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005209 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005210 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005211 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005212 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5213 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005214 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005215 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005216
Douglas Gregora7a795b2011-03-01 20:11:18 +00005217 // Copy information relevant to the elaborated type.
5218 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005219 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005220 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005221 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5222 DependentTemplateSpecializationTypeLoc SpecTL
5223 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005224 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005225 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005226 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005227 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005228 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5229 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005230 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005231 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005232 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005233 TemplateSpecializationTypeLoc SpecTL
5234 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005235 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005236 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005237 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5238 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005239 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005240 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005241 }
5242 return Result;
5243}
5244
5245template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005246QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5247 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005248 QualType Pattern
5249 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005250 if (Pattern.isNull())
5251 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005252
5253 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005254 if (getDerived().AlwaysRebuild() ||
5255 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005256 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005257 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005258 TL.getEllipsisLoc(),
5259 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005260 if (Result.isNull())
5261 return QualType();
5262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005263
Douglas Gregor822d0302011-01-12 17:07:58 +00005264 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5265 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5266 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005267}
5268
5269template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005270QualType
5271TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005272 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005273 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005274 TLB.pushFullCopy(TL);
5275 return TL.getType();
5276}
5277
5278template<typename Derived>
5279QualType
5280TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005281 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005282 // ObjCObjectType is never dependent.
5283 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005284 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285}
Mike Stump11289f42009-09-09 15:08:12 +00005286
5287template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005288QualType
5289TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005290 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005291 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005292 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005293 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005294}
5295
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005297// Statement transformation
5298//===----------------------------------------------------------------------===//
5299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005300StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005302 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005303}
5304
5305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005306StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005307TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5308 return getDerived().TransformCompoundStmt(S, false);
5309}
5310
5311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005312StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005313TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005314 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005315 Sema::CompoundScopeRAII CompoundScope(getSema());
5316
John McCall1ababa62010-08-27 19:56:05 +00005317 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005318 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005319 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005320 for (auto *B : S->body()) {
5321 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005322 if (Result.isInvalid()) {
5323 // Immediately fail if this was a DeclStmt, since it's very
5324 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005325 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005326 return StmtError();
5327
5328 // Otherwise, just keep processing substatements and fail later.
5329 SubStmtInvalid = true;
5330 continue;
5331 }
Mike Stump11289f42009-09-09 15:08:12 +00005332
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005333 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005334 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 }
Mike Stump11289f42009-09-09 15:08:12 +00005336
John McCall1ababa62010-08-27 19:56:05 +00005337 if (SubStmtInvalid)
5338 return StmtError();
5339
Douglas Gregorebe10102009-08-20 07:17:43 +00005340 if (!getDerived().AlwaysRebuild() &&
5341 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005342 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005343
5344 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005345 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 S->getRBracLoc(),
5347 IsStmtExpr);
5348}
Mike Stump11289f42009-09-09 15:08:12 +00005349
Douglas Gregorebe10102009-08-20 07:17:43 +00005350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005351StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005352TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005353 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005354 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005355 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5356 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005357
Eli Friedman06577382009-11-19 03:14:00 +00005358 // Transform the left-hand case value.
5359 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005360 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005361 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005362 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005363
Eli Friedman06577382009-11-19 03:14:00 +00005364 // Transform the right-hand case value (for the GNU case-range extension).
5365 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005366 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005367 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005369 }
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregorebe10102009-08-20 07:17:43 +00005371 // Build the case statement.
5372 // Case statements are always rebuilt so that they will attached to their
5373 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005374 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005375 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005376 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005377 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 S->getColonLoc());
5379 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregorebe10102009-08-20 07:17:43 +00005382 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005384 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005388 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005389}
5390
5391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005392StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005393TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005394 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005395 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005396 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005397 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005398
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 // Default statements are always rebuilt
5400 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005401 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregorebe10102009-08-20 07:17:43 +00005404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005406TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005407 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005410
Chris Lattnercab02a62011-02-17 20:34:02 +00005411 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5412 S->getDecl());
5413 if (!LD)
5414 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005415
5416
Douglas Gregorebe10102009-08-20 07:17:43 +00005417 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005418 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005419 cast<LabelDecl>(LD), SourceLocation(),
5420 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005421}
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregorebe10102009-08-20 07:17:43 +00005423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005424StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005425TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5426 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5427 if (SubStmt.isInvalid())
5428 return StmtError();
5429
5430 // TODO: transform attributes
5431 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5432 return S;
5433
5434 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5435 S->getAttrs(),
5436 SubStmt.get());
5437}
5438
5439template<typename Derived>
5440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005441TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005443 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005444 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005445 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005446 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005447 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005448 getDerived().TransformDefinition(
5449 S->getConditionVariable()->getLocation(),
5450 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005451 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005453 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005454 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005455
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005456 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005458
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005459 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005460 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005461 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005462 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005463 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005465
John McCallb268a282010-08-23 23:25:46 +00005466 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005467 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005469
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005470 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005471 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005475 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005476 if (Then.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 "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005480 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 if (Else.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 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005485 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005486 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 Then.get() == S->getThen() &&
5488 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005489 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005491 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005492 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005493 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005494}
5495
5496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005497StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005498TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005499 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005500 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005501 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005502 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005503 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005504 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005505 getDerived().TransformDefinition(
5506 S->getConditionVariable()->getLocation(),
5507 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005508 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005510 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005511 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005512
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005513 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005514 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005515 }
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005519 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005520 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005521 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005525 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregorebe10102009-08-20 07:17:43 +00005529 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005530 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5531 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005532}
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregorebe10102009-08-20 07:17:43 +00005534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005536TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005537 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005538 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005539 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005540 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005541 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005542 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005543 getDerived().TransformDefinition(
5544 S->getConditionVariable()->getLocation(),
5545 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005546 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005547 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005548 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005549 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005550
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005551 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005553
5554 if (S->getCond()) {
5555 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005556 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5557 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005558 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005559 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005561 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005562 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005563 }
Mike Stump11289f42009-09-09 15:08:12 +00005564
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005565 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005566 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005568
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005570 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005572 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorebe10102009-08-20 07:17:43 +00005574 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005575 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005576 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005577 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005578 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005580 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005581 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005582}
Mike Stump11289f42009-09-09 15:08:12 +00005583
Douglas Gregorebe10102009-08-20 07:17:43 +00005584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005585StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005586TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005587 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005588 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005589 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005592 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005593 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005594 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005596
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 if (!getDerived().AlwaysRebuild() &&
5598 Cond.get() == S->getCond() &&
5599 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005600 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCallb268a282010-08-23 23:25:46 +00005602 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5603 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 S->getRParenLoc());
5605}
Mike Stump11289f42009-09-09 15:08:12 +00005606
Douglas Gregorebe10102009-08-20 07:17:43 +00005607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005608StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005609TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005610 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005611 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005613 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregorebe10102009-08-20 07:17:43 +00005615 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005616 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005617 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005618 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005619 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005620 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005621 getDerived().TransformDefinition(
5622 S->getConditionVariable()->getLocation(),
5623 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005624 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005626 } else {
5627 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005628
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005629 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005631
5632 if (S->getCond()) {
5633 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005634 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5635 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005636 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005637 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005638 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005639
John McCallb268a282010-08-23 23:25:46 +00005640 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005641 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005642 }
Mike Stump11289f42009-09-09 15:08:12 +00005643
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005644 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005645 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005647
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005649 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
Richard Smith945f8d32013-01-14 22:39:08 +00005653 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005654 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005658 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 if (!getDerived().AlwaysRebuild() &&
5663 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005664 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005665 Inc.get() == S->getInc() &&
5666 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005667 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregorebe10102009-08-20 07:17:43 +00005669 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005670 Init.get(), FullCond, ConditionVar,
5671 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005672}
5673
5674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005676TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005677 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5678 S->getLabel());
5679 if (!LD)
5680 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005683 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005684 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005685}
5686
5687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005688StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005689TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005690 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005693 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregorebe10102009-08-20 07:17:43 +00005695 if (!getDerived().AlwaysRebuild() &&
5696 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005697 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005698
5699 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005700 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005701}
5702
5703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005704StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005705TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005706 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005707}
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregorebe10102009-08-20 07:17:43 +00005709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005710StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005711TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005712 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregorebe10102009-08-20 07:17:43 +00005715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005717TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005718 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005721
Mike Stump11289f42009-09-09 15:08:12 +00005722 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005723 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005724 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005725}
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregorebe10102009-08-20 07:17:43 +00005727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005728StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005729TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005730 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005731 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005732 for (auto *D : S->decls()) {
5733 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005734 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005737 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005738 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregorebe10102009-08-20 07:17:43 +00005740 Decls.push_back(Transformed);
5741 }
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregorebe10102009-08-20 07:17:43 +00005743 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005744 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005745
Rafael Espindolaab417692013-07-09 12:05:01 +00005746 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005747}
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregorebe10102009-08-20 07:17:43 +00005749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005750StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005751TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005752
Benjamin Kramerf0623432012-08-23 22:51:59 +00005753 SmallVector<Expr*, 8> Constraints;
5754 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005755 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005756
John McCalldadc5752010-08-24 06:29:42 +00005757 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005758 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005759
5760 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005761
Anders Carlssonaaeef072010-01-24 05:50:09 +00005762 // Go through the outputs.
5763 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005764 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005765
Anders Carlssonaaeef072010-01-24 05:50:09 +00005766 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005767 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005768
Anders Carlssonaaeef072010-01-24 05:50:09 +00005769 // Transform the output expr.
5770 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005771 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005772 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005773 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005774
Anders Carlssonaaeef072010-01-24 05:50:09 +00005775 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005776
John McCallb268a282010-08-23 23:25:46 +00005777 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005778 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005779
Anders Carlssonaaeef072010-01-24 05:50:09 +00005780 // Go through the inputs.
5781 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005782 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005783
Anders Carlssonaaeef072010-01-24 05:50:09 +00005784 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005785 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005786
Anders Carlssonaaeef072010-01-24 05:50:09 +00005787 // Transform the input expr.
5788 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005789 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005790 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005792
Anders Carlssonaaeef072010-01-24 05:50:09 +00005793 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005794
John McCallb268a282010-08-23 23:25:46 +00005795 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005797
Anders Carlssonaaeef072010-01-24 05:50:09 +00005798 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005799 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005800
5801 // Go through the clobbers.
5802 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005803 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005804
5805 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005806 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005807 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5808 S->isVolatile(), S->getNumOutputs(),
5809 S->getNumInputs(), Names.data(),
5810 Constraints, Exprs, AsmString.get(),
5811 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005812}
5813
Chad Rosier32503022012-06-11 20:47:18 +00005814template<typename Derived>
5815StmtResult
5816TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005817 ArrayRef<Token> AsmToks =
5818 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005819
John McCallf413f5e2013-05-03 00:10:13 +00005820 bool HadError = false, HadChange = false;
5821
5822 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5823 SmallVector<Expr*, 8> TransformedExprs;
5824 TransformedExprs.reserve(SrcExprs.size());
5825 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5826 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5827 if (!Result.isUsable()) {
5828 HadError = true;
5829 } else {
5830 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005831 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005832 }
5833 }
5834
5835 if (HadError) return StmtError();
5836 if (!HadChange && !getDerived().AlwaysRebuild())
5837 return Owned(S);
5838
Chad Rosierb6f46c12012-08-15 16:53:30 +00005839 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005840 AsmToks, S->getAsmString(),
5841 S->getNumOutputs(), S->getNumInputs(),
5842 S->getAllConstraints(), S->getClobbers(),
5843 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005844}
Douglas Gregorebe10102009-08-20 07:17:43 +00005845
5846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005848TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005849 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005850 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005851 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005852 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
Douglas Gregor96c79492010-04-23 22:50:49 +00005854 // Transform the @catch statements (if present).
5855 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005856 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005857 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005858 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005859 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005861 if (Catch.get() != S->getCatchStmt(I))
5862 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005863 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
Douglas Gregor306de2f2010-04-22 23:59:56 +00005866 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005867 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005868 if (S->getFinallyStmt()) {
5869 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5870 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005872 }
5873
5874 // If nothing changed, just retain this statement.
5875 if (!getDerived().AlwaysRebuild() &&
5876 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005877 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005878 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005879 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
Douglas Gregor306de2f2010-04-22 23:59:56 +00005881 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005882 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005883 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005884}
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregorebe10102009-08-20 07:17:43 +00005886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005887StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005888TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005889 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005890 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005891 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005892 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005893 if (FromVar->getTypeSourceInfo()) {
5894 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5895 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005897 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005898
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005899 QualType T;
5900 if (TSInfo)
5901 T = TSInfo->getType();
5902 else {
5903 T = getDerived().TransformType(FromVar->getType());
5904 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005905 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005906 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005908 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5909 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005912
John McCalldadc5752010-08-24 06:29:42 +00005913 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005914 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005916
5917 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005918 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005919 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005920}
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregorebe10102009-08-20 07:17:43 +00005922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005923StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005924TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005925 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005926 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005927 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005929
Douglas Gregor306de2f2010-04-22 23:59:56 +00005930 // If nothing changed, just retain this statement.
5931 if (!getDerived().AlwaysRebuild() &&
5932 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005933 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005934
5935 // Build a new statement.
5936 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005937 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005938}
Mike Stump11289f42009-09-09 15:08:12 +00005939
Douglas Gregorebe10102009-08-20 07:17:43 +00005940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005942TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005943 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005944 if (S->getThrowExpr()) {
5945 Operand = getDerived().TransformExpr(S->getThrowExpr());
5946 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005949
Douglas Gregor2900c162010-04-22 21:44:01 +00005950 if (!getDerived().AlwaysRebuild() &&
5951 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005952 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
John McCallb268a282010-08-23 23:25:46 +00005954 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregorebe10102009-08-20 07:17:43 +00005957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005958StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005959TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005960 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005961 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005962 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005963 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005965 Object =
5966 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5967 Object.get());
5968 if (Object.isInvalid())
5969 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
Douglas Gregor6148de72010-04-22 22:01:21 +00005971 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005972 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005973 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005974 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005975
Douglas Gregor6148de72010-04-22 22:01:21 +00005976 // If nothing change, just retain the current statement.
5977 if (!getDerived().AlwaysRebuild() &&
5978 Object.get() == S->getSynchExpr() &&
5979 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005980 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00005981
5982 // Build a new statement.
5983 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005984 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005985}
5986
5987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005988StmtResult
John McCall31168b02011-06-15 23:02:42 +00005989TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5990 ObjCAutoreleasePoolStmt *S) {
5991 // Transform the body.
5992 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5993 if (Body.isInvalid())
5994 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
John McCall31168b02011-06-15 23:02:42 +00005996 // If nothing changed, just retain this statement.
5997 if (!getDerived().AlwaysRebuild() &&
5998 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005999 return S;
John McCall31168b02011-06-15 23:02:42 +00006000
6001 // Build a new statement.
6002 return getDerived().RebuildObjCAutoreleasePoolStmt(
6003 S->getAtLoc(), Body.get());
6004}
6005
6006template<typename Derived>
6007StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006008TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006009 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006010 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006011 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006012 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006013 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006014
Douglas Gregorf68a5082010-04-22 23:10:45 +00006015 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006016 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006017 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Douglas Gregorf68a5082010-04-22 23:10:45 +00006020 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006021 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006022 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006024
Douglas Gregorf68a5082010-04-22 23:10:45 +00006025 // If nothing changed, just retain this statement.
6026 if (!getDerived().AlwaysRebuild() &&
6027 Element.get() == S->getElement() &&
6028 Collection.get() == S->getCollection() &&
6029 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006030 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006031
Douglas Gregorf68a5082010-04-22 23:10:45 +00006032 // Build a new statement.
6033 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006034 Element.get(),
6035 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006036 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006037 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006038}
6039
David Majnemer5f7efef2013-10-15 09:50:08 +00006040template <typename Derived>
6041StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006043 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006044 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6045 TypeSourceInfo *T =
6046 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006047 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006049
David Majnemer5f7efef2013-10-15 09:50:08 +00006050 Var = getDerived().RebuildExceptionDecl(
6051 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6052 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006053 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006055 }
Mike Stump11289f42009-09-09 15:08:12 +00006056
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006058 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006059 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006061
David Majnemer5f7efef2013-10-15 09:50:08 +00006062 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006063 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006064 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006065
David Majnemer5f7efef2013-10-15 09:50:08 +00006066 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006067}
Mike Stump11289f42009-09-09 15:08:12 +00006068
David Majnemer5f7efef2013-10-15 09:50:08 +00006069template <typename Derived>
6070StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006072 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006073 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 // Transform the handlers.
6077 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006078 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006079 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006080 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006081 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006082 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006083
Douglas Gregorebe10102009-08-20 07:17:43 +00006084 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006085 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006086 }
Mike Stump11289f42009-09-09 15:08:12 +00006087
David Majnemer5f7efef2013-10-15 09:50:08 +00006088 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006089 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006090 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006091
John McCallb268a282010-08-23 23:25:46 +00006092 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006093 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
Richard Smith02e85f32011-04-14 22:09:26 +00006096template<typename Derived>
6097StmtResult
6098TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6099 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6100 if (Range.isInvalid())
6101 return StmtError();
6102
6103 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6104 if (BeginEnd.isInvalid())
6105 return StmtError();
6106
6107 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6108 if (Cond.isInvalid())
6109 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006110 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006111 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006112 if (Cond.isInvalid())
6113 return StmtError();
6114 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006115 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006116
6117 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6118 if (Inc.isInvalid())
6119 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006120 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006121 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006122
6123 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6124 if (LoopVar.isInvalid())
6125 return StmtError();
6126
6127 StmtResult NewStmt = S;
6128 if (getDerived().AlwaysRebuild() ||
6129 Range.get() != S->getRangeStmt() ||
6130 BeginEnd.get() != S->getBeginEndStmt() ||
6131 Cond.get() != S->getCond() ||
6132 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006133 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006134 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6135 S->getColonLoc(), Range.get(),
6136 BeginEnd.get(), Cond.get(),
6137 Inc.get(), LoopVar.get(),
6138 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006139 if (NewStmt.isInvalid())
6140 return StmtError();
6141 }
Richard Smith02e85f32011-04-14 22:09:26 +00006142
6143 StmtResult Body = getDerived().TransformStmt(S->getBody());
6144 if (Body.isInvalid())
6145 return StmtError();
6146
6147 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6148 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006149 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006150 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6151 S->getColonLoc(), Range.get(),
6152 BeginEnd.get(), Cond.get(),
6153 Inc.get(), LoopVar.get(),
6154 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006155 if (NewStmt.isInvalid())
6156 return StmtError();
6157 }
Richard Smith02e85f32011-04-14 22:09:26 +00006158
6159 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006160 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006161
6162 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6163}
6164
John Wiegley1c0675e2011-04-28 01:08:34 +00006165template<typename Derived>
6166StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006167TreeTransform<Derived>::TransformMSDependentExistsStmt(
6168 MSDependentExistsStmt *S) {
6169 // Transform the nested-name-specifier, if any.
6170 NestedNameSpecifierLoc QualifierLoc;
6171 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006172 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006173 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6174 if (!QualifierLoc)
6175 return StmtError();
6176 }
6177
6178 // Transform the declaration name.
6179 DeclarationNameInfo NameInfo = S->getNameInfo();
6180 if (NameInfo.getName()) {
6181 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6182 if (!NameInfo.getName())
6183 return StmtError();
6184 }
6185
6186 // Check whether anything changed.
6187 if (!getDerived().AlwaysRebuild() &&
6188 QualifierLoc == S->getQualifierLoc() &&
6189 NameInfo.getName() == S->getNameInfo().getName())
6190 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006191
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006192 // Determine whether this name exists, if we can.
6193 CXXScopeSpec SS;
6194 SS.Adopt(QualifierLoc);
6195 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006196 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006197 case Sema::IER_Exists:
6198 if (S->isIfExists())
6199 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006201 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6202
6203 case Sema::IER_DoesNotExist:
6204 if (S->isIfNotExists())
6205 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006206
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006207 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006208
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006209 case Sema::IER_Dependent:
6210 Dependent = true;
6211 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006212
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006213 case Sema::IER_Error:
6214 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006216
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006217 // We need to continue with the instantiation, so do so now.
6218 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6219 if (SubStmt.isInvalid())
6220 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006221
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006222 // If we have resolved the name, just transform to the substatement.
6223 if (!Dependent)
6224 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006226 // The name is still dependent, so build a dependent expression again.
6227 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6228 S->isIfExists(),
6229 QualifierLoc,
6230 NameInfo,
6231 SubStmt.get());
6232}
6233
6234template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006235ExprResult
6236TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6237 NestedNameSpecifierLoc QualifierLoc;
6238 if (E->getQualifierLoc()) {
6239 QualifierLoc
6240 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6241 if (!QualifierLoc)
6242 return ExprError();
6243 }
6244
6245 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6246 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6247 if (!PD)
6248 return ExprError();
6249
6250 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6251 if (Base.isInvalid())
6252 return ExprError();
6253
6254 return new (SemaRef.getASTContext())
6255 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6256 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6257 QualifierLoc, E->getMemberLoc());
6258}
6259
David Majnemerfad8f482013-10-15 09:33:02 +00006260template <typename Derived>
6261StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006262 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006263 if (TryBlock.isInvalid())
6264 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006265
6266 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006267 if (Handler.isInvalid())
6268 return StmtError();
6269
David Majnemerfad8f482013-10-15 09:33:02 +00006270 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6271 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006272 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006273
David Majnemerfad8f482013-10-15 09:33:02 +00006274 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006275 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006276}
6277
David Majnemerfad8f482013-10-15 09:33:02 +00006278template <typename Derived>
6279StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006280 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006281 if (Block.isInvalid())
6282 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006283
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006284 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006285}
6286
David Majnemerfad8f482013-10-15 09:33:02 +00006287template <typename Derived>
6288StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006289 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006290 if (FilterExpr.isInvalid())
6291 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006292
David Majnemer7e755502013-10-15 09:30:14 +00006293 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006294 if (Block.isInvalid())
6295 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006296
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006297 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6298 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006299}
6300
David Majnemerfad8f482013-10-15 09:33:02 +00006301template <typename Derived>
6302StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6303 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006304 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6305 else
6306 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6307}
6308
Alexander Musman64d33f12014-06-04 07:53:32 +00006309//===----------------------------------------------------------------------===//
6310// OpenMP directive transformation
6311//===----------------------------------------------------------------------===//
6312template <typename Derived>
6313StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6314 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006315
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006316 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006317 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006318 ArrayRef<OMPClause *> Clauses = D->clauses();
6319 TClauses.reserve(Clauses.size());
6320 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6321 I != E; ++I) {
6322 if (*I) {
6323 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006324 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006325 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006326 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006327 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006328 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006329 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006330 }
6331 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006332 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006333 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006334 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006335 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006336 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006337 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006338 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006339 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006340
Alexander Musman64d33f12014-06-04 07:53:32 +00006341 return getDerived().RebuildOMPExecutableDirective(
6342 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6343 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006344}
6345
Alexander Musman64d33f12014-06-04 07:53:32 +00006346template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006347StmtResult
6348TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6349 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006350 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6353 return Res;
6354}
6355
Alexander Musman64d33f12014-06-04 07:53:32 +00006356template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006357StmtResult
6358TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6359 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006360 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006361 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6362 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006363 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006364}
6365
Alexander Musman64d33f12014-06-04 07:53:32 +00006366//===----------------------------------------------------------------------===//
6367// OpenMP clause transformation
6368//===----------------------------------------------------------------------===//
6369template <typename Derived>
6370OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006371 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6372 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006373 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006374 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006375 C->getLParenLoc(), C->getLocEnd());
6376}
6377
Alexander Musman64d33f12014-06-04 07:53:32 +00006378template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006379OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006380TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6381 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6382 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006383 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006384 return getDerived().RebuildOMPNumThreadsClause(
6385 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006386}
6387
Alexey Bataev62c87d22014-03-21 04:51:18 +00006388template <typename Derived>
6389OMPClause *
6390TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6391 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6392 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006393 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006394 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006395 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006396}
6397
Alexander Musman8bd31e62014-05-27 15:12:19 +00006398template <typename Derived>
6399OMPClause *
6400TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6401 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6402 if (E.isInvalid())
6403 return 0;
6404 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006405 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006406}
6407
Alexander Musman64d33f12014-06-04 07:53:32 +00006408template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006409OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006410TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006411 return getDerived().RebuildOMPDefaultClause(
6412 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6413 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006414}
6415
Alexander Musman64d33f12014-06-04 07:53:32 +00006416template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006417OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006418TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006419 return getDerived().RebuildOMPProcBindClause(
6420 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6421 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006422}
6423
Alexander Musman64d33f12014-06-04 07:53:32 +00006424template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006425OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006426TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006427 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006428 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006429 for (auto *VE : C->varlists()) {
6430 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006431 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006432 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006433 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006434 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006435 return getDerived().RebuildOMPPrivateClause(
6436 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006437}
6438
Alexander Musman64d33f12014-06-04 07:53:32 +00006439template <typename Derived>
6440OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6441 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006442 llvm::SmallVector<Expr *, 16> Vars;
6443 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006444 for (auto *VE : C->varlists()) {
6445 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006446 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006447 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006448 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006449 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006450 return getDerived().RebuildOMPFirstprivateClause(
6451 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006452}
6453
Alexander Musman64d33f12014-06-04 07:53:32 +00006454template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006455OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006456TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6457 llvm::SmallVector<Expr *, 16> Vars;
6458 Vars.reserve(C->varlist_size());
6459 for (auto *VE : C->varlists()) {
6460 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6461 if (EVar.isInvalid())
6462 return nullptr;
6463 Vars.push_back(EVar.get());
6464 }
6465 return getDerived().RebuildOMPLastprivateClause(
6466 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6467}
6468
6469template <typename Derived>
6470OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006471TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6472 llvm::SmallVector<Expr *, 16> Vars;
6473 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006474 for (auto *VE : C->varlists()) {
6475 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006476 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006477 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006478 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006479 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006480 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6481 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006482}
6483
Alexander Musman64d33f12014-06-04 07:53:32 +00006484template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006485OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006486TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6487 llvm::SmallVector<Expr *, 16> Vars;
6488 Vars.reserve(C->varlist_size());
6489 for (auto *VE : C->varlists()) {
6490 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6491 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006492 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006493 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006494 }
6495 ExprResult Step = getDerived().TransformExpr(C->getStep());
6496 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006497 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006498 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6499 C->getLParenLoc(),
6500 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006501}
6502
Alexander Musman64d33f12014-06-04 07:53:32 +00006503template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006504OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006505TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6506 llvm::SmallVector<Expr *, 16> Vars;
6507 Vars.reserve(C->varlist_size());
6508 for (auto *VE : C->varlists()) {
6509 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6510 if (EVar.isInvalid())
6511 return nullptr;
6512 Vars.push_back(EVar.get());
6513 }
6514 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6515 if (Alignment.isInvalid())
6516 return nullptr;
6517 return getDerived().RebuildOMPAlignedClause(
6518 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6519 C->getColonLoc(), C->getLocEnd());
6520}
6521
Alexander Musman64d33f12014-06-04 07:53:32 +00006522template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006523OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006524TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6525 llvm::SmallVector<Expr *, 16> Vars;
6526 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006527 for (auto *VE : C->varlists()) {
6528 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006529 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006530 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006531 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006532 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006533 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6534 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006535}
6536
Douglas Gregorebe10102009-08-20 07:17:43 +00006537//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006538// Expression transformation
6539//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006542TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006543 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006544}
Mike Stump11289f42009-09-09 15:08:12 +00006545
6546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006549 NestedNameSpecifierLoc QualifierLoc;
6550 if (E->getQualifierLoc()) {
6551 QualifierLoc
6552 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6553 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006555 }
John McCallce546572009-12-08 09:08:17 +00006556
6557 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006558 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6559 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006560 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006562
John McCall815039a2010-08-17 21:27:17 +00006563 DeclarationNameInfo NameInfo = E->getNameInfo();
6564 if (NameInfo.getName()) {
6565 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6566 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006567 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006568 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006569
6570 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006571 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006572 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006573 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006574 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006575
6576 // Mark it referenced in the new context regardless.
6577 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006578 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006579
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006580 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006581 }
John McCallce546572009-12-08 09:08:17 +00006582
Craig Topperc3ec1492014-05-26 06:22:03 +00006583 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006584 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006585 TemplateArgs = &TransArgs;
6586 TransArgs.setLAngleLoc(E->getLAngleLoc());
6587 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006588 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6589 E->getNumTemplateArgs(),
6590 TransArgs))
6591 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006592 }
6593
Chad Rosier1dcde962012-08-08 18:46:20 +00006594 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006595 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006596}
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregora16548e2009-08-11 05:31:07 +00006598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006601 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006602}
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregora16548e2009-08-11 05:31:07 +00006604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006606TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006607 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006608}
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregora16548e2009-08-11 05:31:07 +00006610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006612TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006613 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006614}
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregora16548e2009-08-11 05:31:07 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006619 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006620}
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregora16548e2009-08-11 05:31:07 +00006622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006625 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006626}
6627
6628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006629ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006630TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006631 if (FunctionDecl *FD = E->getDirectCallee())
6632 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006633 return SemaRef.MaybeBindToTemporary(E);
6634}
6635
6636template<typename Derived>
6637ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006638TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6639 ExprResult ControllingExpr =
6640 getDerived().TransformExpr(E->getControllingExpr());
6641 if (ControllingExpr.isInvalid())
6642 return ExprError();
6643
Chris Lattner01cf8db2011-07-20 06:58:45 +00006644 SmallVector<Expr *, 4> AssocExprs;
6645 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006646 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6647 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6648 if (TS) {
6649 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6650 if (!AssocType)
6651 return ExprError();
6652 AssocTypes.push_back(AssocType);
6653 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006654 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006655 }
6656
6657 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6658 if (AssocExpr.isInvalid())
6659 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006660 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006661 }
6662
6663 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6664 E->getDefaultLoc(),
6665 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006666 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006667 AssocTypes,
6668 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006669}
6670
6671template<typename Derived>
6672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006673TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006674 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006679 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006680
John McCallb268a282010-08-23 23:25:46 +00006681 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 E->getRParen());
6683}
6684
Richard Smithdb2630f2012-10-21 03:28:35 +00006685/// \brief The operand of a unary address-of operator has special rules: it's
6686/// allowed to refer to a non-static member of a class even if there's no 'this'
6687/// object available.
6688template<typename Derived>
6689ExprResult
6690TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6691 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6692 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6693 else
6694 return getDerived().TransformExpr(E);
6695}
6696
Mike Stump11289f42009-09-09 15:08:12 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006699TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006700 ExprResult SubExpr;
6701 if (E->getOpcode() == UO_AddrOf)
6702 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6703 else
6704 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006709 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregora16548e2009-08-11 05:31:07 +00006711 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6712 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006713 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006714}
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregora16548e2009-08-11 05:31:07 +00006716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006717ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006718TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6719 // Transform the type.
6720 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6721 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006722 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006723
Douglas Gregor882211c2010-04-28 22:16:22 +00006724 // Transform all of the components into components similar to what the
6725 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006726 // FIXME: It would be slightly more efficient in the non-dependent case to
6727 // just map FieldDecls, rather than requiring the rebuilder to look for
6728 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006729 // template code that we don't care.
6730 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006731 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006732 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006733 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006734 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6735 const Node &ON = E->getComponent(I);
6736 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006737 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006738 Comp.LocStart = ON.getSourceRange().getBegin();
6739 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006740 switch (ON.getKind()) {
6741 case Node::Array: {
6742 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006743 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006744 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006745 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006746
Douglas Gregor882211c2010-04-28 22:16:22 +00006747 ExprChanged = ExprChanged || Index.get() != FromIndex;
6748 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006749 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006750 break;
6751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006752
Douglas Gregor882211c2010-04-28 22:16:22 +00006753 case Node::Field:
6754 case Node::Identifier:
6755 Comp.isBrackets = false;
6756 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006757 if (!Comp.U.IdentInfo)
6758 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
Douglas Gregor882211c2010-04-28 22:16:22 +00006760 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006761
Douglas Gregord1702062010-04-29 00:18:15 +00006762 case Node::Base:
6763 // Will be recomputed during the rebuild.
6764 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
Douglas Gregor882211c2010-04-28 22:16:22 +00006767 Components.push_back(Comp);
6768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Douglas Gregor882211c2010-04-28 22:16:22 +00006770 // If nothing changed, retain the existing expression.
6771 if (!getDerived().AlwaysRebuild() &&
6772 Type == E->getTypeSourceInfo() &&
6773 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006774 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Douglas Gregor882211c2010-04-28 22:16:22 +00006776 // Build a new offsetof expression.
6777 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6778 Components.data(), Components.size(),
6779 E->getRParenLoc());
6780}
6781
6782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006783ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006784TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6785 assert(getDerived().AlreadyTransformed(E->getType()) &&
6786 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006787 return E;
John McCall8d69a212010-11-15 23:31:06 +00006788}
6789
6790template<typename Derived>
6791ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006792TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006793 // Rebuild the syntactic form. The original syntactic form has
6794 // opaque-value expressions in it, so strip those away and rebuild
6795 // the result. This is a really awful way of doing this, but the
6796 // better solution (rebuilding the semantic expressions and
6797 // rebinding OVEs as necessary) doesn't work; we'd need
6798 // TreeTransform to not strip away implicit conversions.
6799 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6800 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006801 if (result.isInvalid()) return ExprError();
6802
6803 // If that gives us a pseudo-object result back, the pseudo-object
6804 // expression must have been an lvalue-to-rvalue conversion which we
6805 // should reapply.
6806 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006807 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006808
6809 return result;
6810}
6811
6812template<typename Derived>
6813ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006814TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6815 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006816 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006817 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006818
John McCallbcd03502009-12-07 02:54:59 +00006819 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006820 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006822
John McCall4c98fd82009-11-04 07:28:41 +00006823 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006824 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006825
Peter Collingbournee190dee2011-03-11 19:24:49 +00006826 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6827 E->getKind(),
6828 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 }
Mike Stump11289f42009-09-09 15:08:12 +00006830
Eli Friedmane4f22df2012-02-29 04:03:55 +00006831 // C++0x [expr.sizeof]p1:
6832 // The operand is either an expression, which is an unevaluated operand
6833 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006834 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6835 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006836
Eli Friedmane4f22df2012-02-29 04:03:55 +00006837 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6838 if (SubExpr.isInvalid())
6839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006840
Eli Friedmane4f22df2012-02-29 04:03:55 +00006841 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006842 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006843
Peter Collingbournee190dee2011-03-11 19:24:49 +00006844 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6845 E->getOperatorLoc(),
6846 E->getKind(),
6847 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006848}
Mike Stump11289f42009-09-09 15:08:12 +00006849
Douglas Gregora16548e2009-08-11 05:31:07 +00006850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006853 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006854 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006856
John McCalldadc5752010-08-24 06:29:42 +00006857 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006858 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
6861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (!getDerived().AlwaysRebuild() &&
6863 LHS.get() == E->getLHS() &&
6864 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006865 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006866
John McCallb268a282010-08-23 23:25:46 +00006867 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006868 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006869 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 E->getRBracketLoc());
6871}
Mike Stump11289f42009-09-09 15:08:12 +00006872
6873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006874ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006875TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006877 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006878 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006880
6881 // Transform arguments.
6882 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006883 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006884 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006885 &ArgChanged))
6886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006887
Douglas Gregora16548e2009-08-11 05:31:07 +00006888 if (!getDerived().AlwaysRebuild() &&
6889 Callee.get() == E->getCallee() &&
6890 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006891 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006892
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006894 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006895 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006896 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006897 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 E->getRParenLoc());
6899}
Mike Stump11289f42009-09-09 15:08:12 +00006900
6901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006902ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006903TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006904 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006907
Douglas Gregorea972d32011-02-28 21:54:11 +00006908 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006909 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006910 QualifierLoc
6911 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006912
Douglas Gregorea972d32011-02-28 21:54:11 +00006913 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006914 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006915 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006916 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006917
Eli Friedman2cfcef62009-12-04 06:40:45 +00006918 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006919 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6920 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006923
John McCall16df1e52010-03-30 21:47:33 +00006924 NamedDecl *FoundDecl = E->getFoundDecl();
6925 if (FoundDecl == E->getMemberDecl()) {
6926 FoundDecl = Member;
6927 } else {
6928 FoundDecl = cast_or_null<NamedDecl>(
6929 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6930 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006932 }
6933
Douglas Gregora16548e2009-08-11 05:31:07 +00006934 if (!getDerived().AlwaysRebuild() &&
6935 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006936 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006937 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006938 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006939 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006940
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006941 // Mark it referenced in the new context regardless.
6942 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006943 SemaRef.MarkMemberReferenced(E);
6944
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006945 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006946 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006947
John McCall6b51f282009-11-23 01:53:49 +00006948 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006949 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006950 TransArgs.setLAngleLoc(E->getLAngleLoc());
6951 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006952 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6953 E->getNumTemplateArgs(),
6954 TransArgs))
6955 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006957
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006959 SourceLocation FakeOperatorLoc =
6960 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006961
John McCall38836f02010-01-15 08:34:02 +00006962 // FIXME: to do this check properly, we will need to preserve the
6963 // first-qualifier-in-scope here, just in case we had a dependent
6964 // base (and therefore couldn't do the check) and a
6965 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00006966 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00006967
John McCallb268a282010-08-23 23:25:46 +00006968 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006970 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006971 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006972 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006973 Member,
John McCall16df1e52010-03-30 21:47:33 +00006974 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006975 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00006976 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00006977 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006978}
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregora16548e2009-08-11 05:31:07 +00006980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006983 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006984 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006986
John McCalldadc5752010-08-24 06:29:42 +00006987 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006990
Douglas Gregora16548e2009-08-11 05:31:07 +00006991 if (!getDerived().AlwaysRebuild() &&
6992 LHS.get() == E->getLHS() &&
6993 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006994 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006995
Lang Hames5de91cc2012-10-02 04:45:10 +00006996 Sema::FPContractStateRAII FPContractState(getSema());
6997 getSema().FPFeatures.fp_contract = E->isFPContractable();
6998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007000 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007001}
7002
Mike Stump11289f42009-09-09 15:08:12 +00007003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007004ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007005TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007006 CompoundAssignOperator *E) {
7007 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007008}
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregora16548e2009-08-11 05:31:07 +00007010template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007011ExprResult TreeTransform<Derived>::
7012TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7013 // Just rebuild the common and RHS expressions and see whether we
7014 // get any changes.
7015
7016 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7017 if (commonExpr.isInvalid())
7018 return ExprError();
7019
7020 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7021 if (rhs.isInvalid())
7022 return ExprError();
7023
7024 if (!getDerived().AlwaysRebuild() &&
7025 commonExpr.get() == e->getCommon() &&
7026 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007027 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007028
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007029 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007030 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007031 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007032 e->getColonLoc(),
7033 rhs.get());
7034}
7035
7036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007039 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007042
John McCalldadc5752010-08-24 06:29:42 +00007043 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007044 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007046
John McCalldadc5752010-08-24 06:29:42 +00007047 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007050
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 if (!getDerived().AlwaysRebuild() &&
7052 Cond.get() == E->getCond() &&
7053 LHS.get() == E->getLHS() &&
7054 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007055 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007056
John McCallb268a282010-08-23 23:25:46 +00007057 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007058 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007059 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007060 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007061 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007062}
Mike Stump11289f42009-09-09 15:08:12 +00007063
7064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007066TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007067 // Implicit casts are eliminated during transformation, since they
7068 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007069 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007070}
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregora16548e2009-08-11 05:31:07 +00007072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007074TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007075 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7076 if (!Type)
7077 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007078
John McCalldadc5752010-08-24 06:29:42 +00007079 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007080 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007083
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007085 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007086 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007087 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007088
John McCall97513962010-01-15 18:39:57 +00007089 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007090 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007091 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007092 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007093}
Mike Stump11289f42009-09-09 15:08:12 +00007094
Douglas Gregora16548e2009-08-11 05:31:07 +00007095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007097TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007098 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7099 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7100 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007102
John McCalldadc5752010-08-24 06:29:42 +00007103 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007106
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007108 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007110 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007111
John McCall5d7aa7f2010-01-19 22:33:45 +00007112 // Note: the expression type doesn't necessarily match the
7113 // type-as-written, but that's okay, because it should always be
7114 // derivable from the initializer.
7115
John McCalle15bbff2010-01-18 19:35:47 +00007116 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007118 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007119}
Mike Stump11289f42009-09-09 15:08:12 +00007120
Douglas Gregora16548e2009-08-11 05:31:07 +00007121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007124 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 if (!getDerived().AlwaysRebuild() &&
7129 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007130 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007133 SourceLocation FakeOperatorLoc =
7134 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007135 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 E->getAccessorLoc(),
7137 E->getAccessor());
7138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregora16548e2009-08-11 05:31:07 +00007140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007144
Benjamin Kramerf0623432012-08-23 22:51:59 +00007145 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007146 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007147 Inits, &InitChanged))
7148 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007149
Douglas Gregora16548e2009-08-11 05:31:07 +00007150 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007151 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007152
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007153 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007154 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007155}
Mike Stump11289f42009-09-09 15:08:12 +00007156
Douglas Gregora16548e2009-08-11 05:31:07 +00007157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007161
Douglas Gregorebe10102009-08-20 07:17:43 +00007162 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007163 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007164 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007166
Douglas Gregorebe10102009-08-20 07:17:43 +00007167 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007168 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 bool ExprChanged = false;
7170 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7171 DEnd = E->designators_end();
7172 D != DEnd; ++D) {
7173 if (D->isFieldDesignator()) {
7174 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7175 D->getDotLoc(),
7176 D->getFieldLoc()));
7177 continue;
7178 }
Mike Stump11289f42009-09-09 15:08:12 +00007179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007181 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007182 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007184
7185 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007187
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007189 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 continue;
7191 }
Mike Stump11289f42009-09-09 15:08:12 +00007192
Douglas Gregora16548e2009-08-11 05:31:07 +00007193 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007194 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007195 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7196 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007198
John McCalldadc5752010-08-24 06:29:42 +00007199 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007202
7203 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 End.get(),
7205 D->getLBracketLoc(),
7206 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007207
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7209 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007210
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007211 ArrayExprs.push_back(Start.get());
7212 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007213 }
Mike Stump11289f42009-09-09 15:08:12 +00007214
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 if (!getDerived().AlwaysRebuild() &&
7216 Init.get() == E->getInit() &&
7217 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007218 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007219
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007220 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007221 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007222 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223}
Mike Stump11289f42009-09-09 15:08:12 +00007224
Douglas Gregora16548e2009-08-11 05:31:07 +00007225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007226ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007227TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007228 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007229 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007230
Douglas Gregor3da3c062009-10-28 00:29:27 +00007231 // FIXME: Will we ever have proper type location here? Will we actually
7232 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007233 QualType T = getDerived().TransformType(E->getType());
7234 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 if (!getDerived().AlwaysRebuild() &&
7238 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007239 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007240
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 return getDerived().RebuildImplicitValueInitExpr(T);
7242}
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007246TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007247 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7248 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007250
John McCalldadc5752010-08-24 06:29:42 +00007251 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007252 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007253 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007254
Douglas Gregora16548e2009-08-11 05:31:07 +00007255 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007256 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007257 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007258 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007259
John McCallb268a282010-08-23 23:25:46 +00007260 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007261 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007262}
7263
7264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007266TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007267 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007268 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007269 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7270 &ArgumentChanged))
7271 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007272
Douglas Gregora16548e2009-08-11 05:31:07 +00007273 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007274 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007275 E->getRParenLoc());
7276}
Mike Stump11289f42009-09-09 15:08:12 +00007277
Douglas Gregora16548e2009-08-11 05:31:07 +00007278/// \brief Transform an address-of-label expression.
7279///
7280/// By default, the transformation of an address-of-label expression always
7281/// rebuilds the expression, so that the label identifier can be resolved to
7282/// the corresponding label statement by semantic analysis.
7283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007284ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007285TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007286 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7287 E->getLabel());
7288 if (!LD)
7289 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007290
Douglas Gregora16548e2009-08-11 05:31:07 +00007291 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007292 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007293}
Mike Stump11289f42009-09-09 15:08:12 +00007294
7295template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007297TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007298 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007299 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007301 if (SubStmt.isInvalid()) {
7302 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007303 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007304 }
Mike Stump11289f42009-09-09 15:08:12 +00007305
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007307 SubStmt.get() == E->getSubStmt()) {
7308 // Calling this an 'error' is unintuitive, but it does the right thing.
7309 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007310 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007311 }
Mike Stump11289f42009-09-09 15:08:12 +00007312
7313 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007314 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007315 E->getRParenLoc());
7316}
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregora16548e2009-08-11 05:31:07 +00007318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007320TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007321 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007322 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007324
John McCalldadc5752010-08-24 06:29:42 +00007325 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007326 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007328
John McCalldadc5752010-08-24 06:29:42 +00007329 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007332
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 if (!getDerived().AlwaysRebuild() &&
7334 Cond.get() == E->getCond() &&
7335 LHS.get() == E->getLHS() &&
7336 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007337 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregora16548e2009-08-11 05:31:07 +00007339 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007340 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007341 E->getRParenLoc());
7342}
Mike Stump11289f42009-09-09 15:08:12 +00007343
Douglas Gregora16548e2009-08-11 05:31:07 +00007344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007346TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007347 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007348}
7349
7350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007352TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007353 switch (E->getOperator()) {
7354 case OO_New:
7355 case OO_Delete:
7356 case OO_Array_New:
7357 case OO_Array_Delete:
7358 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007359
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007360 case OO_Call: {
7361 // This is a call to an object's operator().
7362 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7363
7364 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007365 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007366 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007367 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007368
7369 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007370 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7371 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007372
7373 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007374 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007375 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007376 Args))
7377 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007378
John McCallb268a282010-08-23 23:25:46 +00007379 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007380 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007381 E->getLocEnd());
7382 }
7383
7384#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7385 case OO_##Name:
7386#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7387#include "clang/Basic/OperatorKinds.def"
7388 case OO_Subscript:
7389 // Handled below.
7390 break;
7391
7392 case OO_Conditional:
7393 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007394
7395 case OO_None:
7396 case NUM_OVERLOADED_OPERATORS:
7397 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007398 }
7399
John McCalldadc5752010-08-24 06:29:42 +00007400 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007403
Richard Smithdb2630f2012-10-21 03:28:35 +00007404 ExprResult First;
7405 if (E->getOperator() == OO_Amp)
7406 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7407 else
7408 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007409 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007410 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007411
John McCalldadc5752010-08-24 06:29:42 +00007412 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 if (E->getNumArgs() == 2) {
7414 Second = getDerived().TransformExpr(E->getArg(1));
7415 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007416 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 }
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregora16548e2009-08-11 05:31:07 +00007419 if (!getDerived().AlwaysRebuild() &&
7420 Callee.get() == E->getCallee() &&
7421 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007422 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007423 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007424
Lang Hames5de91cc2012-10-02 04:45:10 +00007425 Sema::FPContractStateRAII FPContractState(getSema());
7426 getSema().FPFeatures.fp_contract = E->isFPContractable();
7427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7429 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007430 Callee.get(),
7431 First.get(),
7432 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007433}
Mike Stump11289f42009-09-09 15:08:12 +00007434
Douglas Gregora16548e2009-08-11 05:31:07 +00007435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007437TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7438 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007439}
Mike Stump11289f42009-09-09 15:08:12 +00007440
Douglas Gregora16548e2009-08-11 05:31:07 +00007441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007442ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007443TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7444 // Transform the callee.
7445 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7446 if (Callee.isInvalid())
7447 return ExprError();
7448
7449 // Transform exec config.
7450 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7451 if (EC.isInvalid())
7452 return ExprError();
7453
7454 // Transform arguments.
7455 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007456 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007457 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007458 &ArgChanged))
7459 return ExprError();
7460
7461 if (!getDerived().AlwaysRebuild() &&
7462 Callee.get() == E->getCallee() &&
7463 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007464 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007465
7466 // FIXME: Wrong source location information for the '('.
7467 SourceLocation FakeLParenLoc
7468 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7469 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007470 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007471 E->getRParenLoc(), EC.get());
7472}
7473
7474template<typename Derived>
7475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007476TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007477 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7478 if (!Type)
7479 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007480
John McCalldadc5752010-08-24 06:29:42 +00007481 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007482 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007483 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007484 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007485
Douglas Gregora16548e2009-08-11 05:31:07 +00007486 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007487 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007488 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007489 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007490 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007491 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007492 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007493 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007494 E->getAngleBrackets().getEnd(),
7495 // FIXME. this should be '(' location
7496 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007497 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007498 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007499}
Mike Stump11289f42009-09-09 15:08:12 +00007500
Douglas Gregora16548e2009-08-11 05:31:07 +00007501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007503TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7504 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007505}
Mike Stump11289f42009-09-09 15:08:12 +00007506
7507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007509TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7510 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007511}
7512
Douglas Gregora16548e2009-08-11 05:31:07 +00007513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007514ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007515TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007516 CXXReinterpretCastExpr *E) {
7517 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007518}
Mike Stump11289f42009-09-09 15:08:12 +00007519
Douglas Gregora16548e2009-08-11 05:31:07 +00007520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007522TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7523 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007524}
Mike Stump11289f42009-09-09 15:08:12 +00007525
Douglas Gregora16548e2009-08-11 05:31:07 +00007526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007527ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007528TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007529 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007530 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7531 if (!Type)
7532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007533
John McCalldadc5752010-08-24 06:29:42 +00007534 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007535 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007537 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007538
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007540 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007542 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007544 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007545 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007546 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 E->getRParenLoc());
7548}
Mike Stump11289f42009-09-09 15:08:12 +00007549
Douglas Gregora16548e2009-08-11 05:31:07 +00007550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007551ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007552TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007554 TypeSourceInfo *TInfo
7555 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7556 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007558
Douglas Gregora16548e2009-08-11 05:31:07 +00007559 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007560 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007561 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007562
Douglas Gregor9da64192010-04-26 22:37:10 +00007563 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7564 E->getLocStart(),
7565 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 E->getLocEnd());
7567 }
Mike Stump11289f42009-09-09 15:08:12 +00007568
Eli Friedman456f0182012-01-20 01:26:23 +00007569 // We don't know whether the subexpression is potentially evaluated until
7570 // after we perform semantic analysis. We speculatively assume it is
7571 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7574 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007575
John McCalldadc5752010-08-24 06:29:42 +00007576 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007579
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 if (!getDerived().AlwaysRebuild() &&
7581 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007582 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007583
Douglas Gregor9da64192010-04-26 22:37:10 +00007584 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7585 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007586 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 E->getLocEnd());
7588}
7589
7590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007591ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007592TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7593 if (E->isTypeOperand()) {
7594 TypeSourceInfo *TInfo
7595 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7596 if (!TInfo)
7597 return ExprError();
7598
7599 if (!getDerived().AlwaysRebuild() &&
7600 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007601 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007602
Douglas Gregor69735112011-03-06 17:40:41 +00007603 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007604 E->getLocStart(),
7605 TInfo,
7606 E->getLocEnd());
7607 }
7608
Francois Pichet9f4f2072010-09-08 12:20:18 +00007609 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7610
7611 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7612 if (SubExpr.isInvalid())
7613 return ExprError();
7614
7615 if (!getDerived().AlwaysRebuild() &&
7616 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007617 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007618
7619 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7620 E->getLocStart(),
7621 SubExpr.get(),
7622 E->getLocEnd());
7623}
7624
7625template<typename Derived>
7626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007627TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007628 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007629}
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007632ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007633TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007634 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007635 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007636}
Mike Stump11289f42009-09-09 15:08:12 +00007637
Douglas Gregora16548e2009-08-11 05:31:07 +00007638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007640TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007641 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007642
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007643 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7644 // Make sure that we capture 'this'.
7645 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007646 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007648
Douglas Gregorb15af892010-01-07 23:12:05 +00007649 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007650}
Mike Stump11289f42009-09-09 15:08:12 +00007651
Douglas Gregora16548e2009-08-11 05:31:07 +00007652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007654TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007655 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007658
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 if (!getDerived().AlwaysRebuild() &&
7660 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007661 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007662
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007663 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7664 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007665}
Mike Stump11289f42009-09-09 15:08:12 +00007666
Douglas Gregora16548e2009-08-11 05:31:07 +00007667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007669TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007670 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007671 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7672 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007673 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007675
Chandler Carruth794da4c2010-02-08 06:42:49 +00007676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007677 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007678 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007679
Douglas Gregor033f6752009-12-23 23:03:06 +00007680 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007681}
Mike Stump11289f42009-09-09 15:08:12 +00007682
Douglas Gregora16548e2009-08-11 05:31:07 +00007683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007684ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007685TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7686 FieldDecl *Field
7687 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7688 E->getField()));
7689 if (!Field)
7690 return ExprError();
7691
7692 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007693 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007694
7695 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7696}
7697
7698template<typename Derived>
7699ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007700TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7701 CXXScalarValueInitExpr *E) {
7702 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7703 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007704 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007705
Douglas Gregora16548e2009-08-11 05:31:07 +00007706 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007707 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007708 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007709
Chad Rosier1dcde962012-08-08 18:46:20 +00007710 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007711 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007712 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007713}
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007717TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007719 TypeSourceInfo *AllocTypeInfo
7720 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7721 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007722 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007725 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007726 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007728
Douglas Gregora16548e2009-08-11 05:31:07 +00007729 // Transform the placement arguments (if any).
7730 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007731 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007732 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007733 E->getNumPlacementArgs(), true,
7734 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007736
Sebastian Redl6047f072012-02-16 12:22:20 +00007737 // Transform the initializer (if any).
7738 Expr *OldInit = E->getInitializer();
7739 ExprResult NewInit;
7740 if (OldInit)
7741 NewInit = getDerived().TransformExpr(OldInit);
7742 if (NewInit.isInvalid())
7743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007744
Sebastian Redl6047f072012-02-16 12:22:20 +00007745 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007746 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007747 if (E->getOperatorNew()) {
7748 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007749 getDerived().TransformDecl(E->getLocStart(),
7750 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007751 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007752 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007753 }
7754
Craig Topperc3ec1492014-05-26 06:22:03 +00007755 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007756 if (E->getOperatorDelete()) {
7757 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007758 getDerived().TransformDecl(E->getLocStart(),
7759 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007760 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007761 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007762 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007763
Douglas Gregora16548e2009-08-11 05:31:07 +00007764 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007765 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007766 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007767 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007768 OperatorNew == E->getOperatorNew() &&
7769 OperatorDelete == E->getOperatorDelete() &&
7770 !ArgumentChanged) {
7771 // Mark any declarations we need as referenced.
7772 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007773 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007774 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007775 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007776 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007777
Sebastian Redl6047f072012-02-16 12:22:20 +00007778 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007779 QualType ElementType
7780 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7781 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7782 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7783 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007784 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007785 }
7786 }
7787 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007788
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007789 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007790 }
Mike Stump11289f42009-09-09 15:08:12 +00007791
Douglas Gregor0744ef62010-09-07 21:49:58 +00007792 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007793 if (!ArraySize.get()) {
7794 // If no array size was specified, but the new expression was
7795 // instantiated with an array type (e.g., "new T" where T is
7796 // instantiated with "int[4]"), extract the outer bound from the
7797 // array type as our array size. We do this with constant and
7798 // dependently-sized array types.
7799 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7800 if (!ArrayT) {
7801 // Do nothing
7802 } else if (const ConstantArrayType *ConsArrayT
7803 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007804 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7805 SemaRef.Context.getSizeType(),
7806 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007807 AllocType = ConsArrayT->getElementType();
7808 } else if (const DependentSizedArrayType *DepArrayT
7809 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7810 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007811 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007812 AllocType = DepArrayT->getElementType();
7813 }
7814 }
7815 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007816
Douglas Gregora16548e2009-08-11 05:31:07 +00007817 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7818 E->isGlobalNew(),
7819 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007820 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007821 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007822 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007824 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007825 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007826 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007827 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007828}
Mike Stump11289f42009-09-09 15:08:12 +00007829
Douglas Gregora16548e2009-08-11 05:31:07 +00007830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007832TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007833 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007834 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007836
Douglas Gregord2d9da02010-02-26 00:38:10 +00007837 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007838 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007839 if (E->getOperatorDelete()) {
7840 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007841 getDerived().TransformDecl(E->getLocStart(),
7842 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007843 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007844 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007846
Douglas Gregora16548e2009-08-11 05:31:07 +00007847 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007848 Operand.get() == E->getArgument() &&
7849 OperatorDelete == E->getOperatorDelete()) {
7850 // Mark any declarations we need as referenced.
7851 // FIXME: instantiation-specific.
7852 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007853 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007854
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007855 if (!E->getArgument()->isTypeDependent()) {
7856 QualType Destroyed = SemaRef.Context.getBaseElementType(
7857 E->getDestroyedType());
7858 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7859 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007860 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007861 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007862 }
7863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007864
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007865 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007866 }
Mike Stump11289f42009-09-09 15:08:12 +00007867
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7869 E->isGlobalDelete(),
7870 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007871 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007872}
Mike Stump11289f42009-09-09 15:08:12 +00007873
Douglas Gregora16548e2009-08-11 05:31:07 +00007874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007875ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007876TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007877 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007878 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007879 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007881
John McCallba7bf592010-08-24 05:47:05 +00007882 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007883 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007884 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007885 E->getOperatorLoc(),
7886 E->isArrow()? tok::arrow : tok::period,
7887 ObjectTypePtr,
7888 MayBePseudoDestructor);
7889 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007890 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007891
John McCallba7bf592010-08-24 05:47:05 +00007892 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007893 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7894 if (QualifierLoc) {
7895 QualifierLoc
7896 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7897 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007898 return ExprError();
7899 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007900 CXXScopeSpec SS;
7901 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007902
Douglas Gregor678f90d2010-02-25 01:56:36 +00007903 PseudoDestructorTypeStorage Destroyed;
7904 if (E->getDestroyedTypeInfo()) {
7905 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007906 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007907 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007908 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007909 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007910 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007911 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007912 // We aren't likely to be able to resolve the identifier down to a type
7913 // now anyway, so just retain the identifier.
7914 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7915 E->getDestroyedTypeLoc());
7916 } else {
7917 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007918 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007919 *E->getDestroyedTypeIdentifier(),
7920 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007921 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007922 SS, ObjectTypePtr,
7923 false);
7924 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007926
Douglas Gregor678f90d2010-02-25 01:56:36 +00007927 Destroyed
7928 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7929 E->getDestroyedTypeLoc());
7930 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007931
Craig Topperc3ec1492014-05-26 06:22:03 +00007932 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007933 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007934 CXXScopeSpec EmptySS;
7935 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007936 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007937 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007938 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007939 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007940
John McCallb268a282010-08-23 23:25:46 +00007941 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007942 E->getOperatorLoc(),
7943 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007944 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007945 ScopeTypeInfo,
7946 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007947 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007948 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007949}
Mike Stump11289f42009-09-09 15:08:12 +00007950
Douglas Gregorad8a3362009-09-04 17:36:40 +00007951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007952ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007953TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007954 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007955 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7956 Sema::LookupOrdinaryName);
7957
7958 // Transform all the decls.
7959 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7960 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007961 NamedDecl *InstD = static_cast<NamedDecl*>(
7962 getDerived().TransformDecl(Old->getNameLoc(),
7963 *I));
John McCall84d87672009-12-10 09:41:52 +00007964 if (!InstD) {
7965 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7966 // This can happen because of dependent hiding.
7967 if (isa<UsingShadowDecl>(*I))
7968 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007969 else {
7970 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007971 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007972 }
John McCall84d87672009-12-10 09:41:52 +00007973 }
John McCalle66edc12009-11-24 19:00:30 +00007974
7975 // Expand using declarations.
7976 if (isa<UsingDecl>(InstD)) {
7977 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007978 for (auto *I : UD->shadows())
7979 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007980 continue;
7981 }
7982
7983 R.addDecl(InstD);
7984 }
7985
7986 // Resolve a kind, but don't do any further analysis. If it's
7987 // ambiguous, the callee needs to deal with it.
7988 R.resolveKind();
7989
7990 // Rebuild the nested-name qualifier, if present.
7991 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007992 if (Old->getQualifierLoc()) {
7993 NestedNameSpecifierLoc QualifierLoc
7994 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7995 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007996 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007997
Douglas Gregor0da1d432011-02-28 20:01:57 +00007998 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007999 }
8000
Douglas Gregor9262f472010-04-27 18:19:34 +00008001 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008002 CXXRecordDecl *NamingClass
8003 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8004 Old->getNameLoc(),
8005 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008006 if (!NamingClass) {
8007 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008008 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008010
Douglas Gregorda7be082010-04-27 16:10:10 +00008011 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008012 }
8013
Abramo Bagnara7945c982012-01-27 09:46:47 +00008014 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8015
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008016 // If we have neither explicit template arguments, nor the template keyword,
8017 // it's a normal declaration name.
8018 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008019 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8020
8021 // If we have template arguments, rebuild them, then rebuild the
8022 // templateid expression.
8023 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008024 if (Old->hasExplicitTemplateArgs() &&
8025 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008026 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008027 TransArgs)) {
8028 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008029 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008030 }
John McCalle66edc12009-11-24 19:00:30 +00008031
Abramo Bagnara7945c982012-01-27 09:46:47 +00008032 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008033 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008034}
Mike Stump11289f42009-09-09 15:08:12 +00008035
Douglas Gregora16548e2009-08-11 05:31:07 +00008036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008037ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008038TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8039 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008040 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008041 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8042 TypeSourceInfo *From = E->getArg(I);
8043 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008044 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008045 TypeLocBuilder TLB;
8046 TLB.reserve(FromTL.getFullDataSize());
8047 QualType To = getDerived().TransformType(TLB, FromTL);
8048 if (To.isNull())
8049 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008050
Douglas Gregor29c42f22012-02-24 07:38:34 +00008051 if (To == From->getType())
8052 Args.push_back(From);
8053 else {
8054 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8055 ArgChanged = true;
8056 }
8057 continue;
8058 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008059
Douglas Gregor29c42f22012-02-24 07:38:34 +00008060 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008061
Douglas Gregor29c42f22012-02-24 07:38:34 +00008062 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008063 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008064 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8065 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8066 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008067
Douglas Gregor29c42f22012-02-24 07:38:34 +00008068 // Determine whether the set of unexpanded parameter packs can and should
8069 // be expanded.
8070 bool Expand = true;
8071 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008072 Optional<unsigned> OrigNumExpansions =
8073 ExpansionTL.getTypePtr()->getNumExpansions();
8074 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008075 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8076 PatternTL.getSourceRange(),
8077 Unexpanded,
8078 Expand, RetainExpansion,
8079 NumExpansions))
8080 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008081
Douglas Gregor29c42f22012-02-24 07:38:34 +00008082 if (!Expand) {
8083 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008084 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008085 // expansion.
8086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008087
Douglas Gregor29c42f22012-02-24 07:38:34 +00008088 TypeLocBuilder TLB;
8089 TLB.reserve(From->getTypeLoc().getFullDataSize());
8090
8091 QualType To = getDerived().TransformType(TLB, PatternTL);
8092 if (To.isNull())
8093 return ExprError();
8094
Chad Rosier1dcde962012-08-08 18:46:20 +00008095 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008096 PatternTL.getSourceRange(),
8097 ExpansionTL.getEllipsisLoc(),
8098 NumExpansions);
8099 if (To.isNull())
8100 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008101
Douglas Gregor29c42f22012-02-24 07:38:34 +00008102 PackExpansionTypeLoc ToExpansionTL
8103 = TLB.push<PackExpansionTypeLoc>(To);
8104 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8105 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8106 continue;
8107 }
8108
8109 // Expand the pack expansion by substituting for each argument in the
8110 // pack(s).
8111 for (unsigned I = 0; I != *NumExpansions; ++I) {
8112 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8113 TypeLocBuilder TLB;
8114 TLB.reserve(PatternTL.getFullDataSize());
8115 QualType To = getDerived().TransformType(TLB, PatternTL);
8116 if (To.isNull())
8117 return ExprError();
8118
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008119 if (To->containsUnexpandedParameterPack()) {
8120 To = getDerived().RebuildPackExpansionType(To,
8121 PatternTL.getSourceRange(),
8122 ExpansionTL.getEllipsisLoc(),
8123 NumExpansions);
8124 if (To.isNull())
8125 return ExprError();
8126
8127 PackExpansionTypeLoc ToExpansionTL
8128 = TLB.push<PackExpansionTypeLoc>(To);
8129 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8130 }
8131
Douglas Gregor29c42f22012-02-24 07:38:34 +00008132 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008134
Douglas Gregor29c42f22012-02-24 07:38:34 +00008135 if (!RetainExpansion)
8136 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008137
Douglas Gregor29c42f22012-02-24 07:38:34 +00008138 // If we're supposed to retain a pack expansion, do so by temporarily
8139 // forgetting the partially-substituted parameter pack.
8140 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8141
8142 TypeLocBuilder TLB;
8143 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008144
Douglas Gregor29c42f22012-02-24 07:38:34 +00008145 QualType To = getDerived().TransformType(TLB, PatternTL);
8146 if (To.isNull())
8147 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008148
8149 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008150 PatternTL.getSourceRange(),
8151 ExpansionTL.getEllipsisLoc(),
8152 NumExpansions);
8153 if (To.isNull())
8154 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008155
Douglas Gregor29c42f22012-02-24 07:38:34 +00008156 PackExpansionTypeLoc ToExpansionTL
8157 = TLB.push<PackExpansionTypeLoc>(To);
8158 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8159 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8160 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008161
Douglas Gregor29c42f22012-02-24 07:38:34 +00008162 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008163 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008164
8165 return getDerived().RebuildTypeTrait(E->getTrait(),
8166 E->getLocStart(),
8167 Args,
8168 E->getLocEnd());
8169}
8170
8171template<typename Derived>
8172ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008173TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8174 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8175 if (!T)
8176 return ExprError();
8177
8178 if (!getDerived().AlwaysRebuild() &&
8179 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008180 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008181
8182 ExprResult SubExpr;
8183 {
8184 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8185 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8186 if (SubExpr.isInvalid())
8187 return ExprError();
8188
8189 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008190 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008191 }
8192
8193 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8194 E->getLocStart(),
8195 T,
8196 SubExpr.get(),
8197 E->getLocEnd());
8198}
8199
8200template<typename Derived>
8201ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008202TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8203 ExprResult SubExpr;
8204 {
8205 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8206 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8207 if (SubExpr.isInvalid())
8208 return ExprError();
8209
8210 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008211 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008212 }
8213
8214 return getDerived().RebuildExpressionTrait(
8215 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8216}
8217
8218template<typename Derived>
8219ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008220TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008221 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008222 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8223}
8224
8225template<typename Derived>
8226ExprResult
8227TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8228 DependentScopeDeclRefExpr *E,
8229 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008230 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008231 NestedNameSpecifierLoc QualifierLoc
8232 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8233 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008234 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008235 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008236
John McCall31f82722010-11-12 08:19:04 +00008237 // TODO: If this is a conversion-function-id, verify that the
8238 // destination type name (if present) resolves the same way after
8239 // instantiation as it did in the local scope.
8240
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008241 DeclarationNameInfo NameInfo
8242 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8243 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008245
John McCalle66edc12009-11-24 19:00:30 +00008246 if (!E->hasExplicitTemplateArgs()) {
8247 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008248 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008249 // Note: it is sufficient to compare the Name component of NameInfo:
8250 // if name has not changed, DNLoc has not changed either.
8251 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008252 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008253
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008254 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00008255 TemplateKWLoc,
8256 NameInfo,
8257 /*TemplateArgs*/nullptr,
8258 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008259 }
John McCall6b51f282009-11-23 01:53:49 +00008260
8261 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008262 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8263 E->getNumTemplateArgs(),
8264 TransArgs))
8265 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008266
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008267 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008268 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008269 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008270 &TransArgs,
8271 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008272}
8273
8274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008276TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008277 // CXXConstructExprs other than for list-initialization and
8278 // CXXTemporaryObjectExpr are always implicit, so when we have
8279 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008280 if ((E->getNumArgs() == 1 ||
8281 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008282 (!getDerived().DropCallArgument(E->getArg(0))) &&
8283 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008284 return getDerived().TransformExpr(E->getArg(0));
8285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8287
8288 QualType T = getDerived().TransformType(E->getType());
8289 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008290 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008291
8292 CXXConstructorDecl *Constructor
8293 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008294 getDerived().TransformDecl(E->getLocStart(),
8295 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008298
Douglas Gregora16548e2009-08-11 05:31:07 +00008299 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008300 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008301 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008302 &ArgumentChanged))
8303 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 if (!getDerived().AlwaysRebuild() &&
8306 T == E->getType() &&
8307 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008308 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008309 // Mark the constructor as referenced.
8310 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008311 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008312 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008313 }
Mike Stump11289f42009-09-09 15:08:12 +00008314
Douglas Gregordb121ba2009-12-14 16:27:04 +00008315 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8316 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008317 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008318 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008319 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008320 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008321 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008322 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008323}
Mike Stump11289f42009-09-09 15:08:12 +00008324
Douglas Gregora16548e2009-08-11 05:31:07 +00008325/// \brief Transform a C++ temporary-binding expression.
8326///
Douglas Gregor363b1512009-12-24 18:51:59 +00008327/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8328/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008331TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008332 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008333}
Mike Stump11289f42009-09-09 15:08:12 +00008334
John McCall5d413782010-12-06 08:20:24 +00008335/// \brief Transform a C++ expression that contains cleanups that should
8336/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008337///
John McCall5d413782010-12-06 08:20:24 +00008338/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008339/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008341ExprResult
John McCall5d413782010-12-06 08:20:24 +00008342TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008343 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008344}
Mike Stump11289f42009-09-09 15:08:12 +00008345
Douglas Gregora16548e2009-08-11 05:31:07 +00008346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008347ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008348TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008349 CXXTemporaryObjectExpr *E) {
8350 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8351 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 CXXConstructorDecl *Constructor
8355 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008356 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008357 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008362 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008363 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008364 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008365 &ArgumentChanged))
8366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008367
Douglas Gregora16548e2009-08-11 05:31:07 +00008368 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008369 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008371 !ArgumentChanged) {
8372 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008373 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008374 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008375 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008376
Richard Smithd59b8322012-12-19 01:39:02 +00008377 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008378 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8379 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008380 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008381 E->getLocEnd());
8382}
Mike Stump11289f42009-09-09 15:08:12 +00008383
Douglas Gregora16548e2009-08-11 05:31:07 +00008384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008385ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008386TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008387
8388 // Transform any init-capture expressions before entering the scope of the
8389 // lambda body, because they are not semantically within that scope.
8390 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8391 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8392 E->explicit_capture_begin());
8393
8394 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8395 CEnd = E->capture_end();
8396 C != CEnd; ++C) {
8397 if (!C->isInitCapture())
8398 continue;
8399 EnterExpressionEvaluationContext EEEC(getSema(),
8400 Sema::PotentiallyEvaluated);
8401 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8402 C->getCapturedVar()->getInit(),
8403 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8404
8405 if (NewExprInitResult.isInvalid())
8406 return ExprError();
8407 Expr *NewExprInit = NewExprInitResult.get();
8408
8409 VarDecl *OldVD = C->getCapturedVar();
8410 QualType NewInitCaptureType =
8411 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8412 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8413 NewExprInit);
8414 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008415 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8416 std::make_pair(NewExprInitResult, NewInitCaptureType);
8417
8418 }
8419
Faisal Vali524ca282013-11-12 01:40:44 +00008420 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008421 // Transform the template parameters, and add them to the current
8422 // instantiation scope. The null case is handled correctly.
8423 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8424 E->getTemplateParameterList());
8425
8426 // Check to see if the TypeSourceInfo of the call operator needs to
8427 // be transformed, and if so do the transformation in the
8428 // CurrentInstantiationScope.
8429
8430 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8431 FunctionProtoTypeLoc OldCallOpFPTL =
8432 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008433 TypeSourceInfo *NewCallOpTSI = nullptr;
8434
Faisal Vali2cba1332013-10-23 06:44:28 +00008435 const bool CallOpWasAlreadyTransformed =
8436 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8437
8438 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8439 if (CallOpWasAlreadyTransformed)
8440 NewCallOpTSI = OldCallOpTSI;
8441 else {
8442 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8443 // The transformation MUST be done in the CurrentInstantiationScope since
8444 // it introduces a mapping of the original to the newly created
8445 // transformed parameters.
8446
8447 TypeLocBuilder NewCallOpTLBuilder;
8448 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8449 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008450 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008451 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8452 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008453 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008454 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8455 // the vector below - this will be used to synthesize the
8456 // NewCallOperator. Additionally, add the parameters of the untransformed
8457 // lambda call operator to the CurrentInstantiationScope.
8458 SmallVector<ParmVarDecl *, 4> Params;
8459 {
8460 FunctionProtoTypeLoc NewCallOpFPTL =
8461 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8462 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008463 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008464
8465 for (unsigned I = 0; I < NewNumArgs; ++I) {
8466 // If this call operator's type does not require transformation,
8467 // the parameters do not get added to the current instantiation scope,
8468 // - so ADD them! This allows the following to compile when the enclosing
8469 // template is specialized and the entire lambda expression has to be
8470 // transformed.
8471 // template<class T> void foo(T t) {
8472 // auto L = [](auto a) {
8473 // auto M = [](char b) { <-- note: non-generic lambda
8474 // auto N = [](auto c) {
8475 // int x = sizeof(a);
8476 // x = sizeof(b); <-- specifically this line
8477 // x = sizeof(c);
8478 // };
8479 // };
8480 // };
8481 // }
8482 // foo('a')
8483 if (CallOpWasAlreadyTransformed)
8484 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8485 NewParamDeclArray[I]);
8486 // Add to Params array, so these parameters can be used to create
8487 // the newly transformed call operator.
8488 Params.push_back(NewParamDeclArray[I]);
8489 }
8490 }
8491
8492 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008493 return ExprError();
8494
Eli Friedmand564afb2012-09-19 01:18:11 +00008495 // Create the local class that will describe the lambda.
8496 CXXRecordDecl *Class
8497 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008498 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008499 /*KnownDependent=*/false,
8500 E->getCaptureDefault());
8501
Eli Friedmand564afb2012-09-19 01:18:11 +00008502 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8503
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008504 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008505 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008506 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008507 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008508 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008509 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008510 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008511
Faisal Vali2cba1332013-10-23 06:44:28 +00008512 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8513
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008514 return getDerived().TransformLambdaScope(E, NewCallOperator,
8515 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008516}
8517
8518template<typename Derived>
8519ExprResult
8520TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008521 CXXMethodDecl *CallOperator,
8522 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008523 bool Invalid = false;
8524
Douglas Gregorb4328232012-02-14 00:00:48 +00008525 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008526 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8527 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008528
Faisal Vali2b391ab2013-09-26 19:54:12 +00008529 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008530 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008531 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008532 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008533 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008534 E->hasExplicitParameters(),
8535 E->hasExplicitResultType(),
8536 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008537
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008538 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008539 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008540 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008541 CEnd = E->capture_end();
8542 C != CEnd; ++C) {
8543 // When we hit the first implicit capture, tell Sema that we've finished
8544 // the list of explicit captures.
8545 if (!FinishedExplicitCaptures && C->isImplicit()) {
8546 getSema().finishLambdaExplicitCaptures(LSI);
8547 FinishedExplicitCaptures = true;
8548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008549
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008550 // Capturing 'this' is trivial.
8551 if (C->capturesThis()) {
8552 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8553 continue;
8554 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008555
Richard Smithba71c082013-05-16 06:20:58 +00008556 // Rebuild init-captures, including the implied field declaration.
8557 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008558
8559 InitCaptureInfoTy InitExprTypePair =
8560 InitCaptureExprsAndTypes[C - E->capture_begin()];
8561 ExprResult Init = InitExprTypePair.first;
8562 QualType InitQualType = InitExprTypePair.second;
8563 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008564 Invalid = true;
8565 continue;
8566 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008567 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008568 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8569 OldVD->getLocation(), InitExprTypePair.second,
8570 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008571 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008572 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008573 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008574 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008575 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008576 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008577 continue;
8578 }
8579
8580 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8581
Douglas Gregor3e308b12012-02-14 19:27:52 +00008582 // Determine the capture kind for Sema.
8583 Sema::TryCaptureKind Kind
8584 = C->isImplicit()? Sema::TryCapture_Implicit
8585 : C->getCaptureKind() == LCK_ByCopy
8586 ? Sema::TryCapture_ExplicitByVal
8587 : Sema::TryCapture_ExplicitByRef;
8588 SourceLocation EllipsisLoc;
8589 if (C->isPackExpansion()) {
8590 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8591 bool ShouldExpand = false;
8592 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008593 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008594 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8595 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008596 Unexpanded,
8597 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008598 NumExpansions)) {
8599 Invalid = true;
8600 continue;
8601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008602
Douglas Gregor3e308b12012-02-14 19:27:52 +00008603 if (ShouldExpand) {
8604 // The transform has determined that we should perform an expansion;
8605 // transform and capture each of the arguments.
8606 // expansion of the pattern. Do so.
8607 VarDecl *Pack = C->getCapturedVar();
8608 for (unsigned I = 0; I != *NumExpansions; ++I) {
8609 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8610 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008611 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008612 Pack));
8613 if (!CapturedVar) {
8614 Invalid = true;
8615 continue;
8616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008617
Douglas Gregor3e308b12012-02-14 19:27:52 +00008618 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008619 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8620 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008621 continue;
8622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008623
Douglas Gregor3e308b12012-02-14 19:27:52 +00008624 EllipsisLoc = C->getEllipsisLoc();
8625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008626
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008627 // Transform the captured variable.
8628 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008629 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008630 C->getCapturedVar()));
8631 if (!CapturedVar) {
8632 Invalid = true;
8633 continue;
8634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008635
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008636 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008637 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008638 }
8639 if (!FinishedExplicitCaptures)
8640 getSema().finishLambdaExplicitCaptures(LSI);
8641
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008642
8643 // Enter a new evaluation context to insulate the lambda from any
8644 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008645 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008646
8647 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008648 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008649 /*IsInstantiation=*/true);
8650 return ExprError();
8651 }
8652
8653 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008654 StmtResult Body = getDerived().TransformStmt(E->getBody());
8655 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008656 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008657 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008658 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008659 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008660
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008661 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008662 /*CurScope=*/nullptr,
8663 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008664}
8665
8666template<typename Derived>
8667ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008668TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008669 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008670 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8671 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008673
Douglas Gregora16548e2009-08-11 05:31:07 +00008674 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008675 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008676 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008677 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008678 &ArgumentChanged))
8679 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008680
Douglas Gregora16548e2009-08-11 05:31:07 +00008681 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008682 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008683 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008684 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008687 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008688 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008689 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008690 E->getRParenLoc());
8691}
Mike Stump11289f42009-09-09 15:08:12 +00008692
Douglas Gregora16548e2009-08-11 05:31:07 +00008693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008694ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008695TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008696 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008697 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008698 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008699 Expr *OldBase;
8700 QualType BaseType;
8701 QualType ObjectType;
8702 if (!E->isImplicitAccess()) {
8703 OldBase = E->getBase();
8704 Base = getDerived().TransformExpr(OldBase);
8705 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008707
John McCall2d74de92009-12-01 22:10:20 +00008708 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008709 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008710 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008711 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008712 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008713 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008714 ObjectTy,
8715 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008716 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008717 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008718
John McCallba7bf592010-08-24 05:47:05 +00008719 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008720 BaseType = ((Expr*) Base.get())->getType();
8721 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008722 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008723 BaseType = getDerived().TransformType(E->getBaseType());
8724 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8725 }
Mike Stump11289f42009-09-09 15:08:12 +00008726
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008727 // Transform the first part of the nested-name-specifier that qualifies
8728 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008729 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008730 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008731 E->getFirstQualifierFoundInScope(),
8732 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008733
Douglas Gregore16af532011-02-28 18:50:33 +00008734 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008735 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008736 QualifierLoc
8737 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8738 ObjectType,
8739 FirstQualifierInScope);
8740 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008741 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008742 }
Mike Stump11289f42009-09-09 15:08:12 +00008743
Abramo Bagnara7945c982012-01-27 09:46:47 +00008744 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8745
John McCall31f82722010-11-12 08:19:04 +00008746 // TODO: If this is a conversion-function-id, verify that the
8747 // destination type name (if present) resolves the same way after
8748 // instantiation as it did in the local scope.
8749
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008750 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008751 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008752 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008754
John McCall2d74de92009-12-01 22:10:20 +00008755 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008756 // This is a reference to a member without an explicitly-specified
8757 // template argument list. Optimize for this common case.
8758 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008759 Base.get() == OldBase &&
8760 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008761 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008762 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008763 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008764 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008765
John McCallb268a282010-08-23 23:25:46 +00008766 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008767 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008768 E->isArrow(),
8769 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008770 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008771 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008772 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008773 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008774 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008775 }
8776
John McCall6b51f282009-11-23 01:53:49 +00008777 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008778 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8779 E->getNumTemplateArgs(),
8780 TransArgs))
8781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008782
John McCallb268a282010-08-23 23:25:46 +00008783 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008784 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008785 E->isArrow(),
8786 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008787 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008788 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008789 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008790 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008791 &TransArgs);
8792}
8793
8794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008795ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008796TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008797 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008798 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008799 QualType BaseType;
8800 if (!Old->isImplicitAccess()) {
8801 Base = getDerived().TransformExpr(Old->getBase());
8802 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008803 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008804 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008805 Old->isArrow());
8806 if (Base.isInvalid())
8807 return ExprError();
8808 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008809 } else {
8810 BaseType = getDerived().TransformType(Old->getBaseType());
8811 }
John McCall10eae182009-11-30 22:42:35 +00008812
Douglas Gregor0da1d432011-02-28 20:01:57 +00008813 NestedNameSpecifierLoc QualifierLoc;
8814 if (Old->getQualifierLoc()) {
8815 QualifierLoc
8816 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8817 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008818 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008819 }
8820
Abramo Bagnara7945c982012-01-27 09:46:47 +00008821 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8822
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008823 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008824 Sema::LookupOrdinaryName);
8825
8826 // Transform all the decls.
8827 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8828 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008829 NamedDecl *InstD = static_cast<NamedDecl*>(
8830 getDerived().TransformDecl(Old->getMemberLoc(),
8831 *I));
John McCall84d87672009-12-10 09:41:52 +00008832 if (!InstD) {
8833 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8834 // This can happen because of dependent hiding.
8835 if (isa<UsingShadowDecl>(*I))
8836 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008837 else {
8838 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008839 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008840 }
John McCall84d87672009-12-10 09:41:52 +00008841 }
John McCall10eae182009-11-30 22:42:35 +00008842
8843 // Expand using declarations.
8844 if (isa<UsingDecl>(InstD)) {
8845 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008846 for (auto *I : UD->shadows())
8847 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008848 continue;
8849 }
8850
8851 R.addDecl(InstD);
8852 }
8853
8854 R.resolveKind();
8855
Douglas Gregor9262f472010-04-27 18:19:34 +00008856 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008857 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008858 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008859 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008860 Old->getMemberLoc(),
8861 Old->getNamingClass()));
8862 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008864
Douglas Gregorda7be082010-04-27 16:10:10 +00008865 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008867
John McCall10eae182009-11-30 22:42:35 +00008868 TemplateArgumentListInfo TransArgs;
8869 if (Old->hasExplicitTemplateArgs()) {
8870 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8871 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008872 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8873 Old->getNumTemplateArgs(),
8874 TransArgs))
8875 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008876 }
John McCall38836f02010-01-15 08:34:02 +00008877
8878 // FIXME: to do this check properly, we will need to preserve the
8879 // first-qualifier-in-scope here, just in case we had a dependent
8880 // base (and therefore couldn't do the check) and a
8881 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008882 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
John McCallb268a282010-08-23 23:25:46 +00008884 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008885 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008886 Old->getOperatorLoc(),
8887 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008888 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008889 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008890 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008891 R,
8892 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008893 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008894}
8895
8896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008897ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008898TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008899 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008900 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8901 if (SubExpr.isInvalid())
8902 return ExprError();
8903
8904 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008905 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008906
8907 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8908}
8909
8910template<typename Derived>
8911ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008912TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008913 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8914 if (Pattern.isInvalid())
8915 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008916
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008917 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008918 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008919
Douglas Gregorb8840002011-01-14 21:20:45 +00008920 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8921 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008922}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008923
8924template<typename Derived>
8925ExprResult
8926TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8927 // If E is not value-dependent, then nothing will change when we transform it.
8928 // Note: This is an instantiation-centric view.
8929 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008930 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008931
8932 // Note: None of the implementations of TryExpandParameterPacks can ever
8933 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008934 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008935 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8936 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008937 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008938 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008939 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008940 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008941 ShouldExpand, RetainExpansion,
8942 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008944
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008945 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008946 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008947
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008948 NamedDecl *Pack = E->getPack();
8949 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008950 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008951 Pack));
8952 if (!Pack)
8953 return ExprError();
8954 }
8955
Chad Rosier1dcde962012-08-08 18:46:20 +00008956
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008957 // We now know the length of the parameter pack, so build a new expression
8958 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008959 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8960 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008961 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008962}
8963
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008964template<typename Derived>
8965ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008966TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8967 SubstNonTypeTemplateParmPackExpr *E) {
8968 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008969 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008970}
8971
8972template<typename Derived>
8973ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008974TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8975 SubstNonTypeTemplateParmExpr *E) {
8976 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008977 return E;
John McCall7c454bb2011-07-15 05:09:51 +00008978}
8979
8980template<typename Derived>
8981ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008982TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8983 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008984 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00008985}
8986
8987template<typename Derived>
8988ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008989TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8990 MaterializeTemporaryExpr *E) {
8991 return getDerived().TransformExpr(E->GetTemporaryExpr());
8992}
Chad Rosier1dcde962012-08-08 18:46:20 +00008993
Douglas Gregorfe314812011-06-21 17:03:29 +00008994template<typename Derived>
8995ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008996TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8997 CXXStdInitializerListExpr *E) {
8998 return getDerived().TransformExpr(E->getSubExpr());
8999}
9000
9001template<typename Derived>
9002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009003TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009004 return SemaRef.MaybeBindToTemporary(E);
9005}
9006
9007template<typename Derived>
9008ExprResult
9009TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009010 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009011}
9012
9013template<typename Derived>
9014ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009015TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9016 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9017 if (SubExpr.isInvalid())
9018 return ExprError();
9019
9020 if (!getDerived().AlwaysRebuild() &&
9021 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009022 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009023
9024 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009025}
9026
9027template<typename Derived>
9028ExprResult
9029TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9030 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009031 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009032 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009033 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009034 /*IsCall=*/false, Elements, &ArgChanged))
9035 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009036
Ted Kremeneke65b0862012-03-06 20:05:56 +00009037 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9038 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
Ted Kremeneke65b0862012-03-06 20:05:56 +00009040 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9041 Elements.data(),
9042 Elements.size());
9043}
9044
9045template<typename Derived>
9046ExprResult
9047TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009048 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009049 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009050 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009051 bool ArgChanged = false;
9052 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9053 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009054
Ted Kremeneke65b0862012-03-06 20:05:56 +00009055 if (OrigElement.isPackExpansion()) {
9056 // This key/value element is a pack expansion.
9057 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9058 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9059 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9060 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9061
9062 // Determine whether the set of unexpanded parameter packs can
9063 // and should be expanded.
9064 bool Expand = true;
9065 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009066 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9067 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009068 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9069 OrigElement.Value->getLocEnd());
9070 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9071 PatternRange,
9072 Unexpanded,
9073 Expand, RetainExpansion,
9074 NumExpansions))
9075 return ExprError();
9076
9077 if (!Expand) {
9078 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009079 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009080 // expansion.
9081 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9082 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9083 if (Key.isInvalid())
9084 return ExprError();
9085
9086 if (Key.get() != OrigElement.Key)
9087 ArgChanged = true;
9088
9089 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9090 if (Value.isInvalid())
9091 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009092
Ted Kremeneke65b0862012-03-06 20:05:56 +00009093 if (Value.get() != OrigElement.Value)
9094 ArgChanged = true;
9095
Chad Rosier1dcde962012-08-08 18:46:20 +00009096 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009097 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9098 };
9099 Elements.push_back(Expansion);
9100 continue;
9101 }
9102
9103 // Record right away that the argument was changed. This needs
9104 // to happen even if the array expands to nothing.
9105 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009106
Ted Kremeneke65b0862012-03-06 20:05:56 +00009107 // The transform has determined that we should perform an elementwise
9108 // expansion of the pattern. Do so.
9109 for (unsigned I = 0; I != *NumExpansions; ++I) {
9110 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9111 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9112 if (Key.isInvalid())
9113 return ExprError();
9114
9115 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9116 if (Value.isInvalid())
9117 return ExprError();
9118
Chad Rosier1dcde962012-08-08 18:46:20 +00009119 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009120 Key.get(), Value.get(), SourceLocation(), NumExpansions
9121 };
9122
9123 // If any unexpanded parameter packs remain, we still have a
9124 // pack expansion.
9125 if (Key.get()->containsUnexpandedParameterPack() ||
9126 Value.get()->containsUnexpandedParameterPack())
9127 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009128
Ted Kremeneke65b0862012-03-06 20:05:56 +00009129 Elements.push_back(Element);
9130 }
9131
9132 // We've finished with this pack expansion.
9133 continue;
9134 }
9135
9136 // Transform and check key.
9137 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9138 if (Key.isInvalid())
9139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
Ted Kremeneke65b0862012-03-06 20:05:56 +00009141 if (Key.get() != OrigElement.Key)
9142 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009143
Ted Kremeneke65b0862012-03-06 20:05:56 +00009144 // Transform and check value.
9145 ExprResult Value
9146 = getDerived().TransformExpr(OrigElement.Value);
9147 if (Value.isInvalid())
9148 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009149
Ted Kremeneke65b0862012-03-06 20:05:56 +00009150 if (Value.get() != OrigElement.Value)
9151 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009152
9153 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009154 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009155 };
9156 Elements.push_back(Element);
9157 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009158
Ted Kremeneke65b0862012-03-06 20:05:56 +00009159 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9160 return SemaRef.MaybeBindToTemporary(E);
9161
9162 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9163 Elements.data(),
9164 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009165}
9166
Mike Stump11289f42009-09-09 15:08:12 +00009167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009169TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009170 TypeSourceInfo *EncodedTypeInfo
9171 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9172 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009174
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009176 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009177 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009178
9179 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009180 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 E->getRParenLoc());
9182}
Mike Stump11289f42009-09-09 15:08:12 +00009183
Douglas Gregora16548e2009-08-11 05:31:07 +00009184template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009185ExprResult TreeTransform<Derived>::
9186TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009187 // This is a kind of implicit conversion, and it needs to get dropped
9188 // and recomputed for the same general reasons that ImplicitCastExprs
9189 // do, as well a more specific one: this expression is only valid when
9190 // it appears *immediately* as an argument expression.
9191 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009192}
9193
9194template<typename Derived>
9195ExprResult TreeTransform<Derived>::
9196TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009197 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009198 = getDerived().TransformType(E->getTypeInfoAsWritten());
9199 if (!TSInfo)
9200 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009201
John McCall31168b02011-06-15 23:02:42 +00009202 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009203 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009204 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
John McCall31168b02011-06-15 23:02:42 +00009206 if (!getDerived().AlwaysRebuild() &&
9207 TSInfo == E->getTypeInfoAsWritten() &&
9208 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009209 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009210
John McCall31168b02011-06-15 23:02:42 +00009211 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009212 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009213 Result.get());
9214}
9215
9216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009218TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009219 // Transform arguments.
9220 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009221 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009222 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009223 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009224 &ArgChanged))
9225 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009226
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009227 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9228 // Class message: transform the receiver type.
9229 TypeSourceInfo *ReceiverTypeInfo
9230 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9231 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009232 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009233
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009234 // If nothing changed, just retain the existing message send.
9235 if (!getDerived().AlwaysRebuild() &&
9236 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009237 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009238
9239 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009240 SmallVector<SourceLocation, 16> SelLocs;
9241 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009242 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9243 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009244 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009245 E->getMethodDecl(),
9246 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009247 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009248 E->getRightLoc());
9249 }
9250
9251 // Instance message: transform the receiver
9252 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9253 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009254 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009255 = getDerived().TransformExpr(E->getInstanceReceiver());
9256 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009257 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009258
9259 // If nothing changed, just retain the existing message send.
9260 if (!getDerived().AlwaysRebuild() &&
9261 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009262 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009263
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009264 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009265 SmallVector<SourceLocation, 16> SelLocs;
9266 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009267 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009268 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009269 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009270 E->getMethodDecl(),
9271 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009272 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009273 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009274}
9275
Mike Stump11289f42009-09-09 15:08:12 +00009276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009277ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009278TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009279 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009280}
9281
Mike Stump11289f42009-09-09 15:08:12 +00009282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009284TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009285 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009286}
9287
Mike Stump11289f42009-09-09 15:08:12 +00009288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009290TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009291 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009292 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009293 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009294 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009295
9296 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009297
Douglas Gregord51d90d2010-04-26 20:11:03 +00009298 // If nothing changed, just retain the existing expression.
9299 if (!getDerived().AlwaysRebuild() &&
9300 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009301 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009302
John McCallb268a282010-08-23 23:25:46 +00009303 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009304 E->getLocation(),
9305 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009306}
9307
Mike Stump11289f42009-09-09 15:08:12 +00009308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009310TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009311 // 'super' and types never change. Property never changes. Just
9312 // retain the existing expression.
9313 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009314 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009315
Douglas Gregor9faee212010-04-26 20:47:02 +00009316 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009317 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009318 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
Douglas Gregor9faee212010-04-26 20:47:02 +00009321 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009322
Douglas Gregor9faee212010-04-26 20:47:02 +00009323 // If nothing changed, just retain the existing expression.
9324 if (!getDerived().AlwaysRebuild() &&
9325 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009326 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009327
John McCallb7bd14f2010-12-02 01:19:52 +00009328 if (E->isExplicitProperty())
9329 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9330 E->getExplicitProperty(),
9331 E->getLocation());
9332
9333 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009334 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009335 E->getImplicitPropertyGetter(),
9336 E->getImplicitPropertySetter(),
9337 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009338}
9339
Mike Stump11289f42009-09-09 15:08:12 +00009340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009341ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009342TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9343 // Transform the base expression.
9344 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9345 if (Base.isInvalid())
9346 return ExprError();
9347
9348 // Transform the key expression.
9349 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9350 if (Key.isInvalid())
9351 return ExprError();
9352
9353 // If nothing changed, just retain the existing expression.
9354 if (!getDerived().AlwaysRebuild() &&
9355 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009356 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009357
Chad Rosier1dcde962012-08-08 18:46:20 +00009358 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009359 Base.get(), Key.get(),
9360 E->getAtIndexMethodDecl(),
9361 E->setAtIndexMethodDecl());
9362}
9363
9364template<typename Derived>
9365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009366TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009367 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009368 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009369 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009370 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009371
Douglas Gregord51d90d2010-04-26 20:11:03 +00009372 // If nothing changed, just retain the existing expression.
9373 if (!getDerived().AlwaysRebuild() &&
9374 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009375 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009376
John McCallb268a282010-08-23 23:25:46 +00009377 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009378 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009379 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009380}
9381
Mike Stump11289f42009-09-09 15:08:12 +00009382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009384TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009385 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009386 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009387 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009388 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009389 SubExprs, &ArgumentChanged))
9390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 if (!getDerived().AlwaysRebuild() &&
9393 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009394 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009395
Douglas Gregora16548e2009-08-11 05:31:07 +00009396 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009397 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009398 E->getRParenLoc());
9399}
9400
Mike Stump11289f42009-09-09 15:08:12 +00009401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009402ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009403TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9404 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9405 if (SrcExpr.isInvalid())
9406 return ExprError();
9407
9408 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9409 if (!Type)
9410 return ExprError();
9411
9412 if (!getDerived().AlwaysRebuild() &&
9413 Type == E->getTypeSourceInfo() &&
9414 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009415 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009416
9417 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9418 SrcExpr.get(), Type,
9419 E->getRParenLoc());
9420}
9421
9422template<typename Derived>
9423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009424TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009425 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009426
Craig Topperc3ec1492014-05-26 06:22:03 +00009427 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009428 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9429
9430 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009431 blockScope->TheDecl->setBlockMissingReturnType(
9432 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009433
Chris Lattner01cf8db2011-07-20 06:58:45 +00009434 SmallVector<ParmVarDecl*, 4> params;
9435 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009436
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009437 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009438 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9439 oldBlock->param_begin(),
9440 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009441 nullptr, paramTypes, &params)) {
9442 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009443 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009444 }
John McCall490112f2011-02-04 18:33:18 +00009445
Jordan Rosea0a86be2013-03-08 22:25:36 +00009446 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009447 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009448 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009449
Jordan Rose5c382722013-03-08 21:51:21 +00009450 QualType functionType =
9451 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009452 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009453 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009454
9455 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009456 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009457 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009458
9459 if (!oldBlock->blockMissingReturnType()) {
9460 blockScope->HasImplicitReturnType = false;
9461 blockScope->ReturnType = exprResultType;
9462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009463
John McCall3882ace2011-01-05 12:14:39 +00009464 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009465 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009466 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009467 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009468 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009469 }
John McCall3882ace2011-01-05 12:14:39 +00009470
John McCall490112f2011-02-04 18:33:18 +00009471#ifndef NDEBUG
9472 // In builds with assertions, make sure that we captured everything we
9473 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009474 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009475 for (const auto &I : oldBlock->captures()) {
9476 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009477
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009478 // Ignore parameter packs.
9479 if (isa<ParmVarDecl>(oldCapture) &&
9480 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9481 continue;
John McCall490112f2011-02-04 18:33:18 +00009482
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009483 VarDecl *newCapture =
9484 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9485 oldCapture));
9486 assert(blockScope->CaptureMap.count(newCapture));
9487 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009488 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009489 }
9490#endif
9491
9492 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009493 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009494}
9495
Mike Stump11289f42009-09-09 15:08:12 +00009496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009497ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009498TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009499 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009500}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009501
9502template<typename Derived>
9503ExprResult
9504TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009505 QualType RetTy = getDerived().TransformType(E->getType());
9506 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009507 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009508 SubExprs.reserve(E->getNumSubExprs());
9509 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9510 SubExprs, &ArgumentChanged))
9511 return ExprError();
9512
9513 if (!getDerived().AlwaysRebuild() &&
9514 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009515 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009516
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009517 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009518 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009519}
Chad Rosier1dcde962012-08-08 18:46:20 +00009520
Douglas Gregora16548e2009-08-11 05:31:07 +00009521//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009522// Type reconstruction
9523//===----------------------------------------------------------------------===//
9524
Mike Stump11289f42009-09-09 15:08:12 +00009525template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009526QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9527 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009528 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009529 getDerived().getBaseEntity());
9530}
9531
Mike Stump11289f42009-09-09 15:08:12 +00009532template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009533QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9534 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009535 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009536 getDerived().getBaseEntity());
9537}
9538
Mike Stump11289f42009-09-09 15:08:12 +00009539template<typename Derived>
9540QualType
John McCall70dd5f62009-10-30 00:06:24 +00009541TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9542 bool WrittenAsLValue,
9543 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009544 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009545 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009546}
9547
9548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009549QualType
John McCall70dd5f62009-10-30 00:06:24 +00009550TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9551 QualType ClassType,
9552 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009553 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9554 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009555}
9556
9557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009558QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009559TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9560 ArrayType::ArraySizeModifier SizeMod,
9561 const llvm::APInt *Size,
9562 Expr *SizeExpr,
9563 unsigned IndexTypeQuals,
9564 SourceRange BracketsRange) {
9565 if (SizeExpr || !Size)
9566 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9567 IndexTypeQuals, BracketsRange,
9568 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009569
9570 QualType Types[] = {
9571 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9572 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9573 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009574 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009575 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009576 QualType SizeType;
9577 for (unsigned I = 0; I != NumTypes; ++I)
9578 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9579 SizeType = Types[I];
9580 break;
9581 }
Mike Stump11289f42009-09-09 15:08:12 +00009582
Eli Friedman9562f392012-01-25 23:20:27 +00009583 // Note that we can return a VariableArrayType here in the case where
9584 // the element type was a dependent VariableArrayType.
9585 IntegerLiteral *ArraySize
9586 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9587 /*FIXME*/BracketsRange.getBegin());
9588 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009589 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009590 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009591}
Mike Stump11289f42009-09-09 15:08:12 +00009592
Douglas Gregord6ff3322009-08-04 16:50:30 +00009593template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009594QualType
9595TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009596 ArrayType::ArraySizeModifier SizeMod,
9597 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009598 unsigned IndexTypeQuals,
9599 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009600 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009601 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009602}
9603
9604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009605QualType
Mike Stump11289f42009-09-09 15:08:12 +00009606TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009607 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009608 unsigned IndexTypeQuals,
9609 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009610 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009611 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009612}
Mike Stump11289f42009-09-09 15:08:12 +00009613
Douglas Gregord6ff3322009-08-04 16:50:30 +00009614template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009615QualType
9616TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009617 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009618 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009619 unsigned IndexTypeQuals,
9620 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009621 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009622 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009623 IndexTypeQuals, BracketsRange);
9624}
9625
9626template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009627QualType
9628TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009629 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009630 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009631 unsigned IndexTypeQuals,
9632 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009633 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009634 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009635 IndexTypeQuals, BracketsRange);
9636}
9637
9638template<typename Derived>
9639QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009640 unsigned NumElements,
9641 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009642 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009643 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009644}
Mike Stump11289f42009-09-09 15:08:12 +00009645
Douglas Gregord6ff3322009-08-04 16:50:30 +00009646template<typename Derived>
9647QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9648 unsigned NumElements,
9649 SourceLocation AttributeLoc) {
9650 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9651 NumElements, true);
9652 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009653 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9654 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009655 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009656}
Mike Stump11289f42009-09-09 15:08:12 +00009657
Douglas Gregord6ff3322009-08-04 16:50:30 +00009658template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009659QualType
9660TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009661 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009662 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009663 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009664}
Mike Stump11289f42009-09-09 15:08:12 +00009665
Douglas Gregord6ff3322009-08-04 16:50:30 +00009666template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009667QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9668 QualType T,
9669 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009670 const FunctionProtoType::ExtProtoInfo &EPI) {
9671 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009672 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009673 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009674 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009675}
Mike Stump11289f42009-09-09 15:08:12 +00009676
Douglas Gregord6ff3322009-08-04 16:50:30 +00009677template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009678QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9679 return SemaRef.Context.getFunctionNoProtoType(T);
9680}
9681
9682template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009683QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9684 assert(D && "no decl found");
9685 if (D->isInvalidDecl()) return QualType();
9686
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009687 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009688 TypeDecl *Ty;
9689 if (isa<UsingDecl>(D)) {
9690 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009691 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009692 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9693
9694 // A valid resolved using typename decl points to exactly one type decl.
9695 assert(++Using->shadow_begin() == Using->shadow_end());
9696 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009697
John McCallb96ec562009-12-04 22:46:56 +00009698 } else {
9699 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9700 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9701 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9702 }
9703
9704 return SemaRef.Context.getTypeDeclType(Ty);
9705}
9706
9707template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009708QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9709 SourceLocation Loc) {
9710 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009711}
9712
9713template<typename Derived>
9714QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9715 return SemaRef.Context.getTypeOfType(Underlying);
9716}
9717
9718template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009719QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9720 SourceLocation Loc) {
9721 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009722}
9723
9724template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009725QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9726 UnaryTransformType::UTTKind UKind,
9727 SourceLocation Loc) {
9728 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9729}
9730
9731template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009732QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009733 TemplateName Template,
9734 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009735 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009736 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009737}
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregor1135c352009-08-06 05:28:30 +00009739template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009740QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9741 SourceLocation KWLoc) {
9742 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9743}
9744
9745template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009746TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009747TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009748 bool TemplateKW,
9749 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009750 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009751 Template);
9752}
9753
9754template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009755TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009756TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9757 const IdentifierInfo &Name,
9758 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009759 QualType ObjectType,
9760 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009761 UnqualifiedId TemplateName;
9762 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009763 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009764 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009765 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009766 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009767 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009768 /*EnteringContext=*/false,
9769 Template);
John McCall31f82722010-11-12 08:19:04 +00009770 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009771}
Mike Stump11289f42009-09-09 15:08:12 +00009772
Douglas Gregora16548e2009-08-11 05:31:07 +00009773template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009774TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009775TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009776 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009777 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009778 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009779 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009780 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009781 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009782 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009783 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009784 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009785 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009786 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009787 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009788 /*EnteringContext=*/false,
9789 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009790 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009791}
Chad Rosier1dcde962012-08-08 18:46:20 +00009792
Douglas Gregor71395fa2009-11-04 00:56:37 +00009793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009794ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009795TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9796 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009797 Expr *OrigCallee,
9798 Expr *First,
9799 Expr *Second) {
9800 Expr *Callee = OrigCallee->IgnoreParenCasts();
9801 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009802
Douglas Gregora16548e2009-08-11 05:31:07 +00009803 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009804 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009805 if (!First->getType()->isOverloadableType() &&
9806 !Second->getType()->isOverloadableType())
9807 return getSema().CreateBuiltinArraySubscriptExpr(First,
9808 Callee->getLocStart(),
9809 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009810 } else if (Op == OO_Arrow) {
9811 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009812 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9813 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009814 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009815 // The argument is not of overloadable type, so try to create a
9816 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009817 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009818 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009819
John McCallb268a282010-08-23 23:25:46 +00009820 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009821 }
9822 } else {
John McCallb268a282010-08-23 23:25:46 +00009823 if (!First->getType()->isOverloadableType() &&
9824 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009825 // Neither of the arguments is an overloadable type, so try to
9826 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009827 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009828 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009829 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009832
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009833 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009834 }
9835 }
Mike Stump11289f42009-09-09 15:08:12 +00009836
9837 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009838 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009839 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009840
John McCallb268a282010-08-23 23:25:46 +00009841 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009842 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009843 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009844 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009845 // If we've resolved this to a particular non-member function, just call
9846 // that function. If we resolved it to a member function,
9847 // CreateOverloaded* will find that function for us.
9848 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9849 if (!isa<CXXMethodDecl>(ND))
9850 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009851 }
Mike Stump11289f42009-09-09 15:08:12 +00009852
Douglas Gregora16548e2009-08-11 05:31:07 +00009853 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009854 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009855 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009856
Douglas Gregora16548e2009-08-11 05:31:07 +00009857 // Create the overloaded operator invocation for unary operators.
9858 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009859 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009860 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009861 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009862 }
Mike Stump11289f42009-09-09 15:08:12 +00009863
Douglas Gregore9d62932011-07-15 16:25:15 +00009864 if (Op == OO_Subscript) {
9865 SourceLocation LBrace;
9866 SourceLocation RBrace;
9867
9868 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9869 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9870 LBrace = SourceLocation::getFromRawEncoding(
9871 NameLoc.CXXOperatorName.BeginOpNameLoc);
9872 RBrace = SourceLocation::getFromRawEncoding(
9873 NameLoc.CXXOperatorName.EndOpNameLoc);
9874 } else {
9875 LBrace = Callee->getLocStart();
9876 RBrace = OpLoc;
9877 }
9878
9879 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9880 First, Second);
9881 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009882
Douglas Gregora16548e2009-08-11 05:31:07 +00009883 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009884 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009885 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009886 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9887 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009889
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009890 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009891}
Mike Stump11289f42009-09-09 15:08:12 +00009892
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009893template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009894ExprResult
John McCallb268a282010-08-23 23:25:46 +00009895TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009896 SourceLocation OperatorLoc,
9897 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009898 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009899 TypeSourceInfo *ScopeType,
9900 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009901 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009902 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009903 QualType BaseType = Base->getType();
9904 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009905 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009906 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009907 !BaseType->getAs<PointerType>()->getPointeeType()
9908 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009909 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009910 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009911 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009912 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009913 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009914 /*FIXME?*/true);
9915 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009916
Douglas Gregor678f90d2010-02-25 01:56:36 +00009917 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009918 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9919 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9920 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9921 NameInfo.setNamedTypeInfo(DestroyedType);
9922
Richard Smith8e4a3862012-05-15 06:15:11 +00009923 // The scope type is now known to be a valid nested name specifier
9924 // component. Tack it on to the end of the nested name specifier.
9925 if (ScopeType)
9926 SS.Extend(SemaRef.Context, SourceLocation(),
9927 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009928
Abramo Bagnara7945c982012-01-27 09:46:47 +00009929 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009930 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009931 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009932 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009933 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009934 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009935 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009936}
9937
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009938template<typename Derived>
9939StmtResult
9940TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009941 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +00009942 CapturedDecl *CD = S->getCapturedDecl();
9943 unsigned NumParams = CD->getNumParams();
9944 unsigned ContextParamPos = CD->getContextParamPosition();
9945 SmallVector<Sema::CapturedParamNameType, 4> Params;
9946 for (unsigned I = 0; I < NumParams; ++I) {
9947 if (I != ContextParamPos) {
9948 Params.push_back(
9949 std::make_pair(
9950 CD->getParam(I)->getName(),
9951 getDerived().TransformType(CD->getParam(I)->getType())));
9952 } else {
9953 Params.push_back(std::make_pair(StringRef(), QualType()));
9954 }
9955 }
Craig Topperc3ec1492014-05-26 06:22:03 +00009956 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +00009957 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +00009958 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9959
9960 if (Body.isInvalid()) {
9961 getSema().ActOnCapturedRegionError();
9962 return StmtError();
9963 }
9964
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009965 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009966}
9967
Douglas Gregord6ff3322009-08-04 16:50:30 +00009968} // end namespace clang
9969
9970#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H