blob: d2683bec649a6e7a14eee9f2ebb8dbe4044a1953 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000609 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
852 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Craig Topperc3ec1492014-05-26 06:22:03 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Craig Topperc3ec1492014-05-26 06:22:03 +0000916 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001083 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001190 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev62c87d22014-03-21 04:51:18 +00001326 /// \brief Build a new OpenMP 'safelen' clause.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1331 SourceLocation LParenLoc,
1332 SourceLocation EndLoc) {
1333 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1334 }
1335
Alexander Musman8bd31e62014-05-27 15:12:19 +00001336 /// \brief Build a new OpenMP 'collapse' clause.
1337 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1341 SourceLocation LParenLoc,
1342 SourceLocation EndLoc) {
1343 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1344 EndLoc);
1345 }
1346
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001347 /// \brief Build a new OpenMP 'default' clause.
1348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
1351 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1352 SourceLocation KindKwLoc,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1357 StartLoc, LParenLoc, EndLoc);
1358 }
1359
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001360 /// \brief Build a new OpenMP 'proc_bind' clause.
1361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
1364 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1365 SourceLocation KindKwLoc,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1370 StartLoc, LParenLoc, EndLoc);
1371 }
1372
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 /// \brief Build a new OpenMP 'private' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001385 /// \brief Build a new OpenMP 'firstprivate' clause.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001397 /// \brief Build a new OpenMP 'shared' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001401 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexander Musman8dba6642014-04-22 13:09:42 +00001409 /// \brief Build a new OpenMP 'linear' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new statement.
1412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1414 SourceLocation StartLoc,
1415 SourceLocation LParenLoc,
1416 SourceLocation ColonLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1419 ColonLoc, EndLoc);
1420 }
1421
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001422 /// \brief Build a new OpenMP 'copyin' clause.
1423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
1426 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1427 SourceLocation StartLoc,
1428 SourceLocation LParenLoc,
1429 SourceLocation EndLoc) {
1430 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1431 EndLoc);
1432 }
1433
James Dennett2a4d13c2012-06-15 07:13:21 +00001434 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001435 ///
1436 /// By default, performs semantic analysis to build the new statement.
1437 /// Subclasses may override this routine to provide different behavior.
1438 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1439 Expr *object) {
1440 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1441 }
1442
James Dennett2a4d13c2012-06-15 07:13:21 +00001443 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001444 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001445 /// By default, performs semantic analysis to build the new statement.
1446 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001447 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001448 Expr *Object, Stmt *Body) {
1449 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001450 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001451
James Dennett2a4d13c2012-06-15 07:13:21 +00001452 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001453 ///
1454 /// By default, performs semantic analysis to build the new statement.
1455 /// Subclasses may override this routine to provide different behavior.
1456 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1457 Stmt *Body) {
1458 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1459 }
John McCall53848232011-07-27 01:07:15 +00001460
Douglas Gregorf68a5082010-04-22 23:10:45 +00001461 /// \brief Build a new Objective-C fast enumeration statement.
1462 ///
1463 /// By default, performs semantic analysis to build the new statement.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001466 Stmt *Element,
1467 Expr *Collection,
1468 SourceLocation RParenLoc,
1469 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001470 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001471 Element,
John McCallb268a282010-08-23 23:25:46 +00001472 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001473 RParenLoc);
1474 if (ForEachStmt.isInvalid())
1475 return StmtError();
1476
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001477 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001479
Douglas Gregorebe10102009-08-20 07:17:43 +00001480 /// \brief Build a new C++ exception declaration.
1481 ///
1482 /// By default, performs semantic analysis to build the new decaration.
1483 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001484 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001485 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001486 SourceLocation StartLoc,
1487 SourceLocation IdLoc,
1488 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001489 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001490 StartLoc, IdLoc, Id);
1491 if (Var)
1492 getSema().CurContext->addDecl(Var);
1493 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001494 }
1495
1496 /// \brief Build a new C++ catch statement.
1497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001501 VarDecl *ExceptionDecl,
1502 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001503 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1504 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001505 }
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregorebe10102009-08-20 07:17:43 +00001507 /// \brief Build a new C++ try statement.
1508 ///
1509 /// By default, performs semantic analysis to build the new statement.
1510 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001511 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1512 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001513 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Richard Smith02e85f32011-04-14 22:09:26 +00001516 /// \brief Build a new C++0x range-based for statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1520 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1521 SourceLocation ColonLoc,
1522 Stmt *Range, Stmt *BeginEnd,
1523 Expr *Cond, Expr *Inc,
1524 Stmt *LoopVar,
1525 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001526 // If we've just learned that the range is actually an Objective-C
1527 // collection, treat this as an Objective-C fast enumeration loop.
1528 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1529 if (RangeStmt->isSingleDecl()) {
1530 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001531 if (RangeVar->isInvalidDecl())
1532 return StmtError();
1533
Douglas Gregorf7106af2013-04-08 18:40:13 +00001534 Expr *RangeExpr = RangeVar->getInit();
1535 if (!RangeExpr->isTypeDependent() &&
1536 RangeExpr->getType()->isObjCObjectPointerType())
1537 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1538 RParenLoc);
1539 }
1540 }
1541 }
1542
Richard Smith02e85f32011-04-14 22:09:26 +00001543 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001544 Cond, Inc, LoopVar, RParenLoc,
1545 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001546 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001547
1548 /// \brief Build a new C++0x range-based for statement.
1549 ///
1550 /// By default, performs semantic analysis to build the new statement.
1551 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001552 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001553 bool IsIfExists,
1554 NestedNameSpecifierLoc QualifierLoc,
1555 DeclarationNameInfo NameInfo,
1556 Stmt *Nested) {
1557 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1558 QualifierLoc, NameInfo, Nested);
1559 }
1560
Richard Smith02e85f32011-04-14 22:09:26 +00001561 /// \brief Attach body to a C++0x range-based for statement.
1562 ///
1563 /// By default, performs semantic analysis to finish the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
1565 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1566 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001568
David Majnemerfad8f482013-10-15 09:33:02 +00001569 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1570 Stmt *TryBlock, Stmt *Handler) {
1571 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001572 }
1573
David Majnemerfad8f482013-10-15 09:33:02 +00001574 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001575 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001576 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001577 }
1578
David Majnemerfad8f482013-10-15 09:33:02 +00001579 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1580 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001581 }
1582
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// \brief Build a new expression that references a declaration.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001588 LookupResult &R,
1589 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001590 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1591 }
1592
1593
1594 /// \brief Build a new expression that references a declaration.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001598 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 ValueDecl *VD,
1600 const DeclarationNameInfo &NameInfo,
1601 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001602 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001603 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001604
1605 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001606
1607 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001611 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001616 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 }
1618
Douglas Gregorad8a3362009-09-04 17:36:40 +00001619 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001620 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001624 SourceLocation OperatorLoc,
1625 bool isArrow,
1626 CXXScopeSpec &SS,
1627 TypeSourceInfo *ScopeType,
1628 SourceLocation CCLoc,
1629 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001630 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001637 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001638 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001639 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregor882211c2010-04-28 22:16:22 +00001642 /// \brief Build a new builtin offsetof expression.
1643 ///
1644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001646 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001647 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001648 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001649 unsigned NumComponents,
1650 SourceLocation RParenLoc) {
1651 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1652 NumComponents, RParenLoc);
1653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001654
1655 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001656 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001657 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001660 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1661 SourceLocation OpLoc,
1662 UnaryExprOrTypeTrait ExprKind,
1663 SourceRange R) {
1664 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
Peter Collingbournee190dee2011-03-11 19:24:49 +00001667 /// \brief Build a new sizeof, alignof or vec step expression with an
1668 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001669 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001672 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1673 UnaryExprOrTypeTrait ExprKind,
1674 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001676 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001679
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001680 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001684 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001687 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001689 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001691 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001692 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 RBracketLoc);
1694 }
1695
1696 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001697 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001702 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001703 Expr *ExecConfig = nullptr) {
1704 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001705 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001709 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001713 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001714 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001715 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001716 const DeclarationNameInfo &MemberNameInfo,
1717 ValueDecl *Member,
1718 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001719 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001720 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001721 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1722 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001723 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001724 // We have a reference to an unnamed field. This is always the
1725 // base of an anonymous struct/union member access, i.e. the
1726 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001727 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001728 assert(Member->getType()->isRecordType() &&
1729 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001730
Richard Smithcab9a7d2011-10-26 19:06:56 +00001731 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001732 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001733 QualifierLoc.getNestedNameSpecifier(),
1734 FoundDecl, Member);
1735 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001736 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001737 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001738 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001739 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001740 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001741 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001742 cast<FieldDecl>(Member)->getType(),
1743 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001744 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001745 }
Mike Stump11289f42009-09-09 15:08:12 +00001746
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001747 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001748 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001749
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001750 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001751 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001752
John McCall16df1e52010-03-30 21:47:33 +00001753 // FIXME: this involves duplicating earlier analysis in a lot of
1754 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001755 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001756 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001757 R.resolveKind();
1758
John McCallb268a282010-08-23 23:25:46 +00001759 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001760 SS, TemplateKWLoc,
1761 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001762 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 }
Mike Stump11289f42009-09-09 15:08:12 +00001764
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001766 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001770 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001771 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001772 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 }
1774
1775 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001780 SourceLocation QuestionLoc,
1781 Expr *LHS,
1782 SourceLocation ColonLoc,
1783 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001784 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1785 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001795 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001796 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001797 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001801 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001805 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001807 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001808 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001809 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001813 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation OpLoc,
1818 SourceLocation AccessorLoc,
1819 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001820
John McCall10eae182009-11-30 22:42:35 +00001821 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001822 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001823 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001824 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001825 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001826 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001827 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001828 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
Mike Stump11289f42009-09-09 15:08:12 +00001830
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001836 MultiExprArg Inits,
1837 SourceLocation RBraceLoc,
1838 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001840 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001841 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001842 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001843
Douglas Gregord3d93062009-11-09 17:16:50 +00001844 // Patch in the result type we were given, which may have been computed
1845 // when the initial InitListExpr was built.
1846 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1847 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001848 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 MultiExprArg ArrayExprs,
1857 SourceLocation EqualOrColonLoc,
1858 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001859 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001862 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001865
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001866 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 }
Mike Stump11289f42009-09-09 15:08:12 +00001868
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001870 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// By default, builds the implicit value initialization without performing
1872 /// any semantic analysis. Subclasses may override this routine to provide
1873 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001874 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001875 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 }
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001879 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001883 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001884 SourceLocation RParenLoc) {
1885 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001886 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001887 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 }
1889
1890 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001891 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001895 MultiExprArg SubExprs,
1896 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001897 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 }
Mike Stump11289f42009-09-09 15:08:12 +00001899
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001901 ///
1902 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// rather than attempting to map the label statement itself.
1904 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001906 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001907 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 }
Mike Stump11289f42009-09-09 15:08:12 +00001909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001911 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001915 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001917 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 }
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 /// \brief Build a new __builtin_choose_expr expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001925 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 SourceLocation RParenLoc) {
1927 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001928 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 RParenLoc);
1930 }
Mike Stump11289f42009-09-09 15:08:12 +00001931
Peter Collingbourne91147592011-04-15 00:35:48 +00001932 /// \brief Build a new generic selection expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1937 SourceLocation DefaultLoc,
1938 SourceLocation RParenLoc,
1939 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001940 ArrayRef<TypeSourceInfo *> Types,
1941 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001942 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001943 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001944 }
1945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new overloaded operator call expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// The semantic analysis provides the behavior of template instantiation,
1950 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001951 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// argument-dependent lookup, etc. Subclasses may override this routine to
1953 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001956 Expr *Callee,
1957 Expr *First,
1958 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001959
1960 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 /// reinterpret_cast.
1962 ///
1963 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001964 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 Stmt::StmtClass Class,
1968 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001969 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 SourceLocation RAngleLoc,
1971 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001972 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 SourceLocation RParenLoc) {
1974 switch (Class) {
1975 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001976 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001977 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001979
1980 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001981 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001982 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001986 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001987 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001988 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001992 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001993 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001994 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001997 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 }
Mike Stump11289f42009-09-09 15:08:12 +00002000
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// \brief Build a new C++ static_cast expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002005 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002007 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 SourceLocation RAngleLoc,
2009 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002012 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002013 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002014 SourceRange(LAngleLoc, RAngleLoc),
2015 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
2017
2018 /// \brief Build a new C++ dynamic_cast expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002024 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 SourceLocation RAngleLoc,
2026 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002029 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002030 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002031 SourceRange(LAngleLoc, RAngleLoc),
2032 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new C++ reinterpret_cast expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002039 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002041 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 SourceLocation RAngleLoc,
2043 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002044 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002046 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002047 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002048 SourceRange(LAngleLoc, RAngleLoc),
2049 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
2051
2052 /// \brief Build a new C++ const_cast expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002058 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation RAngleLoc,
2060 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002061 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002063 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002064 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002065 SourceRange(LAngleLoc, RAngleLoc),
2066 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// \brief Build a new C++ functional-style cast expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002073 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2074 SourceLocation LParenLoc,
2075 Expr *Sub,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002078 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 RParenLoc);
2080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// \brief Build a new C++ typeid(type) expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002086 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002087 SourceLocation TypeidLoc,
2088 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002090 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002091 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Francois Pichet9f4f2072010-09-08 12:20:18 +00002094
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// \brief Build a new C++ typeid(expr) expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002100 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002101 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002103 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002104 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002105 }
2106
Francois Pichet9f4f2072010-09-08 12:20:18 +00002107 /// \brief Build a new C++ __uuidof(type) expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2112 SourceLocation TypeidLoc,
2113 TypeSourceInfo *Operand,
2114 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002115 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002116 RParenLoc);
2117 }
2118
2119 /// \brief Build a new C++ __uuidof(expr) expression.
2120 ///
2121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
2123 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2124 SourceLocation TypeidLoc,
2125 Expr *Operand,
2126 SourceLocation RParenLoc) {
2127 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2128 RParenLoc);
2129 }
2130
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 /// \brief Build a new C++ "this" expression.
2132 ///
2133 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002134 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002137 QualType ThisType,
2138 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002139 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002140 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 }
2142
2143 /// \brief Build a new C++ throw expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002147 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2148 bool IsThrownVariableInScope) {
2149 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
2151
2152 /// \brief Build a new C++ default-argument expression.
2153 ///
2154 /// By default, builds a new default-argument expression, which does not
2155 /// require any semantic analysis. Subclasses may override this routine to
2156 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002157 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002158 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002159 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
2161
Richard Smith852c9db2013-04-20 22:23:05 +00002162 /// \brief Build a new C++11 default-initialization expression.
2163 ///
2164 /// By default, builds a new default field initialization expression, which
2165 /// does not require any semantic analysis. Subclasses may override this
2166 /// routine to provide different behavior.
2167 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2168 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002169 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002170 }
2171
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// \brief Build a new C++ zero-initialization expression.
2173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002176 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2177 SourceLocation LParenLoc,
2178 SourceLocation RParenLoc) {
2179 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002180 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new C++ "new" expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002188 bool UseGlobal,
2189 SourceLocation PlacementLParen,
2190 MultiExprArg PlacementArgs,
2191 SourceLocation PlacementRParen,
2192 SourceRange TypeIdParens,
2193 QualType AllocatedType,
2194 TypeSourceInfo *AllocatedTypeInfo,
2195 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002196 SourceRange DirectInitRange,
2197 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002198 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002200 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002202 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002203 AllocatedType,
2204 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002205 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002206 DirectInitRange,
2207 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// \brief Build a new C++ "delete" expression.
2211 ///
2212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002214 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 bool IsGlobalDelete,
2216 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002217 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002219 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 }
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregor29c42f22012-02-24 07:38:34 +00002222 /// \brief Build a new type trait expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
2226 ExprResult RebuildTypeTrait(TypeTrait Trait,
2227 SourceLocation StartLoc,
2228 ArrayRef<TypeSourceInfo *> Args,
2229 SourceLocation RParenLoc) {
2230 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2231 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002232
John Wiegley6242b6a2011-04-28 00:16:57 +00002233 /// \brief Build a new array type trait expression.
2234 ///
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
2237 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2238 SourceLocation StartLoc,
2239 TypeSourceInfo *TSInfo,
2240 Expr *DimExpr,
2241 SourceLocation RParenLoc) {
2242 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2243 }
2244
John Wiegleyf9f65842011-04-25 06:54:41 +00002245 /// \brief Build a new expression trait expression.
2246 ///
2247 /// By default, performs semantic analysis to build the new expression.
2248 /// Subclasses may override this routine to provide different behavior.
2249 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2250 SourceLocation StartLoc,
2251 Expr *Queried,
2252 SourceLocation RParenLoc) {
2253 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2254 }
2255
Mike Stump11289f42009-09-09 15:08:12 +00002256 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 /// expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002261 ExprResult RebuildDependentScopeDeclRefExpr(
2262 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002263 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002264 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002265 const TemplateArgumentListInfo *TemplateArgs,
2266 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002268 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002269
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002270 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002271 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002272 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002273
Richard Smithdb2630f2012-10-21 03:28:35 +00002274 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2275 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 }
2277
2278 /// \brief Build a new template-id expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002283 SourceLocation TemplateKWLoc,
2284 LookupResult &R,
2285 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002286 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002287 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2288 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
2290
2291 /// \brief Build a new object-construction expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002296 SourceLocation Loc,
2297 CXXConstructorDecl *Constructor,
2298 bool IsElidable,
2299 MultiExprArg Args,
2300 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002301 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002302 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002303 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002304 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002305 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002306 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002307 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002309
Douglas Gregordb121ba2009-12-14 16:27:04 +00002310 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002311 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002312 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002313 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002314 RequiresZeroInit, ConstructKind,
2315 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 }
2317
2318 /// \brief Build a new object-construction expression.
2319 ///
2320 /// By default, performs semantic analysis to build the new expression.
2321 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002322 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2323 SourceLocation LParenLoc,
2324 MultiExprArg Args,
2325 SourceLocation RParenLoc) {
2326 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002328 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 RParenLoc);
2330 }
2331
2332 /// \brief Build a new object-construction expression.
2333 ///
2334 /// By default, performs semantic analysis to build the new expression.
2335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002336 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2337 SourceLocation LParenLoc,
2338 MultiExprArg Args,
2339 SourceLocation RParenLoc) {
2340 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002342 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 RParenLoc);
2344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 /// \brief Build a new member reference expression.
2347 ///
2348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002351 QualType BaseType,
2352 bool IsArrow,
2353 SourceLocation OperatorLoc,
2354 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002355 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002356 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002357 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002358 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002360 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002361
John McCallb268a282010-08-23 23:25:46 +00002362 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002363 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002364 SS, TemplateKWLoc,
2365 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002366 MemberNameInfo,
2367 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 }
2369
John McCall10eae182009-11-30 22:42:35 +00002370 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002371 ///
2372 /// By default, performs semantic analysis to build the new expression.
2373 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002374 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2375 SourceLocation OperatorLoc,
2376 bool IsArrow,
2377 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002378 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002379 NamedDecl *FirstQualifierInScope,
2380 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002381 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002382 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002383 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002384
John McCallb268a282010-08-23 23:25:46 +00002385 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002386 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002387 SS, TemplateKWLoc,
2388 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002389 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002392 /// \brief Build a new noexcept expression.
2393 ///
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
2396 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2397 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2398 }
2399
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002400 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002401 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2402 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002403 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002404 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002405 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002406 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2407 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002408 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002409
2410 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2411 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002412 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002413 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002414
Patrick Beard0caa3942012-04-19 00:25:12 +00002415 /// \brief Build a new Objective-C boxed expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
2419 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2420 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002422
Ted Kremeneke65b0862012-03-06 20:05:56 +00002423 /// \brief Build a new Objective-C array literal.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
2427 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2428 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002429 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002430 MultiExprArg(Elements, NumElements));
2431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002432
2433 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002434 Expr *Base, Expr *Key,
2435 ObjCMethodDecl *getterMethod,
2436 ObjCMethodDecl *setterMethod) {
2437 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2438 getterMethod, setterMethod);
2439 }
2440
2441 /// \brief Build a new Objective-C dictionary literal.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
2445 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2446 ObjCDictionaryElement *Elements,
2447 unsigned NumElements) {
2448 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002450
James Dennett2a4d13c2012-06-15 07:13:21 +00002451 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002455 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002456 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002458 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002459 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002460
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002461 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002462 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002464 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002465 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002466 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002467 MultiExprArg Args,
2468 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2470 ReceiverTypeInfo->getType(),
2471 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002472 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002473 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002474 }
2475
2476 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002478 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002479 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002480 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002481 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002482 MultiExprArg Args,
2483 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002484 return SemaRef.BuildInstanceMessage(Receiver,
2485 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002487 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002488 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002489 }
2490
Douglas Gregord51d90d2010-04-26 20:11:03 +00002491 /// \brief Build a new Objective-C ivar reference expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002495 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002496 SourceLocation IvarLoc,
2497 bool IsArrow, bool IsFreeIvar) {
2498 // FIXME: We lose track of the IsFreeIvar bit.
2499 CXXScopeSpec SS;
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002500 ExprResult Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002501 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2502 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002503 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002504 /*FIME:*/IvarLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002505 SS, nullptr,
John McCalle9cccd82010-06-16 08:42:20 +00002506 false);
John Wiegley01296292011-04-08 18:41:53 +00002507 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002508 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002509
Douglas Gregord51d90d2010-04-26 20:11:03 +00002510 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002511 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002512
John Wiegley01296292011-04-08 18:41:53 +00002513 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002514 /*FIXME:*/IvarLoc, IsArrow,
2515 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002516 /*FirstQualifierInScope=*/nullptr,
Chad Rosier1dcde962012-08-08 18:46:20 +00002517 R,
Craig Topperc3ec1492014-05-26 06:22:03 +00002518 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002519 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002520
2521 /// \brief Build a new Objective-C property reference expression.
2522 ///
2523 /// By default, performs semantic analysis to build the new expression.
2524 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002525 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002526 ObjCPropertyDecl *Property,
2527 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002528 CXXScopeSpec SS;
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002529 ExprResult Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002530 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2531 Sema::LookupMemberName);
2532 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002533 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002534 /*FIME:*/PropertyLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002535 SS, nullptr, false);
John Wiegley01296292011-04-08 18:41:53 +00002536 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002537 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002538
Douglas Gregor9faee212010-04-26 20:47:02 +00002539 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002540 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002541
John Wiegley01296292011-04-08 18:41:53 +00002542 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002543 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002544 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002545 /*FirstQualifierInScope=*/nullptr,
2546 R, /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002548
John McCallb7bd14f2010-12-02 01:19:52 +00002549 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002550 ///
2551 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002552 /// Subclasses may override this routine to provide different behavior.
2553 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2554 ObjCMethodDecl *Getter,
2555 ObjCMethodDecl *Setter,
2556 SourceLocation PropertyLoc) {
2557 // Since these expressions can only be value-dependent, we do not
2558 // need to perform semantic analysis again.
2559 return Owned(
2560 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2561 VK_LValue, OK_ObjCProperty,
2562 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002563 }
2564
Douglas Gregord51d90d2010-04-26 20:11:03 +00002565 /// \brief Build a new Objective-C "isa" expression.
2566 ///
2567 /// By default, performs semantic analysis to build the new expression.
2568 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002569 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002570 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002571 bool IsArrow) {
2572 CXXScopeSpec SS;
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002573 ExprResult Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002574 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2575 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002576 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002577 OpLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002578 SS, nullptr, false);
John Wiegley01296292011-04-08 18:41:53 +00002579 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002581
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002583 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002584
John Wiegley01296292011-04-08 18:41:53 +00002585 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002586 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002587 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002588 /*FirstQualifierInScope=*/nullptr,
Chad Rosier1dcde962012-08-08 18:46:20 +00002589 R,
Craig Topperc3ec1492014-05-26 06:22:03 +00002590 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002592
Douglas Gregora16548e2009-08-11 05:31:07 +00002593 /// \brief Build a new shuffle vector expression.
2594 ///
2595 /// By default, performs semantic analysis to build the new expression.
2596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002597 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002598 MultiExprArg SubExprs,
2599 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002601 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2603 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2604 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002605 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002606
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002608 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002609 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2610 SemaRef.Context.BuiltinFnTy,
2611 VK_RValue, BuiltinLoc);
2612 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2613 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002614 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002615
2616 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002617 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002618 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002619 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregora16548e2009-08-11 05:31:07 +00002621 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002622 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 }
John McCall31f82722010-11-12 08:19:04 +00002624
Hal Finkelc4d7c822013-09-18 03:29:45 +00002625 /// \brief Build a new convert vector expression.
2626 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2627 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2628 SourceLocation RParenLoc) {
2629 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2630 BuiltinLoc, RParenLoc);
2631 }
2632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002633 /// \brief Build a new template argument pack expansion.
2634 ///
2635 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002636 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002637 /// different behavior.
2638 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002639 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002640 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002641 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002642 case TemplateArgument::Expression: {
2643 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002644 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2645 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002646 if (Result.isInvalid())
2647 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002648
Douglas Gregor98318c22011-01-03 21:37:45 +00002649 return TemplateArgumentLoc(Result.get(), Result.get());
2650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002651
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002652 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002653 return TemplateArgumentLoc(TemplateArgument(
2654 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002655 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002656 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002657 Pattern.getTemplateNameLoc(),
2658 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002659
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002660 case TemplateArgument::Null:
2661 case TemplateArgument::Integral:
2662 case TemplateArgument::Declaration:
2663 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002664 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002665 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002666 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002667
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002668 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002669 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002670 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002671 EllipsisLoc,
2672 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002673 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2674 Expansion);
2675 break;
2676 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002677
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002678 return TemplateArgumentLoc();
2679 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002680
Douglas Gregor968f23a2011-01-03 19:31:53 +00002681 /// \brief Build a new expression pack expansion.
2682 ///
2683 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002684 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002685 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002686 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002687 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002688 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002689 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002690
2691 /// \brief Build a new atomic operation expression.
2692 ///
2693 /// By default, performs semantic analysis to build the new expression.
2694 /// Subclasses may override this routine to provide different behavior.
2695 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2696 MultiExprArg SubExprs,
2697 QualType RetTy,
2698 AtomicExpr::AtomicOp Op,
2699 SourceLocation RParenLoc) {
2700 // Just create the expression; there is not any interesting semantic
2701 // analysis here because we can't actually build an AtomicExpr until
2702 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002703 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002704 RParenLoc);
2705 }
2706
John McCall31f82722010-11-12 08:19:04 +00002707private:
Douglas Gregor14454802011-02-25 02:25:35 +00002708 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2709 QualType ObjectType,
2710 NamedDecl *FirstQualifierInScope,
2711 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002712
2713 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2714 QualType ObjectType,
2715 NamedDecl *FirstQualifierInScope,
2716 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002717
2718 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2719 NamedDecl *FirstQualifierInScope,
2720 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002721};
Douglas Gregora16548e2009-08-11 05:31:07 +00002722
Douglas Gregorebe10102009-08-20 07:17:43 +00002723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002724StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002725 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002726 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregorebe10102009-08-20 07:17:43 +00002728 switch (S->getStmtClass()) {
2729 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002730
Douglas Gregorebe10102009-08-20 07:17:43 +00002731 // Transform individual statement nodes
2732#define STMT(Node, Parent) \
2733 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002734#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002735#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002736#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002737
Douglas Gregorebe10102009-08-20 07:17:43 +00002738 // Transform expressions by calling TransformExpr.
2739#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002740#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002741#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002742#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002743 {
John McCalldadc5752010-08-24 06:29:42 +00002744 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002745 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002746 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002747
Richard Smith945f8d32013-01-14 22:39:08 +00002748 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002749 }
Mike Stump11289f42009-09-09 15:08:12 +00002750 }
2751
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002752 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002753}
Mike Stump11289f42009-09-09 15:08:12 +00002754
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002755template<typename Derived>
2756OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2757 if (!S)
2758 return S;
2759
2760 switch (S->getClauseKind()) {
2761 default: break;
2762 // Transform individual clause nodes
2763#define OPENMP_CLAUSE(Name, Class) \
2764 case OMPC_ ## Name : \
2765 return getDerived().Transform ## Class(cast<Class>(S));
2766#include "clang/Basic/OpenMPKinds.def"
2767 }
2768
2769 return S;
2770}
2771
Mike Stump11289f42009-09-09 15:08:12 +00002772
Douglas Gregore922c772009-08-04 22:27:00 +00002773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002774ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002776 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002777
2778 switch (E->getStmtClass()) {
2779 case Stmt::NoStmtClass: break;
2780#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002781#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002782#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002783 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002784#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002785 }
2786
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002787 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002788}
2789
2790template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002791ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2792 bool CXXDirectInit) {
2793 // Initializers are instantiated like expressions, except that various outer
2794 // layers are stripped.
2795 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002796 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002797
2798 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2799 Init = ExprTemp->getSubExpr();
2800
Richard Smithe6ca4752013-05-30 22:40:16 +00002801 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2802 Init = MTE->GetTemporaryExpr();
2803
Richard Smithd59b8322012-12-19 01:39:02 +00002804 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2805 Init = Binder->getSubExpr();
2806
2807 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2808 Init = ICE->getSubExprAsWritten();
2809
Richard Smithcc1b96d2013-06-12 22:31:48 +00002810 if (CXXStdInitializerListExpr *ILE =
2811 dyn_cast<CXXStdInitializerListExpr>(Init))
2812 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2813
Richard Smith38a549b2012-12-21 08:13:35 +00002814 // If this is not a direct-initializer, we only need to reconstruct
2815 // InitListExprs. Other forms of copy-initialization will be a no-op if
2816 // the initializer is already the right type.
2817 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2818 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2819 return getDerived().TransformExpr(Init);
2820
2821 // Revert value-initialization back to empty parens.
2822 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2823 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002824 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002825 Parens.getEnd());
2826 }
2827
2828 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2829 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002830 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002831 SourceLocation());
2832
2833 // Revert initialization by constructor back to a parenthesized or braced list
2834 // of expressions. Any other form of initializer can just be reused directly.
2835 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002836 return getDerived().TransformExpr(Init);
2837
2838 SmallVector<Expr*, 8> NewArgs;
2839 bool ArgChanged = false;
2840 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2841 /*IsCall*/true, NewArgs, &ArgChanged))
2842 return ExprError();
2843
2844 // If this was list initialization, revert to list form.
2845 if (Construct->isListInitialization())
2846 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2847 Construct->getLocEnd(),
2848 Construct->getType());
2849
Richard Smithd59b8322012-12-19 01:39:02 +00002850 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002851 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002852 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2853 Parens.getEnd());
2854}
2855
2856template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002857bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2858 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002859 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002860 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002861 bool *ArgChanged) {
2862 for (unsigned I = 0; I != NumInputs; ++I) {
2863 // If requested, drop call arguments that need to be dropped.
2864 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2865 if (ArgChanged)
2866 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002867
Douglas Gregora3efea12011-01-03 19:04:46 +00002868 break;
2869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002870
Douglas Gregor968f23a2011-01-03 19:31:53 +00002871 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2872 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002873
Chris Lattner01cf8db2011-07-20 06:58:45 +00002874 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2876 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Douglas Gregor968f23a2011-01-03 19:31:53 +00002878 // Determine whether the set of unexpanded parameter packs can and should
2879 // be expanded.
2880 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002881 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002882 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2883 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002884 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2885 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002886 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002887 Expand, RetainExpansion,
2888 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002889 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
Douglas Gregor968f23a2011-01-03 19:31:53 +00002891 if (!Expand) {
2892 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002893 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002894 // expansion.
2895 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2896 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2897 if (OutPattern.isInvalid())
2898 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002899
2900 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002901 Expansion->getEllipsisLoc(),
2902 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002903 if (Out.isInvalid())
2904 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002905
Douglas Gregor968f23a2011-01-03 19:31:53 +00002906 if (ArgChanged)
2907 *ArgChanged = true;
2908 Outputs.push_back(Out.get());
2909 continue;
2910 }
John McCall542e7c62011-07-06 07:30:07 +00002911
2912 // Record right away that the argument was changed. This needs
2913 // to happen even if the array expands to nothing.
2914 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002915
Douglas Gregor968f23a2011-01-03 19:31:53 +00002916 // The transform has determined that we should perform an elementwise
2917 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002918 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2920 ExprResult Out = getDerived().TransformExpr(Pattern);
2921 if (Out.isInvalid())
2922 return true;
2923
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002924 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002925 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2926 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002927 if (Out.isInvalid())
2928 return true;
2929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregor968f23a2011-01-03 19:31:53 +00002931 Outputs.push_back(Out.get());
2932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregor968f23a2011-01-03 19:31:53 +00002934 continue;
2935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Richard Smithd59b8322012-12-19 01:39:02 +00002937 ExprResult Result =
2938 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2939 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002940 if (Result.isInvalid())
2941 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002942
Douglas Gregora3efea12011-01-03 19:04:46 +00002943 if (Result.get() != Inputs[I] && ArgChanged)
2944 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002945
2946 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregora3efea12011-01-03 19:04:46 +00002949 return false;
2950}
2951
2952template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002953NestedNameSpecifierLoc
2954TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2955 NestedNameSpecifierLoc NNS,
2956 QualType ObjectType,
2957 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002958 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002959 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002960 Qualifier = Qualifier.getPrefix())
2961 Qualifiers.push_back(Qualifier);
2962
2963 CXXScopeSpec SS;
2964 while (!Qualifiers.empty()) {
2965 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2966 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002967
Douglas Gregor14454802011-02-25 02:25:35 +00002968 switch (QNNS->getKind()) {
2969 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002970 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002971 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002972 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002973 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002974 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002975 FirstQualifierInScope, false))
2976 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
Douglas Gregor14454802011-02-25 02:25:35 +00002978 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002979
Douglas Gregor14454802011-02-25 02:25:35 +00002980 case NestedNameSpecifier::Namespace: {
2981 NamespaceDecl *NS
2982 = cast_or_null<NamespaceDecl>(
2983 getDerived().TransformDecl(
2984 Q.getLocalBeginLoc(),
2985 QNNS->getAsNamespace()));
2986 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2987 break;
2988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregor14454802011-02-25 02:25:35 +00002990 case NestedNameSpecifier::NamespaceAlias: {
2991 NamespaceAliasDecl *Alias
2992 = cast_or_null<NamespaceAliasDecl>(
2993 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2994 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002995 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002996 Q.getLocalEndLoc());
2997 break;
2998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor14454802011-02-25 02:25:35 +00003000 case NestedNameSpecifier::Global:
3001 // There is no meaningful transformation that one could perform on the
3002 // global scope.
3003 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3004 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003005
Douglas Gregor14454802011-02-25 02:25:35 +00003006 case NestedNameSpecifier::TypeSpecWithTemplate:
3007 case NestedNameSpecifier::TypeSpec: {
3008 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3009 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor14454802011-02-25 02:25:35 +00003011 if (!TL)
3012 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor14454802011-02-25 02:25:35 +00003014 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003015 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003016 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003017 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003018 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003019 if (TL.getType()->isEnumeralType())
3020 SemaRef.Diag(TL.getBeginLoc(),
3021 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003022 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3023 Q.getLocalEndLoc());
3024 break;
3025 }
Richard Trieude756fb2011-05-07 01:36:37 +00003026 // If the nested-name-specifier is an invalid type def, don't emit an
3027 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003028 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3029 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003030 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003031 << TL.getType() << SS.getRange();
3032 }
Douglas Gregor14454802011-02-25 02:25:35 +00003033 return NestedNameSpecifierLoc();
3034 }
Douglas Gregore16af532011-02-28 18:50:33 +00003035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003036
Douglas Gregore16af532011-02-28 18:50:33 +00003037 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003038 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003039 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003040 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003041
Douglas Gregor14454802011-02-25 02:25:35 +00003042 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003043 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003044 !getDerived().AlwaysRebuild())
3045 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003046
3047 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003048 // nested-name-specifier, do so.
3049 if (SS.location_size() == NNS.getDataLength() &&
3050 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3051 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3052
3053 // Allocate new nested-name-specifier location information.
3054 return SS.getWithLocInContext(SemaRef.Context);
3055}
3056
3057template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003058DeclarationNameInfo
3059TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003060::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003061 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003062 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003063 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003064
3065 switch (Name.getNameKind()) {
3066 case DeclarationName::Identifier:
3067 case DeclarationName::ObjCZeroArgSelector:
3068 case DeclarationName::ObjCOneArgSelector:
3069 case DeclarationName::ObjCMultiArgSelector:
3070 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003071 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003072 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003073 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003074
Douglas Gregorf816bd72009-09-03 22:13:48 +00003075 case DeclarationName::CXXConstructorName:
3076 case DeclarationName::CXXDestructorName:
3077 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003078 TypeSourceInfo *NewTInfo;
3079 CanQualType NewCanTy;
3080 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003081 NewTInfo = getDerived().TransformType(OldTInfo);
3082 if (!NewTInfo)
3083 return DeclarationNameInfo();
3084 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003085 }
3086 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003087 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003088 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003089 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003090 if (NewT.isNull())
3091 return DeclarationNameInfo();
3092 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3093 }
Mike Stump11289f42009-09-09 15:08:12 +00003094
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003095 DeclarationName NewName
3096 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3097 NewCanTy);
3098 DeclarationNameInfo NewNameInfo(NameInfo);
3099 NewNameInfo.setName(NewName);
3100 NewNameInfo.setNamedTypeInfo(NewTInfo);
3101 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003102 }
Mike Stump11289f42009-09-09 15:08:12 +00003103 }
3104
David Blaikie83d382b2011-09-23 05:06:16 +00003105 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003106}
3107
3108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003109TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003110TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3111 TemplateName Name,
3112 SourceLocation NameLoc,
3113 QualType ObjectType,
3114 NamedDecl *FirstQualifierInScope) {
3115 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3116 TemplateDecl *Template = QTN->getTemplateDecl();
3117 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor9db53502011-03-02 18:07:45 +00003119 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003120 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003121 Template));
3122 if (!TransTemplate)
3123 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor9db53502011-03-02 18:07:45 +00003125 if (!getDerived().AlwaysRebuild() &&
3126 SS.getScopeRep() == QTN->getQualifier() &&
3127 TransTemplate == Template)
3128 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003129
Douglas Gregor9db53502011-03-02 18:07:45 +00003130 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3131 TransTemplate);
3132 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003133
Douglas Gregor9db53502011-03-02 18:07:45 +00003134 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3135 if (SS.getScopeRep()) {
3136 // These apply to the scope specifier, not the template.
3137 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003138 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003139 }
3140
Douglas Gregor9db53502011-03-02 18:07:45 +00003141 if (!getDerived().AlwaysRebuild() &&
3142 SS.getScopeRep() == DTN->getQualifier() &&
3143 ObjectType.isNull())
3144 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003145
Douglas Gregor9db53502011-03-02 18:07:45 +00003146 if (DTN->isIdentifier()) {
3147 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003148 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003149 NameLoc,
3150 ObjectType,
3151 FirstQualifierInScope);
3152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
Douglas Gregor9db53502011-03-02 18:07:45 +00003154 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3155 ObjectType);
3156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor9db53502011-03-02 18:07:45 +00003158 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3159 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003160 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003161 Template));
3162 if (!TransTemplate)
3163 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003164
Douglas Gregor9db53502011-03-02 18:07:45 +00003165 if (!getDerived().AlwaysRebuild() &&
3166 TransTemplate == Template)
3167 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003168
Douglas Gregor9db53502011-03-02 18:07:45 +00003169 return TemplateName(TransTemplate);
3170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003171
Douglas Gregor9db53502011-03-02 18:07:45 +00003172 if (SubstTemplateTemplateParmPackStorage *SubstPack
3173 = Name.getAsSubstTemplateTemplateParmPack()) {
3174 TemplateTemplateParmDecl *TransParam
3175 = cast_or_null<TemplateTemplateParmDecl>(
3176 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3177 if (!TransParam)
3178 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003179
Douglas Gregor9db53502011-03-02 18:07:45 +00003180 if (!getDerived().AlwaysRebuild() &&
3181 TransParam == SubstPack->getParameterPack())
3182 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003183
3184 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003185 SubstPack->getArgumentPack());
3186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
Douglas Gregor9db53502011-03-02 18:07:45 +00003188 // These should be getting filtered out before they reach the AST.
3189 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003190}
3191
3192template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003193void TreeTransform<Derived>::InventTemplateArgumentLoc(
3194 const TemplateArgument &Arg,
3195 TemplateArgumentLoc &Output) {
3196 SourceLocation Loc = getDerived().getBaseLocation();
3197 switch (Arg.getKind()) {
3198 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003199 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003200 break;
3201
3202 case TemplateArgument::Type:
3203 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003204 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
John McCall0ad16662009-10-29 08:12:44 +00003206 break;
3207
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003208 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003209 case TemplateArgument::TemplateExpansion: {
3210 NestedNameSpecifierLocBuilder Builder;
3211 TemplateName Template = Arg.getAsTemplate();
3212 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3213 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3214 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3215 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003216
Douglas Gregor9d802122011-03-02 17:09:35 +00003217 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003218 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003219 Builder.getWithLocInContext(SemaRef.Context),
3220 Loc);
3221 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003222 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003223 Builder.getWithLocInContext(SemaRef.Context),
3224 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003225
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003226 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003227 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003228
John McCall0ad16662009-10-29 08:12:44 +00003229 case TemplateArgument::Expression:
3230 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3231 break;
3232
3233 case TemplateArgument::Declaration:
3234 case TemplateArgument::Integral:
3235 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003236 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003237 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003238 break;
3239 }
3240}
3241
3242template<typename Derived>
3243bool TreeTransform<Derived>::TransformTemplateArgument(
3244 const TemplateArgumentLoc &Input,
3245 TemplateArgumentLoc &Output) {
3246 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003247 switch (Arg.getKind()) {
3248 case TemplateArgument::Null:
3249 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003250 case TemplateArgument::Pack:
3251 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003252 case TemplateArgument::NullPtr:
3253 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregore922c772009-08-04 22:27:00 +00003255 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003256 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003257 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003258 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003259
3260 DI = getDerived().TransformType(DI);
3261 if (!DI) return true;
3262
3263 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3264 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003265 }
Mike Stump11289f42009-09-09 15:08:12 +00003266
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003267 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003268 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3269 if (QualifierLoc) {
3270 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3271 if (!QualifierLoc)
3272 return true;
3273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregordf846d12011-03-02 18:46:51 +00003275 CXXScopeSpec SS;
3276 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003277 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003278 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3279 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003280 if (Template.isNull())
3281 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregor9d802122011-03-02 17:09:35 +00003283 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003284 Input.getTemplateNameLoc());
3285 return false;
3286 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003287
3288 case TemplateArgument::TemplateExpansion:
3289 llvm_unreachable("Caller should expand pack expansions");
3290
Douglas Gregore922c772009-08-04 22:27:00 +00003291 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003292 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003293 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003294 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall0ad16662009-10-29 08:12:44 +00003296 Expr *InputExpr = Input.getSourceExpression();
3297 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3298
Chris Lattnercdb591a2011-04-25 20:37:58 +00003299 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003300 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003301 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003302 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003303 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003304 }
Douglas Gregore922c772009-08-04 22:27:00 +00003305 }
Mike Stump11289f42009-09-09 15:08:12 +00003306
Douglas Gregore922c772009-08-04 22:27:00 +00003307 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003308 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003309}
3310
Douglas Gregorfe921a72010-12-20 23:36:19 +00003311/// \brief Iterator adaptor that invents template argument location information
3312/// for each of the template arguments in its underlying iterator.
3313template<typename Derived, typename InputIterator>
3314class TemplateArgumentLocInventIterator {
3315 TreeTransform<Derived> &Self;
3316 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003317
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318public:
3319 typedef TemplateArgumentLoc value_type;
3320 typedef TemplateArgumentLoc reference;
3321 typedef typename std::iterator_traits<InputIterator>::difference_type
3322 difference_type;
3323 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregorfe921a72010-12-20 23:36:19 +00003325 class pointer {
3326 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregorfe921a72010-12-20 23:36:19 +00003328 public:
3329 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregorfe921a72010-12-20 23:36:19 +00003331 const TemplateArgumentLoc *operator->() const { return &Arg; }
3332 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
Douglas Gregorfe921a72010-12-20 23:36:19 +00003334 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3337 InputIterator Iter)
3338 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregorfe921a72010-12-20 23:36:19 +00003340 TemplateArgumentLocInventIterator &operator++() {
3341 ++Iter;
3342 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Douglas Gregorfe921a72010-12-20 23:36:19 +00003345 TemplateArgumentLocInventIterator operator++(int) {
3346 TemplateArgumentLocInventIterator Old(*this);
3347 ++(*this);
3348 return Old;
3349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregorfe921a72010-12-20 23:36:19 +00003351 reference operator*() const {
3352 TemplateArgumentLoc Result;
3353 Self.InventTemplateArgumentLoc(*Iter, Result);
3354 return Result;
3355 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003356
Douglas Gregorfe921a72010-12-20 23:36:19 +00003357 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003358
Douglas Gregorfe921a72010-12-20 23:36:19 +00003359 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3360 const TemplateArgumentLocInventIterator &Y) {
3361 return X.Iter == Y.Iter;
3362 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003363
Douglas Gregorfe921a72010-12-20 23:36:19 +00003364 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3365 const TemplateArgumentLocInventIterator &Y) {
3366 return X.Iter != Y.Iter;
3367 }
3368};
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor42cafa82010-12-20 17:42:22 +00003370template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003371template<typename InputIterator>
3372bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3373 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003374 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003375 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003376 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003377 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003379 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3380 // Unpack argument packs, which we translate them into separate
3381 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003382 // FIXME: We could do much better if we could guarantee that the
3383 // TemplateArgumentLocInfo for the pack expansion would be usable for
3384 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003385 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003386 TemplateArgument::pack_iterator>
3387 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003388 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003389 In.getArgument().pack_begin()),
3390 PackLocIterator(*this,
3391 In.getArgument().pack_end()),
3392 Outputs))
3393 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003394
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003395 continue;
3396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003398 if (In.getArgument().isPackExpansion()) {
3399 // We have a pack expansion, for which we will be substituting into
3400 // the pattern.
3401 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003402 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003403 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003404 = getSema().getTemplateArgumentPackExpansionPattern(
3405 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Chris Lattner01cf8db2011-07-20 06:58:45 +00003407 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003408 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3409 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003411 // Determine whether the set of unexpanded parameter packs can and should
3412 // be expanded.
3413 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003414 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003415 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003416 if (getDerived().TryExpandParameterPacks(Ellipsis,
3417 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003418 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003419 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003420 RetainExpansion,
3421 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003422 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003424 if (!Expand) {
3425 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003426 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003427 // expansion.
3428 TemplateArgumentLoc OutPattern;
3429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3430 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3431 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003433 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3434 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003435 if (Out.getArgument().isNull())
3436 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003438 Outputs.addArgument(Out);
3439 continue;
3440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003442 // The transform has determined that we should perform an elementwise
3443 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003444 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003445 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3446
3447 if (getDerived().TransformTemplateArgument(Pattern, Out))
3448 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003450 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003451 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3452 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003453 if (Out.getArgument().isNull())
3454 return true;
3455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003457 Outputs.addArgument(Out);
3458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregor48d24112011-01-10 20:53:55 +00003460 // If we're supposed to retain a pack expansion, do so by temporarily
3461 // forgetting the partially-substituted parameter pack.
3462 if (RetainExpansion) {
3463 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor48d24112011-01-10 20:53:55 +00003465 if (getDerived().TransformTemplateArgument(Pattern, Out))
3466 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003468 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3469 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003470 if (Out.getArgument().isNull())
3471 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor48d24112011-01-10 20:53:55 +00003473 Outputs.addArgument(Out);
3474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003476 continue;
3477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003478
3479 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003480 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003481 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
Douglas Gregor42cafa82010-12-20 17:42:22 +00003483 Outputs.addArgument(Out);
3484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor42cafa82010-12-20 17:42:22 +00003486 return false;
3487
3488}
3489
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490//===----------------------------------------------------------------------===//
3491// Type transformation
3492//===----------------------------------------------------------------------===//
3493
3494template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003495QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003496 if (getDerived().AlreadyTransformed(T))
3497 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003498
John McCall550e0c22009-10-21 00:40:46 +00003499 // Temporary workaround. All of these transformations should
3500 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003501 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3502 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
John McCall31f82722010-11-12 08:19:04 +00003504 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003505
John McCall550e0c22009-10-21 00:40:46 +00003506 if (!NewDI)
3507 return QualType();
3508
3509 return NewDI->getType();
3510}
3511
3512template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003513TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003514 // Refine the base location to the type's location.
3515 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3516 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003517 if (getDerived().AlreadyTransformed(DI->getType()))
3518 return DI;
3519
3520 TypeLocBuilder TLB;
3521
3522 TypeLoc TL = DI->getTypeLoc();
3523 TLB.reserve(TL.getFullDataSize());
3524
John McCall31f82722010-11-12 08:19:04 +00003525 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003526 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003527 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003528
John McCallbcd03502009-12-07 02:54:59 +00003529 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003530}
3531
3532template<typename Derived>
3533QualType
John McCall31f82722010-11-12 08:19:04 +00003534TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003535 switch (T.getTypeLocClass()) {
3536#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003537#define TYPELOC(CLASS, PARENT) \
3538 case TypeLoc::CLASS: \
3539 return getDerived().Transform##CLASS##Type(TLB, \
3540 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003541#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003542 }
Mike Stump11289f42009-09-09 15:08:12 +00003543
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003544 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003545}
3546
3547/// FIXME: By default, this routine adds type qualifiers only to types
3548/// that can have qualifiers, and silently suppresses those qualifiers
3549/// that are not permitted (e.g., qualifiers on reference or function
3550/// types). This is the right thing for template instantiation, but
3551/// probably not for other clients.
3552template<typename Derived>
3553QualType
3554TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003555 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003556 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003557
John McCall31f82722010-11-12 08:19:04 +00003558 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003559 if (Result.isNull())
3560 return QualType();
3561
3562 // Silently suppress qualifiers if the result type can't be qualified.
3563 // FIXME: this is the right thing for template instantiation, but
3564 // probably not for other clients.
3565 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003566 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003567
John McCall31168b02011-06-15 23:02:42 +00003568 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003569 // resulting type.
3570 if (Quals.hasObjCLifetime()) {
3571 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3572 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003573 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003574 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003575 // A lifetime qualifier applied to a substituted template parameter
3576 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003577 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003578 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003579 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3580 QualType Replacement = SubstTypeParam->getReplacementType();
3581 Qualifiers Qs = Replacement.getQualifiers();
3582 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003583 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003584 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3585 Qs);
3586 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003587 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003588 Replacement);
3589 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003590 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3591 // 'auto' types behave the same way as template parameters.
3592 QualType Deduced = AutoTy->getDeducedType();
3593 Qualifiers Qs = Deduced.getQualifiers();
3594 Qs.removeObjCLifetime();
3595 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3596 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003597 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3598 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003599 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003600 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003601 // Otherwise, complain about the addition of a qualifier to an
3602 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003603 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003604 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003605 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003606
Douglas Gregore46db902011-06-17 22:11:49 +00003607 Quals.removeObjCLifetime();
3608 }
3609 }
3610 }
John McCallcb0f89a2010-06-05 06:41:15 +00003611 if (!Quals.empty()) {
3612 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003613 // BuildQualifiedType might not add qualifiers if they are invalid.
3614 if (Result.hasLocalQualifiers())
3615 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003616 // No location information to preserve.
3617 }
John McCall550e0c22009-10-21 00:40:46 +00003618
3619 return Result;
3620}
3621
Douglas Gregor14454802011-02-25 02:25:35 +00003622template<typename Derived>
3623TypeLoc
3624TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3625 QualType ObjectType,
3626 NamedDecl *UnqualLookup,
3627 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003628 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003629 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003631 TypeSourceInfo *TSI =
3632 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3633 if (TSI)
3634 return TSI->getTypeLoc();
3635 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003636}
3637
Douglas Gregor579c15f2011-03-02 18:32:08 +00003638template<typename Derived>
3639TypeSourceInfo *
3640TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3641 QualType ObjectType,
3642 NamedDecl *UnqualLookup,
3643 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003644 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003645 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003647 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3648 UnqualLookup, SS);
3649}
3650
3651template <typename Derived>
3652TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3653 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3654 CXXScopeSpec &SS) {
3655 QualType T = TL.getType();
3656 assert(!getDerived().AlreadyTransformed(T));
3657
Douglas Gregor579c15f2011-03-02 18:32:08 +00003658 TypeLocBuilder TLB;
3659 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003660
Douglas Gregor579c15f2011-03-02 18:32:08 +00003661 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003662 TemplateSpecializationTypeLoc SpecTL =
3663 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
Douglas Gregor579c15f2011-03-02 18:32:08 +00003665 TemplateName Template
3666 = getDerived().TransformTemplateName(SS,
3667 SpecTL.getTypePtr()->getTemplateName(),
3668 SpecTL.getTemplateNameLoc(),
3669 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003670 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003671 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
3673 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003674 Template);
3675 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003676 DependentTemplateSpecializationTypeLoc SpecTL =
3677 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003678
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003680 = getDerived().RebuildTemplateName(SS,
3681 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003682 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003683 ObjectType, UnqualLookup);
3684 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003685 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003686
3687 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003688 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003689 Template,
3690 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003691 } else {
3692 // Nothing special needs to be done for these.
3693 Result = getDerived().TransformType(TLB, TL);
3694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003695
3696 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003697 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor579c15f2011-03-02 18:32:08 +00003699 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3700}
3701
John McCall550e0c22009-10-21 00:40:46 +00003702template <class TyLoc> static inline
3703QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3704 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3705 NewT.setNameLoc(T.getNameLoc());
3706 return T.getType();
3707}
3708
John McCall550e0c22009-10-21 00:40:46 +00003709template<typename Derived>
3710QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003711 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003712 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3713 NewT.setBuiltinLoc(T.getBuiltinLoc());
3714 if (T.needsExtraLocalData())
3715 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3716 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003717}
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregord6ff3322009-08-04 16:50:30 +00003719template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003720QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003721 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003722 // FIXME: recurse?
3723 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003724}
Mike Stump11289f42009-09-09 15:08:12 +00003725
Reid Kleckner0503a872013-12-05 01:23:43 +00003726template <typename Derived>
3727QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3728 AdjustedTypeLoc TL) {
3729 // Adjustments applied during transformation are handled elsewhere.
3730 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3731}
3732
Douglas Gregord6ff3322009-08-04 16:50:30 +00003733template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003734QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3735 DecayedTypeLoc TL) {
3736 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3737 if (OriginalType.isNull())
3738 return QualType();
3739
3740 QualType Result = TL.getType();
3741 if (getDerived().AlwaysRebuild() ||
3742 OriginalType != TL.getOriginalLoc().getType())
3743 Result = SemaRef.Context.getDecayedType(OriginalType);
3744 TLB.push<DecayedTypeLoc>(Result);
3745 // Nothing to set for DecayedTypeLoc.
3746 return Result;
3747}
3748
3749template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003750QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003751 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003752 QualType PointeeType
3753 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003754 if (PointeeType.isNull())
3755 return QualType();
3756
3757 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003758 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003759 // A dependent pointer type 'T *' has is being transformed such
3760 // that an Objective-C class type is being replaced for 'T'. The
3761 // resulting pointer type is an ObjCObjectPointerType, not a
3762 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003763 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
John McCall8b07ec22010-05-15 11:32:37 +00003765 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3766 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003767 return Result;
3768 }
John McCall31f82722010-11-12 08:19:04 +00003769
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003770 if (getDerived().AlwaysRebuild() ||
3771 PointeeType != TL.getPointeeLoc().getType()) {
3772 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3773 if (Result.isNull())
3774 return QualType();
3775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
John McCall31168b02011-06-15 23:02:42 +00003777 // Objective-C ARC can add lifetime qualifiers to the type that we're
3778 // pointing to.
3779 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003781 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3782 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003783 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003784}
Mike Stump11289f42009-09-09 15:08:12 +00003785
3786template<typename Derived>
3787QualType
John McCall550e0c22009-10-21 00:40:46 +00003788TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003789 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003790 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003791 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3792 if (PointeeType.isNull())
3793 return QualType();
3794
3795 QualType Result = TL.getType();
3796 if (getDerived().AlwaysRebuild() ||
3797 PointeeType != TL.getPointeeLoc().getType()) {
3798 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003799 TL.getSigilLoc());
3800 if (Result.isNull())
3801 return QualType();
3802 }
3803
Douglas Gregor049211a2010-04-22 16:50:51 +00003804 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003805 NewT.setSigilLoc(TL.getSigilLoc());
3806 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003807}
3808
John McCall70dd5f62009-10-30 00:06:24 +00003809/// Transforms a reference type. Note that somewhat paradoxically we
3810/// don't care whether the type itself is an l-value type or an r-value
3811/// type; we only care if the type was *written* as an l-value type
3812/// or an r-value type.
3813template<typename Derived>
3814QualType
3815TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003816 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003817 const ReferenceType *T = TL.getTypePtr();
3818
3819 // Note that this works with the pointee-as-written.
3820 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3821 if (PointeeType.isNull())
3822 return QualType();
3823
3824 QualType Result = TL.getType();
3825 if (getDerived().AlwaysRebuild() ||
3826 PointeeType != T->getPointeeTypeAsWritten()) {
3827 Result = getDerived().RebuildReferenceType(PointeeType,
3828 T->isSpelledAsLValue(),
3829 TL.getSigilLoc());
3830 if (Result.isNull())
3831 return QualType();
3832 }
3833
John McCall31168b02011-06-15 23:02:42 +00003834 // Objective-C ARC can add lifetime qualifiers to the type that we're
3835 // referring to.
3836 TLB.TypeWasModifiedSafely(
3837 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3838
John McCall70dd5f62009-10-30 00:06:24 +00003839 // r-value references can be rebuilt as l-value references.
3840 ReferenceTypeLoc NewTL;
3841 if (isa<LValueReferenceType>(Result))
3842 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3843 else
3844 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3845 NewTL.setSigilLoc(TL.getSigilLoc());
3846
3847 return Result;
3848}
3849
Mike Stump11289f42009-09-09 15:08:12 +00003850template<typename Derived>
3851QualType
John McCall550e0c22009-10-21 00:40:46 +00003852TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003853 LValueReferenceTypeLoc TL) {
3854 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003855}
3856
Mike Stump11289f42009-09-09 15:08:12 +00003857template<typename Derived>
3858QualType
John McCall550e0c22009-10-21 00:40:46 +00003859TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003860 RValueReferenceTypeLoc TL) {
3861 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862}
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregord6ff3322009-08-04 16:50:30 +00003864template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003865QualType
John McCall550e0c22009-10-21 00:40:46 +00003866TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003867 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003868 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869 if (PointeeType.isNull())
3870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003871
Abramo Bagnara509357842011-03-05 14:42:21 +00003872 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003873 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003874 if (OldClsTInfo) {
3875 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3876 if (!NewClsTInfo)
3877 return QualType();
3878 }
3879
3880 const MemberPointerType *T = TL.getTypePtr();
3881 QualType OldClsType = QualType(T->getClass(), 0);
3882 QualType NewClsType;
3883 if (NewClsTInfo)
3884 NewClsType = NewClsTInfo->getType();
3885 else {
3886 NewClsType = getDerived().TransformType(OldClsType);
3887 if (NewClsType.isNull())
3888 return QualType();
3889 }
Mike Stump11289f42009-09-09 15:08:12 +00003890
John McCall550e0c22009-10-21 00:40:46 +00003891 QualType Result = TL.getType();
3892 if (getDerived().AlwaysRebuild() ||
3893 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003894 NewClsType != OldClsType) {
3895 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003896 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003897 if (Result.isNull())
3898 return QualType();
3899 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900
Reid Kleckner0503a872013-12-05 01:23:43 +00003901 // If we had to adjust the pointee type when building a member pointer, make
3902 // sure to push TypeLoc info for it.
3903 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3904 if (MPT && PointeeType != MPT->getPointeeType()) {
3905 assert(isa<AdjustedType>(MPT->getPointeeType()));
3906 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3907 }
3908
John McCall550e0c22009-10-21 00:40:46 +00003909 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3910 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003911 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003912
3913 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914}
3915
Mike Stump11289f42009-09-09 15:08:12 +00003916template<typename Derived>
3917QualType
John McCall550e0c22009-10-21 00:40:46 +00003918TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003919 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003920 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003921 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003922 if (ElementType.isNull())
3923 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 QualType Result = TL.getType();
3926 if (getDerived().AlwaysRebuild() ||
3927 ElementType != T->getElementType()) {
3928 Result = getDerived().RebuildConstantArrayType(ElementType,
3929 T->getSizeModifier(),
3930 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003931 T->getIndexTypeCVRQualifiers(),
3932 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003933 if (Result.isNull())
3934 return QualType();
3935 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003936
3937 // We might have either a ConstantArrayType or a VariableArrayType now:
3938 // a ConstantArrayType is allowed to have an element type which is a
3939 // VariableArrayType if the type is dependent. Fortunately, all array
3940 // types have the same location layout.
3941 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003942 NewTL.setLBracketLoc(TL.getLBracketLoc());
3943 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCall550e0c22009-10-21 00:40:46 +00003945 Expr *Size = TL.getSizeExpr();
3946 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003947 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3948 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003949 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3950 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003951 }
3952 NewTL.setSizeExpr(Size);
3953
3954 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955}
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003959 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003960 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003961 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003962 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963 if (ElementType.isNull())
3964 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003965
John McCall550e0c22009-10-21 00:40:46 +00003966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() ||
3968 ElementType != T->getElementType()) {
3969 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003971 T->getIndexTypeCVRQualifiers(),
3972 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003973 if (Result.isNull())
3974 return QualType();
3975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003976
John McCall550e0c22009-10-21 00:40:46 +00003977 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3978 NewTL.setLBracketLoc(TL.getLBracketLoc());
3979 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003980 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003981
3982 return Result;
3983}
3984
3985template<typename Derived>
3986QualType
3987TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003988 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003989 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003990 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3991 if (ElementType.isNull())
3992 return QualType();
3993
John McCalldadc5752010-08-24 06:29:42 +00003994 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003995 = getDerived().TransformExpr(T->getSizeExpr());
3996 if (SizeResult.isInvalid())
3997 return QualType();
3998
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003999 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004000
4001 QualType Result = TL.getType();
4002 if (getDerived().AlwaysRebuild() ||
4003 ElementType != T->getElementType() ||
4004 Size != T->getSizeExpr()) {
4005 Result = getDerived().RebuildVariableArrayType(ElementType,
4006 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004007 Size,
John McCall550e0c22009-10-21 00:40:46 +00004008 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004009 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004010 if (Result.isNull())
4011 return QualType();
4012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004013
Serge Pavlov774c6d02014-02-06 03:49:11 +00004014 // We might have constant size array now, but fortunately it has the same
4015 // location layout.
4016 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004017 NewTL.setLBracketLoc(TL.getLBracketLoc());
4018 NewTL.setRBracketLoc(TL.getRBracketLoc());
4019 NewTL.setSizeExpr(Size);
4020
4021 return Result;
4022}
4023
4024template<typename Derived>
4025QualType
4026TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004027 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004028 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004029 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4030 if (ElementType.isNull())
4031 return QualType();
4032
Richard Smith764d2fe2011-12-20 02:08:33 +00004033 // Array bounds are constant expressions.
4034 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4035 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004036
John McCall33ddac02011-01-19 10:06:00 +00004037 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4038 Expr *origSize = TL.getSizeExpr();
4039 if (!origSize) origSize = T->getSizeExpr();
4040
4041 ExprResult sizeResult
4042 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004043 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004044 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004045 return QualType();
4046
John McCall33ddac02011-01-19 10:06:00 +00004047 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004048
4049 QualType Result = TL.getType();
4050 if (getDerived().AlwaysRebuild() ||
4051 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004052 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004053 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4054 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004055 size,
John McCall550e0c22009-10-21 00:40:46 +00004056 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004057 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004058 if (Result.isNull())
4059 return QualType();
4060 }
John McCall550e0c22009-10-21 00:40:46 +00004061
4062 // We might have any sort of array type now, but fortunately they
4063 // all have the same location layout.
4064 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4065 NewTL.setLBracketLoc(TL.getLBracketLoc());
4066 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004067 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004068
4069 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070}
Mike Stump11289f42009-09-09 15:08:12 +00004071
4072template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004074 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004075 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004076 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004077
4078 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079 QualType ElementType = getDerived().TransformType(T->getElementType());
4080 if (ElementType.isNull())
4081 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004082
Richard Smith764d2fe2011-12-20 02:08:33 +00004083 // Vector sizes are constant expressions.
4084 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4085 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004086
John McCalldadc5752010-08-24 06:29:42 +00004087 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004088 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089 if (Size.isInvalid())
4090 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004091
John McCall550e0c22009-10-21 00:40:46 +00004092 QualType Result = TL.getType();
4093 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004094 ElementType != T->getElementType() ||
4095 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004096 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004097 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004098 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004099 if (Result.isNull())
4100 return QualType();
4101 }
John McCall550e0c22009-10-21 00:40:46 +00004102
4103 // Result might be dependent or not.
4104 if (isa<DependentSizedExtVectorType>(Result)) {
4105 DependentSizedExtVectorTypeLoc NewTL
4106 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4107 NewTL.setNameLoc(TL.getNameLoc());
4108 } else {
4109 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4110 NewTL.setNameLoc(TL.getNameLoc());
4111 }
4112
4113 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
4116template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004117QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004118 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004119 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004120 QualType ElementType = getDerived().TransformType(T->getElementType());
4121 if (ElementType.isNull())
4122 return QualType();
4123
John McCall550e0c22009-10-21 00:40:46 +00004124 QualType Result = TL.getType();
4125 if (getDerived().AlwaysRebuild() ||
4126 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004127 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004128 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004129 if (Result.isNull())
4130 return QualType();
4131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
John McCall550e0c22009-10-21 00:40:46 +00004133 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4134 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004135
John McCall550e0c22009-10-21 00:40:46 +00004136 return Result;
4137}
4138
4139template<typename Derived>
4140QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004142 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004143 QualType ElementType = getDerived().TransformType(T->getElementType());
4144 if (ElementType.isNull())
4145 return QualType();
4146
4147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
4149 ElementType != T->getElementType()) {
4150 Result = getDerived().RebuildExtVectorType(ElementType,
4151 T->getNumElements(),
4152 /*FIXME*/ SourceLocation());
4153 if (Result.isNull())
4154 return QualType();
4155 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004156
John McCall550e0c22009-10-21 00:40:46 +00004157 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4158 NewTL.setNameLoc(TL.getNameLoc());
4159
4160 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
David Blaikie05785d12013-02-20 22:23:23 +00004163template <typename Derived>
4164ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4165 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4166 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004167 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004168 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004169
Douglas Gregor715e4612011-01-14 22:40:04 +00004170 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004171 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004172 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004173 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004174 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004175
Douglas Gregor715e4612011-01-14 22:40:04 +00004176 TypeLocBuilder TLB;
4177 TypeLoc NewTL = OldDI->getTypeLoc();
4178 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004179
4180 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004181 OldExpansionTL.getPatternLoc());
4182 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004183 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004184
4185 Result = RebuildPackExpansionType(Result,
4186 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004187 OldExpansionTL.getEllipsisLoc(),
4188 NumExpansions);
4189 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004190 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004191
Douglas Gregor715e4612011-01-14 22:40:04 +00004192 PackExpansionTypeLoc NewExpansionTL
4193 = TLB.push<PackExpansionTypeLoc>(Result);
4194 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4195 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4196 } else
4197 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004198 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004199 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004200
John McCall8fb0d9d2011-05-01 22:35:37 +00004201 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004202 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004203
4204 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4205 OldParm->getDeclContext(),
4206 OldParm->getInnerLocStart(),
4207 OldParm->getLocation(),
4208 OldParm->getIdentifier(),
4209 NewDI->getType(),
4210 NewDI,
4211 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004212 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004213 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4214 OldParm->getFunctionScopeIndex() + indexAdjustment);
4215 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004216}
4217
4218template<typename Derived>
4219bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004220 TransformFunctionTypeParams(SourceLocation Loc,
4221 ParmVarDecl **Params, unsigned NumParams,
4222 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004223 SmallVectorImpl<QualType> &OutParamTypes,
4224 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004225 int indexAdjustment = 0;
4226
Douglas Gregordd472162011-01-07 00:20:55 +00004227 for (unsigned i = 0; i != NumParams; ++i) {
4228 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004229 assert(OldParm->getFunctionScopeIndex() == i);
4230
David Blaikie05785d12013-02-20 22:23:23 +00004231 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004232 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004233 if (OldParm->isParameterPack()) {
4234 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004235 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004236
Douglas Gregor5499af42011-01-05 23:12:31 +00004237 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004238 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004239 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004240 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4241 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004242 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4243
Douglas Gregor5499af42011-01-05 23:12:31 +00004244 // Determine whether we should expand the parameter packs.
4245 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004246 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004247 Optional<unsigned> OrigNumExpansions =
4248 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004249 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004250 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4251 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004252 Unexpanded,
4253 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004254 RetainExpansion,
4255 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004256 return true;
4257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004258
Douglas Gregor5499af42011-01-05 23:12:31 +00004259 if (ShouldExpand) {
4260 // Expand the function parameter pack into multiple, separate
4261 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004262 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004263 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004264 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004265 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004266 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004267 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004268 OrigNumExpansions,
4269 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004270 if (!NewParm)
4271 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004272
Douglas Gregordd472162011-01-07 00:20:55 +00004273 OutParamTypes.push_back(NewParm->getType());
4274 if (PVars)
4275 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004276 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004277
4278 // If we're supposed to retain a pack expansion, do so by temporarily
4279 // forgetting the partially-substituted parameter pack.
4280 if (RetainExpansion) {
4281 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004282 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004283 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004284 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004285 OrigNumExpansions,
4286 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004287 if (!NewParm)
4288 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004289
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004290 OutParamTypes.push_back(NewParm->getType());
4291 if (PVars)
4292 PVars->push_back(NewParm);
4293 }
4294
John McCall8fb0d9d2011-05-01 22:35:37 +00004295 // The next parameter should have the same adjustment as the
4296 // last thing we pushed, but we post-incremented indexAdjustment
4297 // on every push. Also, if we push nothing, the adjustment should
4298 // go down by one.
4299 indexAdjustment--;
4300
Douglas Gregor5499af42011-01-05 23:12:31 +00004301 // We're done with the pack expansion.
4302 continue;
4303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004304
4305 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004306 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004307 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4308 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004309 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004310 NumExpansions,
4311 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004312 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004313 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004314 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004315 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004316
John McCall58f10c32010-03-11 09:03:00 +00004317 if (!NewParm)
4318 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
Douglas Gregordd472162011-01-07 00:20:55 +00004320 OutParamTypes.push_back(NewParm->getType());
4321 if (PVars)
4322 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004323 continue;
4324 }
John McCall58f10c32010-03-11 09:03:00 +00004325
4326 // Deal with the possibility that we don't have a parameter
4327 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004328 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004329 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004330 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004331 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004332 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 = dyn_cast<PackExpansionType>(OldType)) {
4334 // We have a function parameter pack that may need to be expanded.
4335 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004336 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004337 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004338
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 // Determine whether we should expand the parameter packs.
4340 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004341 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004342 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004343 Unexpanded,
4344 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004345 RetainExpansion,
4346 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004347 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004349
Douglas Gregor5499af42011-01-05 23:12:31 +00004350 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004351 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004352 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004353 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004354 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4355 QualType NewType = getDerived().TransformType(Pattern);
4356 if (NewType.isNull())
4357 return true;
John McCall58f10c32010-03-11 09:03:00 +00004358
Douglas Gregordd472162011-01-07 00:20:55 +00004359 OutParamTypes.push_back(NewType);
4360 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004361 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004363
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 // We're done with the pack expansion.
4365 continue;
4366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004367
Douglas Gregor48d24112011-01-10 20:53:55 +00004368 // If we're supposed to retain a pack expansion, do so by temporarily
4369 // forgetting the partially-substituted parameter pack.
4370 if (RetainExpansion) {
4371 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4372 QualType NewType = getDerived().TransformType(Pattern);
4373 if (NewType.isNull())
4374 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004375
Douglas Gregor48d24112011-01-10 20:53:55 +00004376 OutParamTypes.push_back(NewType);
4377 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004378 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004379 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004380
Chad Rosier1dcde962012-08-08 18:46:20 +00004381 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004382 // expansion.
4383 OldType = Expansion->getPattern();
4384 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004385 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4386 NewType = getDerived().TransformType(OldType);
4387 } else {
4388 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004390
Douglas Gregor5499af42011-01-05 23:12:31 +00004391 if (NewType.isNull())
4392 return true;
4393
4394 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004395 NewType = getSema().Context.getPackExpansionType(NewType,
4396 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004397
Douglas Gregordd472162011-01-07 00:20:55 +00004398 OutParamTypes.push_back(NewType);
4399 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004400 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004401 }
4402
John McCall8fb0d9d2011-05-01 22:35:37 +00004403#ifndef NDEBUG
4404 if (PVars) {
4405 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4406 if (ParmVarDecl *parm = (*PVars)[i])
4407 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004408 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004409#endif
4410
4411 return false;
4412}
John McCall58f10c32010-03-11 09:03:00 +00004413
4414template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004415QualType
John McCall550e0c22009-10-21 00:40:46 +00004416TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004417 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004418 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004419}
4420
4421template<typename Derived>
4422QualType
4423TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4424 FunctionProtoTypeLoc TL,
4425 CXXRecordDecl *ThisContext,
4426 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004427 // Transform the parameters and return type.
4428 //
Richard Smithf623c962012-04-17 00:58:00 +00004429 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004430 // When the function has a trailing return type, we instantiate the
4431 // parameters before the return type, since the return type can then refer
4432 // to the parameters themselves (via decltype, sizeof, etc.).
4433 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004434 SmallVector<QualType, 4> ParamTypes;
4435 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004436 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004437
Douglas Gregor7fb25412010-10-01 18:44:50 +00004438 QualType ResultType;
4439
Richard Smith1226c602012-08-14 22:51:13 +00004440 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004441 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004442 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004443 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004444 return QualType();
4445
Douglas Gregor3024f072012-04-16 07:05:22 +00004446 {
4447 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004448 // If a declaration declares a member function or member function
4449 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004450 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004451 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004452 // declarator.
4453 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
Alp Toker42a16a62014-01-25 23:51:36 +00004455 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004456 if (ResultType.isNull())
4457 return QualType();
4458 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004459 }
4460 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004461 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004462 if (ResultType.isNull())
4463 return QualType();
4464
Alp Toker9cacbab2014-01-20 20:26:09 +00004465 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004466 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004467 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004468 return QualType();
4469 }
4470
Richard Smithf623c962012-04-17 00:58:00 +00004471 // FIXME: Need to transform the exception-specification too.
4472
John McCall550e0c22009-10-21 00:40:46 +00004473 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004474 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004475 T->getNumParams() != ParamTypes.size() ||
4476 !std::equal(T->param_type_begin(), T->param_type_end(),
4477 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004478 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004479 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004480 if (Result.isNull())
4481 return QualType();
4482 }
Mike Stump11289f42009-09-09 15:08:12 +00004483
John McCall550e0c22009-10-21 00:40:46 +00004484 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004485 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004486 NewTL.setLParenLoc(TL.getLParenLoc());
4487 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004488 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004489 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4490 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004491
4492 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004493}
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495template<typename Derived>
4496QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004497 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004498 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004499 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004500 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004501 if (ResultType.isNull())
4502 return QualType();
4503
4504 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004505 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004506 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4507
4508 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004509 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004510 NewTL.setLParenLoc(TL.getLParenLoc());
4511 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004512 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004513
4514 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
John McCallb96ec562009-12-04 22:46:56 +00004517template<typename Derived> QualType
4518TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004519 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004520 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004521 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004522 if (!D)
4523 return QualType();
4524
4525 QualType Result = TL.getType();
4526 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4527 Result = getDerived().RebuildUnresolvedUsingType(D);
4528 if (Result.isNull())
4529 return QualType();
4530 }
4531
4532 // We might get an arbitrary type spec type back. We should at
4533 // least always get a type spec type, though.
4534 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4535 NewTL.setNameLoc(TL.getNameLoc());
4536
4537 return Result;
4538}
4539
Douglas Gregord6ff3322009-08-04 16:50:30 +00004540template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004541QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004542 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004543 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004544 TypedefNameDecl *Typedef
4545 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4546 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547 if (!Typedef)
4548 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004549
John McCall550e0c22009-10-21 00:40:46 +00004550 QualType Result = TL.getType();
4551 if (getDerived().AlwaysRebuild() ||
4552 Typedef != T->getDecl()) {
4553 Result = getDerived().RebuildTypedefType(Typedef);
4554 if (Result.isNull())
4555 return QualType();
4556 }
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCall550e0c22009-10-21 00:40:46 +00004558 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4559 NewTL.setNameLoc(TL.getNameLoc());
4560
4561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562}
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregord6ff3322009-08-04 16:50:30 +00004564template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004565QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004566 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004567 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004568 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4569 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004570
John McCalldadc5752010-08-24 06:29:42 +00004571 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572 if (E.isInvalid())
4573 return QualType();
4574
Eli Friedmane4f22df2012-02-29 04:03:55 +00004575 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4576 if (E.isInvalid())
4577 return QualType();
4578
John McCall550e0c22009-10-21 00:40:46 +00004579 QualType Result = TL.getType();
4580 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004581 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004582 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004583 if (Result.isNull())
4584 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004586 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004587
John McCall550e0c22009-10-21 00:40:46 +00004588 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004589 NewTL.setTypeofLoc(TL.getTypeofLoc());
4590 NewTL.setLParenLoc(TL.getLParenLoc());
4591 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004592
4593 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004594}
Mike Stump11289f42009-09-09 15:08:12 +00004595
4596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004597QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004599 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4600 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4601 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004602 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004603
John McCall550e0c22009-10-21 00:40:46 +00004604 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004605 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4606 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004607 if (Result.isNull())
4608 return QualType();
4609 }
Mike Stump11289f42009-09-09 15:08:12 +00004610
John McCall550e0c22009-10-21 00:40:46 +00004611 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004612 NewTL.setTypeofLoc(TL.getTypeofLoc());
4613 NewTL.setLParenLoc(TL.getLParenLoc());
4614 NewTL.setRParenLoc(TL.getRParenLoc());
4615 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004616
4617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
4620template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004621QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004622 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004623 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004624
Douglas Gregore922c772009-08-04 22:27:00 +00004625 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004626 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4627 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004628
John McCalldadc5752010-08-24 06:29:42 +00004629 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004630 if (E.isInvalid())
4631 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004632
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004633 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004634 if (E.isInvalid())
4635 return QualType();
4636
John McCall550e0c22009-10-21 00:40:46 +00004637 QualType Result = TL.getType();
4638 if (getDerived().AlwaysRebuild() ||
4639 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004640 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004641 if (Result.isNull())
4642 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004643 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004644 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004645
John McCall550e0c22009-10-21 00:40:46 +00004646 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4647 NewTL.setNameLoc(TL.getNameLoc());
4648
4649 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004650}
4651
4652template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004653QualType TreeTransform<Derived>::TransformUnaryTransformType(
4654 TypeLocBuilder &TLB,
4655 UnaryTransformTypeLoc TL) {
4656 QualType Result = TL.getType();
4657 if (Result->isDependentType()) {
4658 const UnaryTransformType *T = TL.getTypePtr();
4659 QualType NewBase =
4660 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4661 Result = getDerived().RebuildUnaryTransformType(NewBase,
4662 T->getUTTKind(),
4663 TL.getKWLoc());
4664 if (Result.isNull())
4665 return QualType();
4666 }
4667
4668 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4669 NewTL.setKWLoc(TL.getKWLoc());
4670 NewTL.setParensRange(TL.getParensRange());
4671 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4672 return Result;
4673}
4674
4675template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004676QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4677 AutoTypeLoc TL) {
4678 const AutoType *T = TL.getTypePtr();
4679 QualType OldDeduced = T->getDeducedType();
4680 QualType NewDeduced;
4681 if (!OldDeduced.isNull()) {
4682 NewDeduced = getDerived().TransformType(OldDeduced);
4683 if (NewDeduced.isNull())
4684 return QualType();
4685 }
4686
4687 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004688 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4689 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004690 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004691 if (Result.isNull())
4692 return QualType();
4693 }
4694
4695 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4696 NewTL.setNameLoc(TL.getNameLoc());
4697
4698 return Result;
4699}
4700
4701template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004702QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004703 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004704 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004705 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004706 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4707 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708 if (!Record)
4709 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004710
John McCall550e0c22009-10-21 00:40:46 +00004711 QualType Result = TL.getType();
4712 if (getDerived().AlwaysRebuild() ||
4713 Record != T->getDecl()) {
4714 Result = getDerived().RebuildRecordType(Record);
4715 if (Result.isNull())
4716 return QualType();
4717 }
Mike Stump11289f42009-09-09 15:08:12 +00004718
John McCall550e0c22009-10-21 00:40:46 +00004719 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4720 NewTL.setNameLoc(TL.getNameLoc());
4721
4722 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
4725template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004726QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004727 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004728 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004730 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4731 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004732 if (!Enum)
4733 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004734
John McCall550e0c22009-10-21 00:40:46 +00004735 QualType Result = TL.getType();
4736 if (getDerived().AlwaysRebuild() ||
4737 Enum != T->getDecl()) {
4738 Result = getDerived().RebuildEnumType(Enum);
4739 if (Result.isNull())
4740 return QualType();
4741 }
Mike Stump11289f42009-09-09 15:08:12 +00004742
John McCall550e0c22009-10-21 00:40:46 +00004743 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4744 NewTL.setNameLoc(TL.getNameLoc());
4745
4746 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004747}
John McCallfcc33b02009-09-05 00:15:47 +00004748
John McCalle78aac42010-03-10 03:28:59 +00004749template<typename Derived>
4750QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4751 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004752 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004753 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4754 TL.getTypePtr()->getDecl());
4755 if (!D) return QualType();
4756
4757 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4758 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4759 return T;
4760}
4761
Douglas Gregord6ff3322009-08-04 16:50:30 +00004762template<typename Derived>
4763QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004764 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004765 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004766 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004767}
4768
Mike Stump11289f42009-09-09 15:08:12 +00004769template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004770QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004771 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004772 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004773 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004774
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004775 // Substitute into the replacement type, which itself might involve something
4776 // that needs to be transformed. This only tends to occur with default
4777 // template arguments of template template parameters.
4778 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4779 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4780 if (Replacement.isNull())
4781 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004782
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004783 // Always canonicalize the replacement type.
4784 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4785 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004786 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004787 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004788
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004789 // Propagate type-source information.
4790 SubstTemplateTypeParmTypeLoc NewTL
4791 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4792 NewTL.setNameLoc(TL.getNameLoc());
4793 return Result;
4794
John McCallcebee162009-10-18 09:09:24 +00004795}
4796
4797template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004798QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4799 TypeLocBuilder &TLB,
4800 SubstTemplateTypeParmPackTypeLoc TL) {
4801 return TransformTypeSpecType(TLB, TL);
4802}
4803
4804template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004805QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004806 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004807 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004808 const TemplateSpecializationType *T = TL.getTypePtr();
4809
Douglas Gregordf846d12011-03-02 18:46:51 +00004810 // The nested-name-specifier never matters in a TemplateSpecializationType,
4811 // because we can't have a dependent nested-name-specifier anyway.
4812 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004813 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004814 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4815 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004816 if (Template.isNull())
4817 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004818
John McCall31f82722010-11-12 08:19:04 +00004819 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4820}
4821
Eli Friedman0dfb8892011-10-06 23:00:33 +00004822template<typename Derived>
4823QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4824 AtomicTypeLoc TL) {
4825 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4826 if (ValueType.isNull())
4827 return QualType();
4828
4829 QualType Result = TL.getType();
4830 if (getDerived().AlwaysRebuild() ||
4831 ValueType != TL.getValueLoc().getType()) {
4832 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4833 if (Result.isNull())
4834 return QualType();
4835 }
4836
4837 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4838 NewTL.setKWLoc(TL.getKWLoc());
4839 NewTL.setLParenLoc(TL.getLParenLoc());
4840 NewTL.setRParenLoc(TL.getRParenLoc());
4841
4842 return Result;
4843}
4844
Chad Rosier1dcde962012-08-08 18:46:20 +00004845 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004846 /// container that provides a \c getArgLoc() member function.
4847 ///
4848 /// This iterator is intended to be used with the iterator form of
4849 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4850 template<typename ArgLocContainer>
4851 class TemplateArgumentLocContainerIterator {
4852 ArgLocContainer *Container;
4853 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004854
Douglas Gregorfe921a72010-12-20 23:36:19 +00004855 public:
4856 typedef TemplateArgumentLoc value_type;
4857 typedef TemplateArgumentLoc reference;
4858 typedef int difference_type;
4859 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004860
Douglas Gregorfe921a72010-12-20 23:36:19 +00004861 class pointer {
4862 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004863
Douglas Gregorfe921a72010-12-20 23:36:19 +00004864 public:
4865 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004866
Douglas Gregorfe921a72010-12-20 23:36:19 +00004867 const TemplateArgumentLoc *operator->() const {
4868 return &Arg;
4869 }
4870 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
4872
Douglas Gregorfe921a72010-12-20 23:36:19 +00004873 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
Douglas Gregorfe921a72010-12-20 23:36:19 +00004875 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4876 unsigned Index)
4877 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004878
Douglas Gregorfe921a72010-12-20 23:36:19 +00004879 TemplateArgumentLocContainerIterator &operator++() {
4880 ++Index;
4881 return *this;
4882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004883
Douglas Gregorfe921a72010-12-20 23:36:19 +00004884 TemplateArgumentLocContainerIterator operator++(int) {
4885 TemplateArgumentLocContainerIterator Old(*this);
4886 ++(*this);
4887 return Old;
4888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004889
Douglas Gregorfe921a72010-12-20 23:36:19 +00004890 TemplateArgumentLoc operator*() const {
4891 return Container->getArgLoc(Index);
4892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
Douglas Gregorfe921a72010-12-20 23:36:19 +00004894 pointer operator->() const {
4895 return pointer(Container->getArgLoc(Index));
4896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004897
Douglas Gregorfe921a72010-12-20 23:36:19 +00004898 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004899 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004900 return X.Container == Y.Container && X.Index == Y.Index;
4901 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004902
Douglas Gregorfe921a72010-12-20 23:36:19 +00004903 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004904 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004905 return !(X == Y);
4906 }
4907 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
4909
John McCall31f82722010-11-12 08:19:04 +00004910template <typename Derived>
4911QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4912 TypeLocBuilder &TLB,
4913 TemplateSpecializationTypeLoc TL,
4914 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004915 TemplateArgumentListInfo NewTemplateArgs;
4916 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4917 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004918 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4919 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004920 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004921 ArgIterator(TL, TL.getNumArgs()),
4922 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004923 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004924
John McCall0ad16662009-10-29 08:12:44 +00004925 // FIXME: maybe don't rebuild if all the template arguments are the same.
4926
4927 QualType Result =
4928 getDerived().RebuildTemplateSpecializationType(Template,
4929 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004930 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004931
4932 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004933 // Specializations of template template parameters are represented as
4934 // TemplateSpecializationTypes, and substitution of type alias templates
4935 // within a dependent context can transform them into
4936 // DependentTemplateSpecializationTypes.
4937 if (isa<DependentTemplateSpecializationType>(Result)) {
4938 DependentTemplateSpecializationTypeLoc NewTL
4939 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004940 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004941 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004942 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004943 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004944 NewTL.setLAngleLoc(TL.getLAngleLoc());
4945 NewTL.setRAngleLoc(TL.getRAngleLoc());
4946 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4947 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4948 return Result;
4949 }
4950
John McCall0ad16662009-10-29 08:12:44 +00004951 TemplateSpecializationTypeLoc NewTL
4952 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004953 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004954 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4955 NewTL.setLAngleLoc(TL.getLAngleLoc());
4956 NewTL.setRAngleLoc(TL.getRAngleLoc());
4957 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4958 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004959 }
Mike Stump11289f42009-09-09 15:08:12 +00004960
John McCall0ad16662009-10-29 08:12:44 +00004961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregor5a064722011-02-28 17:23:35 +00004964template <typename Derived>
4965QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4966 TypeLocBuilder &TLB,
4967 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004968 TemplateName Template,
4969 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004970 TemplateArgumentListInfo NewTemplateArgs;
4971 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4972 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4973 typedef TemplateArgumentLocContainerIterator<
4974 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004975 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004976 ArgIterator(TL, TL.getNumArgs()),
4977 NewTemplateArgs))
4978 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004979
Douglas Gregor5a064722011-02-28 17:23:35 +00004980 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004981
Douglas Gregor5a064722011-02-28 17:23:35 +00004982 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4983 QualType Result
4984 = getSema().Context.getDependentTemplateSpecializationType(
4985 TL.getTypePtr()->getKeyword(),
4986 DTN->getQualifier(),
4987 DTN->getIdentifier(),
4988 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregor5a064722011-02-28 17:23:35 +00004990 DependentTemplateSpecializationTypeLoc NewTL
4991 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004992 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004993 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004994 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004995 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004996 NewTL.setLAngleLoc(TL.getLAngleLoc());
4997 NewTL.setRAngleLoc(TL.getRAngleLoc());
4998 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4999 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5000 return Result;
5001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
5003 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005004 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005005 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005006 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
Douglas Gregor5a064722011-02-28 17:23:35 +00005008 if (!Result.isNull()) {
5009 /// FIXME: Wrap this in an elaborated-type-specifier?
5010 TemplateSpecializationTypeLoc NewTL
5011 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005012 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005013 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005014 NewTL.setLAngleLoc(TL.getLAngleLoc());
5015 NewTL.setRAngleLoc(TL.getRAngleLoc());
5016 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5017 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005019
Douglas Gregor5a064722011-02-28 17:23:35 +00005020 return Result;
5021}
5022
Mike Stump11289f42009-09-09 15:08:12 +00005023template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005024QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005025TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005026 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005027 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005028
Douglas Gregor844cb502011-03-01 18:12:44 +00005029 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005030 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005031 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005032 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005033 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5034 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005035 return QualType();
5036 }
Mike Stump11289f42009-09-09 15:08:12 +00005037
John McCall31f82722010-11-12 08:19:04 +00005038 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5039 if (NamedT.isNull())
5040 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005041
Richard Smith3f1b5d02011-05-05 21:57:07 +00005042 // C++0x [dcl.type.elab]p2:
5043 // If the identifier resolves to a typedef-name or the simple-template-id
5044 // resolves to an alias template specialization, the
5045 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005046 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5047 if (const TemplateSpecializationType *TST =
5048 NamedT->getAs<TemplateSpecializationType>()) {
5049 TemplateName Template = TST->getTemplateName();
5050 if (TypeAliasTemplateDecl *TAT =
5051 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5052 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5053 diag::err_tag_reference_non_tag) << 4;
5054 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5055 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005056 }
5057 }
5058
John McCall550e0c22009-10-21 00:40:46 +00005059 QualType Result = TL.getType();
5060 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005061 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005062 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005063 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005064 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005065 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005066 if (Result.isNull())
5067 return QualType();
5068 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005069
Abramo Bagnara6150c882010-05-11 21:36:43 +00005070 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005071 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005072 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005073 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005074}
Mike Stump11289f42009-09-09 15:08:12 +00005075
5076template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005077QualType TreeTransform<Derived>::TransformAttributedType(
5078 TypeLocBuilder &TLB,
5079 AttributedTypeLoc TL) {
5080 const AttributedType *oldType = TL.getTypePtr();
5081 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5082 if (modifiedType.isNull())
5083 return QualType();
5084
5085 QualType result = TL.getType();
5086
5087 // FIXME: dependent operand expressions?
5088 if (getDerived().AlwaysRebuild() ||
5089 modifiedType != oldType->getModifiedType()) {
5090 // TODO: this is really lame; we should really be rebuilding the
5091 // equivalent type from first principles.
5092 QualType equivalentType
5093 = getDerived().TransformType(oldType->getEquivalentType());
5094 if (equivalentType.isNull())
5095 return QualType();
5096 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5097 modifiedType,
5098 equivalentType);
5099 }
5100
5101 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5102 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5103 if (TL.hasAttrOperand())
5104 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5105 if (TL.hasAttrExprOperand())
5106 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5107 else if (TL.hasAttrEnumOperand())
5108 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5109
5110 return result;
5111}
5112
5113template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005114QualType
5115TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5116 ParenTypeLoc TL) {
5117 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5118 if (Inner.isNull())
5119 return QualType();
5120
5121 QualType Result = TL.getType();
5122 if (getDerived().AlwaysRebuild() ||
5123 Inner != TL.getInnerLoc().getType()) {
5124 Result = getDerived().RebuildParenType(Inner);
5125 if (Result.isNull())
5126 return QualType();
5127 }
5128
5129 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5130 NewTL.setLParenLoc(TL.getLParenLoc());
5131 NewTL.setRParenLoc(TL.getRParenLoc());
5132 return Result;
5133}
5134
5135template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005136QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005137 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005138 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005139
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005140 NestedNameSpecifierLoc QualifierLoc
5141 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5142 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005143 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005144
John McCallc392f372010-06-11 00:33:02 +00005145 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005146 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005147 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005148 QualifierLoc,
5149 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005150 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005151 if (Result.isNull())
5152 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005153
Abramo Bagnarad7548482010-05-19 21:37:53 +00005154 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5155 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005156 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5157
Abramo Bagnarad7548482010-05-19 21:37:53 +00005158 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005159 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005160 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005161 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005162 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005163 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005164 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005165 NewTL.setNameLoc(TL.getNameLoc());
5166 }
John McCall550e0c22009-10-21 00:40:46 +00005167 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005168}
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregord6ff3322009-08-04 16:50:30 +00005170template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005171QualType TreeTransform<Derived>::
5172 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005173 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005174 NestedNameSpecifierLoc QualifierLoc;
5175 if (TL.getQualifierLoc()) {
5176 QualifierLoc
5177 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5178 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005179 return QualType();
5180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005181
John McCall31f82722010-11-12 08:19:04 +00005182 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005183 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005184}
5185
5186template<typename Derived>
5187QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5189 DependentTemplateSpecializationTypeLoc TL,
5190 NestedNameSpecifierLoc QualifierLoc) {
5191 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005192
Douglas Gregora7a795b2011-03-01 20:11:18 +00005193 TemplateArgumentListInfo NewTemplateArgs;
5194 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5195 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005196
Douglas Gregora7a795b2011-03-01 20:11:18 +00005197 typedef TemplateArgumentLocContainerIterator<
5198 DependentTemplateSpecializationTypeLoc> ArgIterator;
5199 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5200 ArgIterator(TL, TL.getNumArgs()),
5201 NewTemplateArgs))
5202 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005203
Douglas Gregora7a795b2011-03-01 20:11:18 +00005204 QualType Result
5205 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5206 QualifierLoc,
5207 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005208 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005209 NewTemplateArgs);
5210 if (Result.isNull())
5211 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005212
Douglas Gregora7a795b2011-03-01 20:11:18 +00005213 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5214 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005215
Douglas Gregora7a795b2011-03-01 20:11:18 +00005216 // Copy information relevant to the template specialization.
5217 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005218 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005219 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005220 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005221 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5222 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005223 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005224 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
Douglas Gregora7a795b2011-03-01 20:11:18 +00005226 // Copy information relevant to the elaborated type.
5227 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005228 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005229 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005230 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5231 DependentTemplateSpecializationTypeLoc SpecTL
5232 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005233 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005234 SpecTL.setQualifierLoc(QualifierLoc);
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 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005242 TemplateSpecializationTypeLoc SpecTL
5243 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005244 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005245 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005246 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5247 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005248 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005249 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005250 }
5251 return Result;
5252}
5253
5254template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005255QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5256 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005257 QualType Pattern
5258 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005259 if (Pattern.isNull())
5260 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005261
5262 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005263 if (getDerived().AlwaysRebuild() ||
5264 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005265 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005266 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005267 TL.getEllipsisLoc(),
5268 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005269 if (Result.isNull())
5270 return QualType();
5271 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregor822d0302011-01-12 17:07:58 +00005273 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5274 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5275 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005276}
5277
5278template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005279QualType
5280TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005281 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005282 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005283 TLB.pushFullCopy(TL);
5284 return TL.getType();
5285}
5286
5287template<typename Derived>
5288QualType
5289TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005290 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005291 // ObjCObjectType is never dependent.
5292 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005293 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005294}
Mike Stump11289f42009-09-09 15:08:12 +00005295
5296template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005297QualType
5298TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005299 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005300 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005301 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005302 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005303}
5304
Douglas Gregord6ff3322009-08-04 16:50:30 +00005305//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005306// Statement transformation
5307//===----------------------------------------------------------------------===//
5308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005311 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005312}
5313
5314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005315StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005316TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5317 return getDerived().TransformCompoundStmt(S, false);
5318}
5319
5320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005321StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005322TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005323 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005324 Sema::CompoundScopeRAII CompoundScope(getSema());
5325
John McCall1ababa62010-08-27 19:56:05 +00005326 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005327 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005328 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005329 for (auto *B : S->body()) {
5330 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005331 if (Result.isInvalid()) {
5332 // Immediately fail if this was a DeclStmt, since it's very
5333 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005334 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005335 return StmtError();
5336
5337 // Otherwise, just keep processing substatements and fail later.
5338 SubStmtInvalid = true;
5339 continue;
5340 }
Mike Stump11289f42009-09-09 15:08:12 +00005341
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005342 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005343 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 }
Mike Stump11289f42009-09-09 15:08:12 +00005345
John McCall1ababa62010-08-27 19:56:05 +00005346 if (SubStmtInvalid)
5347 return StmtError();
5348
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 if (!getDerived().AlwaysRebuild() &&
5350 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005351 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005352
5353 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005354 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005355 S->getRBracLoc(),
5356 IsStmtExpr);
5357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005360StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005361TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005362 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005363 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005364 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5365 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005366
Eli Friedman06577382009-11-19 03:14:00 +00005367 // Transform the left-hand case value.
5368 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005369 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005370 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005372
Eli Friedman06577382009-11-19 03:14:00 +00005373 // Transform the right-hand case value (for the GNU case-range extension).
5374 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005375 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005376 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005378 }
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregorebe10102009-08-20 07:17:43 +00005380 // Build the case statement.
5381 // Case statements are always rebuilt so that they will attached to their
5382 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005383 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005384 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005386 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 S->getColonLoc());
5388 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregorebe10102009-08-20 07:17:43 +00005391 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005392 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005393 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregorebe10102009-08-20 07:17:43 +00005396 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005397 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005398}
5399
5400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005401StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005402TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005403 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005404 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005405 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 // Default statements are always rebuilt
5409 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005410 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005411}
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005415TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005416 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005417 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005419
Chris Lattnercab02a62011-02-17 20:34:02 +00005420 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5421 S->getDecl());
5422 if (!LD)
5423 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005424
5425
Douglas Gregorebe10102009-08-20 07:17:43 +00005426 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005427 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005428 cast<LabelDecl>(LD), SourceLocation(),
5429 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005430}
Mike Stump11289f42009-09-09 15:08:12 +00005431
Douglas Gregorebe10102009-08-20 07:17:43 +00005432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005433StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005434TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5435 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5436 if (SubStmt.isInvalid())
5437 return StmtError();
5438
5439 // TODO: transform attributes
5440 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5441 return S;
5442
5443 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5444 S->getAttrs(),
5445 SubStmt.get());
5446}
5447
5448template<typename Derived>
5449StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005450TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005451 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005452 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005453 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005454 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005455 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005456 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005457 getDerived().TransformDefinition(
5458 S->getConditionVariable()->getLocation(),
5459 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005460 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005462 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005463 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005464
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005465 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005467
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005468 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005469 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005470 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005471 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005472 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005473 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
John McCallb268a282010-08-23 23:25:46 +00005475 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005476 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005478
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005479 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005480 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005482
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005484 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005489 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005494 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005495 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005496 Then.get() == S->getThen() &&
5497 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005498 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005500 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005501 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005502 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503}
5504
5505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005507TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005509 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005510 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005511 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005512 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005513 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005514 getDerived().TransformDefinition(
5515 S->getConditionVariable()->getLocation(),
5516 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005517 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005519 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005520 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005522 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005524 }
Mike Stump11289f42009-09-09 15:08:12 +00005525
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005527 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005528 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005529 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005531 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregorebe10102009-08-20 07:17:43 +00005533 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005534 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005535 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005537
Douglas Gregorebe10102009-08-20 07:17:43 +00005538 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005539 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5540 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005541}
Mike Stump11289f42009-09-09 15:08:12 +00005542
Douglas Gregorebe10102009-08-20 07:17:43 +00005543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005544StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005545TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005546 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005547 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005548 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005549 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005550 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005551 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005552 getDerived().TransformDefinition(
5553 S->getConditionVariable()->getLocation(),
5554 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005555 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005557 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005558 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005559
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005560 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005562
5563 if (S->getCond()) {
5564 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005565 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5566 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005567 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005568 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005570 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005571 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005572 }
Mike Stump11289f42009-09-09 15:08:12 +00005573
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005574 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005575 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005577
Douglas Gregorebe10102009-08-20 07:17:43 +00005578 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005579 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005580 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005584 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005585 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005587 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005589 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005590 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005591}
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005595TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005597 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005601 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005602 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005603 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005605
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 if (!getDerived().AlwaysRebuild() &&
5607 Cond.get() == S->getCond() &&
5608 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005609 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCallb268a282010-08-23 23:25:46 +00005611 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5612 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 S->getRParenLoc());
5614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregorebe10102009-08-20 07:17:43 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005618TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005619 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005620 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005622 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005625 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005626 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005627 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005628 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005629 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005630 getDerived().TransformDefinition(
5631 S->getConditionVariable()->getLocation(),
5632 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005633 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005634 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005635 } else {
5636 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005637
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005638 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005640
5641 if (S->getCond()) {
5642 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005643 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5644 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005645 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005646 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005648
John McCallb268a282010-08-23 23:25:46 +00005649 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005650 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005651 }
Mike Stump11289f42009-09-09 15:08:12 +00005652
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005653 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005654 if (!S->getConditionVariable() && S->getCond() && !FullCond.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 increment
John McCalldadc5752010-08-24 06:29:42 +00005658 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Richard Smith945f8d32013-01-14 22:39:08 +00005662 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005663 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005667 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 if (!getDerived().AlwaysRebuild() &&
5672 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005673 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 Inc.get() == S->getInc() &&
5675 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005676 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005679 Init.get(), FullCond, ConditionVar,
5680 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005681}
5682
5683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005684StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005685TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005686 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5687 S->getLabel());
5688 if (!LD)
5689 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005692 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005693 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005694}
5695
5696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005697StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005698TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005699 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005700 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005701 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005702 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704 if (!getDerived().AlwaysRebuild() &&
5705 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005706 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005707
5708 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005709 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005710}
5711
5712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005713StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005714TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005715 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005716}
Mike Stump11289f42009-09-09 15:08:12 +00005717
Douglas Gregorebe10102009-08-20 07:17:43 +00005718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005719StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005720TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005721 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005722}
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregorebe10102009-08-20 07:17:43 +00005724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005725StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005726TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005727 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005728 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005729 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005730
Mike Stump11289f42009-09-09 15:08:12 +00005731 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005732 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005733 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005734}
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregorebe10102009-08-20 07:17:43 +00005736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005737StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005738TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005739 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005740 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005741 for (auto *D : S->decls()) {
5742 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005743 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005745
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005746 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005747 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregorebe10102009-08-20 07:17:43 +00005749 Decls.push_back(Transformed);
5750 }
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregorebe10102009-08-20 07:17:43 +00005752 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005753 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005754
Rafael Espindolaab417692013-07-09 12:05:01 +00005755 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005756}
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregorebe10102009-08-20 07:17:43 +00005758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005759StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005760TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005761
Benjamin Kramerf0623432012-08-23 22:51:59 +00005762 SmallVector<Expr*, 8> Constraints;
5763 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005764 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005765
John McCalldadc5752010-08-24 06:29:42 +00005766 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005767 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005768
5769 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005770
Anders Carlssonaaeef072010-01-24 05:50:09 +00005771 // Go through the outputs.
5772 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005773 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005774
Anders Carlssonaaeef072010-01-24 05:50:09 +00005775 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005776 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005777
Anders Carlssonaaeef072010-01-24 05:50:09 +00005778 // Transform the output expr.
5779 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005780 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005781 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005782 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005783
Anders Carlssonaaeef072010-01-24 05:50:09 +00005784 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005785
John McCallb268a282010-08-23 23:25:46 +00005786 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005788
Anders Carlssonaaeef072010-01-24 05:50:09 +00005789 // Go through the inputs.
5790 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005791 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005792
Anders Carlssonaaeef072010-01-24 05:50:09 +00005793 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005794 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Anders Carlssonaaeef072010-01-24 05:50:09 +00005796 // Transform the input expr.
5797 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005798 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005799 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005800 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005801
Anders Carlssonaaeef072010-01-24 05:50:09 +00005802 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005803
John McCallb268a282010-08-23 23:25:46 +00005804 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005806
Anders Carlssonaaeef072010-01-24 05:50:09 +00005807 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005808 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005809
5810 // Go through the clobbers.
5811 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005812 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005813
5814 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005815 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005816 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5817 S->isVolatile(), S->getNumOutputs(),
5818 S->getNumInputs(), Names.data(),
5819 Constraints, Exprs, AsmString.get(),
5820 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005821}
5822
Chad Rosier32503022012-06-11 20:47:18 +00005823template<typename Derived>
5824StmtResult
5825TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005826 ArrayRef<Token> AsmToks =
5827 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005828
John McCallf413f5e2013-05-03 00:10:13 +00005829 bool HadError = false, HadChange = false;
5830
5831 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5832 SmallVector<Expr*, 8> TransformedExprs;
5833 TransformedExprs.reserve(SrcExprs.size());
5834 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5835 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5836 if (!Result.isUsable()) {
5837 HadError = true;
5838 } else {
5839 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005840 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005841 }
5842 }
5843
5844 if (HadError) return StmtError();
5845 if (!HadChange && !getDerived().AlwaysRebuild())
5846 return Owned(S);
5847
Chad Rosierb6f46c12012-08-15 16:53:30 +00005848 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005849 AsmToks, S->getAsmString(),
5850 S->getNumOutputs(), S->getNumInputs(),
5851 S->getAllConstraints(), S->getClobbers(),
5852 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005853}
Douglas Gregorebe10102009-08-20 07:17:43 +00005854
5855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005856StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005857TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005858 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005859 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005860 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005861 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Douglas Gregor96c79492010-04-23 22:50:49 +00005863 // Transform the @catch statements (if present).
5864 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005865 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005866 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005867 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005868 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005869 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005870 if (Catch.get() != S->getCatchStmt(I))
5871 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005872 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Douglas Gregor306de2f2010-04-22 23:59:56 +00005875 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005876 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005877 if (S->getFinallyStmt()) {
5878 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5879 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005881 }
5882
5883 // If nothing changed, just retain this statement.
5884 if (!getDerived().AlwaysRebuild() &&
5885 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005886 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005887 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005888 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
Douglas Gregor306de2f2010-04-22 23:59:56 +00005890 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005891 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005892 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005893}
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregorebe10102009-08-20 07:17:43 +00005895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005896StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005897TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005898 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005899 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005900 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005901 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005902 if (FromVar->getTypeSourceInfo()) {
5903 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5904 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +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 QualType T;
5909 if (TSInfo)
5910 T = TSInfo->getType();
5911 else {
5912 T = getDerived().TransformType(FromVar->getType());
5913 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005914 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005915 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005916
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005917 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5918 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005921
John McCalldadc5752010-08-24 06:29:42 +00005922 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005923 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005924 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005925
5926 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005927 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005928 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005929}
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregorebe10102009-08-20 07:17:43 +00005931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005932StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005933TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005934 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005935 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005936 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
Douglas Gregor306de2f2010-04-22 23:59:56 +00005939 // If nothing changed, just retain this statement.
5940 if (!getDerived().AlwaysRebuild() &&
5941 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005942 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005943
5944 // Build a new statement.
5945 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005946 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregorebe10102009-08-20 07:17:43 +00005949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005951TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005952 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005953 if (S->getThrowExpr()) {
5954 Operand = getDerived().TransformExpr(S->getThrowExpr());
5955 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005958
Douglas Gregor2900c162010-04-22 21:44:01 +00005959 if (!getDerived().AlwaysRebuild() &&
5960 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005961 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005962
John McCallb268a282010-08-23 23:25:46 +00005963 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005964}
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregorebe10102009-08-20 07:17:43 +00005966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005967StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005968TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005969 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005970 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005971 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005972 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005974 Object =
5975 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5976 Object.get());
5977 if (Object.isInvalid())
5978 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregor6148de72010-04-22 22:01:21 +00005980 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005981 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005982 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005983 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
Douglas Gregor6148de72010-04-22 22:01:21 +00005985 // If nothing change, just retain the current statement.
5986 if (!getDerived().AlwaysRebuild() &&
5987 Object.get() == S->getSynchExpr() &&
5988 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005989 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00005990
5991 // Build a new statement.
5992 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005993 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005994}
5995
5996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005997StmtResult
John McCall31168b02011-06-15 23:02:42 +00005998TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5999 ObjCAutoreleasePoolStmt *S) {
6000 // Transform the body.
6001 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6002 if (Body.isInvalid())
6003 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006004
John McCall31168b02011-06-15 23:02:42 +00006005 // If nothing changed, just retain this statement.
6006 if (!getDerived().AlwaysRebuild() &&
6007 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006008 return S;
John McCall31168b02011-06-15 23:02:42 +00006009
6010 // Build a new statement.
6011 return getDerived().RebuildObjCAutoreleasePoolStmt(
6012 S->getAtLoc(), Body.get());
6013}
6014
6015template<typename Derived>
6016StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006017TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006018 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006019 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006020 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006021 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
Douglas Gregorf68a5082010-04-22 23:10:45 +00006024 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006025 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006026 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006027 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006028
Douglas Gregorf68a5082010-04-22 23:10:45 +00006029 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006030 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006031 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006033
Douglas Gregorf68a5082010-04-22 23:10:45 +00006034 // If nothing changed, just retain this statement.
6035 if (!getDerived().AlwaysRebuild() &&
6036 Element.get() == S->getElement() &&
6037 Collection.get() == S->getCollection() &&
6038 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006039 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006040
Douglas Gregorf68a5082010-04-22 23:10:45 +00006041 // Build a new statement.
6042 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006043 Element.get(),
6044 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006045 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006046 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006047}
6048
David Majnemer5f7efef2013-10-15 09:50:08 +00006049template <typename Derived>
6050StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006052 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006053 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6054 TypeSourceInfo *T =
6055 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006056 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006057 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006058
David Majnemer5f7efef2013-10-15 09:50:08 +00006059 Var = getDerived().RebuildExceptionDecl(
6060 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6061 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006062 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006063 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 }
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregorebe10102009-08-20 07:17:43 +00006066 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006067 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006068 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006069 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006070
David Majnemer5f7efef2013-10-15 09:50:08 +00006071 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006073 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006074
David Majnemer5f7efef2013-10-15 09:50:08 +00006075 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006076}
Mike Stump11289f42009-09-09 15:08:12 +00006077
David Majnemer5f7efef2013-10-15 09:50:08 +00006078template <typename Derived>
6079StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006081 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006083 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 // Transform the handlers.
6086 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006087 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006088 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006089 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006092
Douglas Gregorebe10102009-08-20 07:17:43 +00006093 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006094 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 }
Mike Stump11289f42009-09-09 15:08:12 +00006096
David Majnemer5f7efef2013-10-15 09:50:08 +00006097 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006099 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006100
John McCallb268a282010-08-23 23:25:46 +00006101 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006102 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006103}
Mike Stump11289f42009-09-09 15:08:12 +00006104
Richard Smith02e85f32011-04-14 22:09:26 +00006105template<typename Derived>
6106StmtResult
6107TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6108 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6109 if (Range.isInvalid())
6110 return StmtError();
6111
6112 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6113 if (BeginEnd.isInvalid())
6114 return StmtError();
6115
6116 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6117 if (Cond.isInvalid())
6118 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006119 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006120 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006121 if (Cond.isInvalid())
6122 return StmtError();
6123 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006124 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006125
6126 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6127 if (Inc.isInvalid())
6128 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006129 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006130 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006131
6132 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6133 if (LoopVar.isInvalid())
6134 return StmtError();
6135
6136 StmtResult NewStmt = S;
6137 if (getDerived().AlwaysRebuild() ||
6138 Range.get() != S->getRangeStmt() ||
6139 BeginEnd.get() != S->getBeginEndStmt() ||
6140 Cond.get() != S->getCond() ||
6141 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006142 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006143 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6144 S->getColonLoc(), Range.get(),
6145 BeginEnd.get(), Cond.get(),
6146 Inc.get(), LoopVar.get(),
6147 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006148 if (NewStmt.isInvalid())
6149 return StmtError();
6150 }
Richard Smith02e85f32011-04-14 22:09:26 +00006151
6152 StmtResult Body = getDerived().TransformStmt(S->getBody());
6153 if (Body.isInvalid())
6154 return StmtError();
6155
6156 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6157 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006158 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006159 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6160 S->getColonLoc(), Range.get(),
6161 BeginEnd.get(), Cond.get(),
6162 Inc.get(), LoopVar.get(),
6163 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006164 if (NewStmt.isInvalid())
6165 return StmtError();
6166 }
Richard Smith02e85f32011-04-14 22:09:26 +00006167
6168 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006169 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006170
6171 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6172}
6173
John Wiegley1c0675e2011-04-28 01:08:34 +00006174template<typename Derived>
6175StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006176TreeTransform<Derived>::TransformMSDependentExistsStmt(
6177 MSDependentExistsStmt *S) {
6178 // Transform the nested-name-specifier, if any.
6179 NestedNameSpecifierLoc QualifierLoc;
6180 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006181 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006182 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6183 if (!QualifierLoc)
6184 return StmtError();
6185 }
6186
6187 // Transform the declaration name.
6188 DeclarationNameInfo NameInfo = S->getNameInfo();
6189 if (NameInfo.getName()) {
6190 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6191 if (!NameInfo.getName())
6192 return StmtError();
6193 }
6194
6195 // Check whether anything changed.
6196 if (!getDerived().AlwaysRebuild() &&
6197 QualifierLoc == S->getQualifierLoc() &&
6198 NameInfo.getName() == S->getNameInfo().getName())
6199 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006201 // Determine whether this name exists, if we can.
6202 CXXScopeSpec SS;
6203 SS.Adopt(QualifierLoc);
6204 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006205 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006206 case Sema::IER_Exists:
6207 if (S->isIfExists())
6208 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006210 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6211
6212 case Sema::IER_DoesNotExist:
6213 if (S->isIfNotExists())
6214 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006215
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006216 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006218 case Sema::IER_Dependent:
6219 Dependent = true;
6220 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006221
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006222 case Sema::IER_Error:
6223 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006226 // We need to continue with the instantiation, so do so now.
6227 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6228 if (SubStmt.isInvalid())
6229 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006230
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006231 // If we have resolved the name, just transform to the substatement.
6232 if (!Dependent)
6233 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006234
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006235 // The name is still dependent, so build a dependent expression again.
6236 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6237 S->isIfExists(),
6238 QualifierLoc,
6239 NameInfo,
6240 SubStmt.get());
6241}
6242
6243template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006244ExprResult
6245TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6246 NestedNameSpecifierLoc QualifierLoc;
6247 if (E->getQualifierLoc()) {
6248 QualifierLoc
6249 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6250 if (!QualifierLoc)
6251 return ExprError();
6252 }
6253
6254 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6255 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6256 if (!PD)
6257 return ExprError();
6258
6259 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6260 if (Base.isInvalid())
6261 return ExprError();
6262
6263 return new (SemaRef.getASTContext())
6264 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6265 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6266 QualifierLoc, E->getMemberLoc());
6267}
6268
David Majnemerfad8f482013-10-15 09:33:02 +00006269template <typename Derived>
6270StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006271 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006272 if (TryBlock.isInvalid())
6273 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006274
6275 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006276 if (Handler.isInvalid())
6277 return StmtError();
6278
David Majnemerfad8f482013-10-15 09:33:02 +00006279 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6280 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006281 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006282
David Majnemerfad8f482013-10-15 09:33:02 +00006283 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006284 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006285}
6286
David Majnemerfad8f482013-10-15 09:33:02 +00006287template <typename Derived>
6288StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006289 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006290 if (Block.isInvalid())
6291 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006292
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006293 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006294}
6295
David Majnemerfad8f482013-10-15 09:33:02 +00006296template <typename Derived>
6297StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006298 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006299 if (FilterExpr.isInvalid())
6300 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006301
David Majnemer7e755502013-10-15 09:30:14 +00006302 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006303 if (Block.isInvalid())
6304 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006305
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006306 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6307 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006308}
6309
David Majnemerfad8f482013-10-15 09:33:02 +00006310template <typename Derived>
6311StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6312 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006313 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6314 else
6315 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6316}
6317
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006318template<typename Derived>
6319StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006320TreeTransform<Derived>::TransformOMPExecutableDirective(
6321 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006322
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006323 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006324 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006325 ArrayRef<OMPClause *> Clauses = D->clauses();
6326 TClauses.reserve(Clauses.size());
6327 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6328 I != E; ++I) {
6329 if (*I) {
6330 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006331 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006332 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006333 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006334 TClauses.push_back(Clause);
6335 }
6336 else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006337 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006338 }
6339 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006340 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006341 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006342 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006343 StmtResult AssociatedStmt =
6344 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006345 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006346 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006347 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006348
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006349 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6350 TClauses,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006351 AssociatedStmt.get(),
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006352 D->getLocStart(),
6353 D->getLocEnd());
6354}
6355
6356template<typename Derived>
6357StmtResult
6358TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6359 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006360 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006361 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6362 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6363 return Res;
6364}
6365
6366template<typename Derived>
6367StmtResult
6368TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6369 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006370 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006371 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6372 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006373 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006374}
6375
6376template<typename Derived>
6377OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006378TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006379 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6380 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006381 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006382 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006383 C->getLParenLoc(), C->getLocEnd());
6384}
6385
6386template<typename Derived>
6387OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006388TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6389 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6390 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006391 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006392 return getDerived().RebuildOMPNumThreadsClause(NumThreads.get(),
Alexey Bataev568a8332014-03-06 06:15:19 +00006393 C->getLocStart(),
6394 C->getLParenLoc(),
6395 C->getLocEnd());
6396}
6397
Alexey Bataev62c87d22014-03-21 04:51:18 +00006398template <typename Derived>
6399OMPClause *
6400TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6401 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6402 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006403 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006404 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006405 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006406}
6407
Alexander Musman8bd31e62014-05-27 15:12:19 +00006408template <typename Derived>
6409OMPClause *
6410TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6411 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6412 if (E.isInvalid())
6413 return 0;
6414 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006415 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006416}
6417
Alexey Bataev568a8332014-03-06 06:15:19 +00006418template<typename Derived>
6419OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006420TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6421 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6422 C->getDefaultKindKwLoc(),
6423 C->getLocStart(),
6424 C->getLParenLoc(),
6425 C->getLocEnd());
6426}
6427
6428template<typename Derived>
6429OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006430TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
6431 return getDerived().RebuildOMPProcBindClause(C->getProcBindKind(),
6432 C->getProcBindKindKwLoc(),
6433 C->getLocStart(),
6434 C->getLParenLoc(),
6435 C->getLocEnd());
6436}
6437
6438template<typename Derived>
6439OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006440TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006441 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006442 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006443 for (auto *VE : C->varlists()) {
6444 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006445 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006446 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006447 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006448 }
6449 return getDerived().RebuildOMPPrivateClause(Vars,
6450 C->getLocStart(),
6451 C->getLParenLoc(),
6452 C->getLocEnd());
6453}
6454
Alexey Bataev758e55e2013-09-06 18:03:48 +00006455template<typename Derived>
6456OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006457TreeTransform<Derived>::TransformOMPFirstprivateClause(
6458 OMPFirstprivateClause *C) {
6459 llvm::SmallVector<Expr *, 16> Vars;
6460 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006461 for (auto *VE : C->varlists()) {
6462 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006463 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006464 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006465 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006466 }
6467 return getDerived().RebuildOMPFirstprivateClause(Vars,
6468 C->getLocStart(),
6469 C->getLParenLoc(),
6470 C->getLocEnd());
6471}
6472
6473template<typename Derived>
6474OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006475TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6476 llvm::SmallVector<Expr *, 16> Vars;
6477 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006478 for (auto *VE : C->varlists()) {
6479 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006480 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006481 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006482 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006483 }
6484 return getDerived().RebuildOMPSharedClause(Vars,
6485 C->getLocStart(),
6486 C->getLParenLoc(),
6487 C->getLocEnd());
6488}
6489
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006490template<typename Derived>
6491OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006492TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6493 llvm::SmallVector<Expr *, 16> Vars;
6494 Vars.reserve(C->varlist_size());
6495 for (auto *VE : C->varlists()) {
6496 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6497 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006498 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006499 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006500 }
6501 ExprResult Step = getDerived().TransformExpr(C->getStep());
6502 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006503 return nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +00006504 return getDerived().RebuildOMPLinearClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006505 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexander Musman8dba6642014-04-22 13:09:42 +00006506 C->getLocEnd());
6507}
6508
6509template<typename Derived>
6510OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006511TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6512 llvm::SmallVector<Expr *, 16> Vars;
6513 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006514 for (auto *VE : C->varlists()) {
6515 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006516 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006517 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006518 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006519 }
6520 return getDerived().RebuildOMPCopyinClause(Vars,
6521 C->getLocStart(),
6522 C->getLParenLoc(),
6523 C->getLocEnd());
6524}
6525
Douglas Gregorebe10102009-08-20 07:17:43 +00006526//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006527// Expression transformation
6528//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006531TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006532 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
6535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006537TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006538 NestedNameSpecifierLoc QualifierLoc;
6539 if (E->getQualifierLoc()) {
6540 QualifierLoc
6541 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6542 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006543 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006544 }
John McCallce546572009-12-08 09:08:17 +00006545
6546 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006547 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6548 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006551
John McCall815039a2010-08-17 21:27:17 +00006552 DeclarationNameInfo NameInfo = E->getNameInfo();
6553 if (NameInfo.getName()) {
6554 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6555 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006557 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006558
6559 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006560 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006561 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006562 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006563 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006564
6565 // Mark it referenced in the new context regardless.
6566 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006567 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006568
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006569 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006570 }
John McCallce546572009-12-08 09:08:17 +00006571
Craig Topperc3ec1492014-05-26 06:22:03 +00006572 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006573 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006574 TemplateArgs = &TransArgs;
6575 TransArgs.setLAngleLoc(E->getLAngleLoc());
6576 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006577 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6578 E->getNumTemplateArgs(),
6579 TransArgs))
6580 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006581 }
6582
Chad Rosier1dcde962012-08-08 18:46:20 +00006583 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006584 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006590 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006591}
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregora16548e2009-08-11 05:31:07 +00006593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006596 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006597}
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregora16548e2009-08-11 05:31:07 +00006599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006600ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006602 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006603}
Mike Stump11289f42009-09-09 15:08:12 +00006604
Douglas Gregora16548e2009-08-11 05:31:07 +00006605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006606ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006607TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006608 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006609}
Mike Stump11289f42009-09-09 15:08:12 +00006610
Douglas Gregora16548e2009-08-11 05:31:07 +00006611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006614 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006615}
6616
6617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006618ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006619TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006620 if (FunctionDecl *FD = E->getDirectCallee())
6621 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006622 return SemaRef.MaybeBindToTemporary(E);
6623}
6624
6625template<typename Derived>
6626ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006627TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6628 ExprResult ControllingExpr =
6629 getDerived().TransformExpr(E->getControllingExpr());
6630 if (ControllingExpr.isInvalid())
6631 return ExprError();
6632
Chris Lattner01cf8db2011-07-20 06:58:45 +00006633 SmallVector<Expr *, 4> AssocExprs;
6634 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006635 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6636 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6637 if (TS) {
6638 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6639 if (!AssocType)
6640 return ExprError();
6641 AssocTypes.push_back(AssocType);
6642 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006643 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006644 }
6645
6646 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6647 if (AssocExpr.isInvalid())
6648 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006649 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006650 }
6651
6652 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6653 E->getDefaultLoc(),
6654 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006655 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006656 AssocTypes,
6657 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006658}
6659
6660template<typename Derived>
6661ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006662TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006663 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006668 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006669
John McCallb268a282010-08-23 23:25:46 +00006670 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006671 E->getRParen());
6672}
6673
Richard Smithdb2630f2012-10-21 03:28:35 +00006674/// \brief The operand of a unary address-of operator has special rules: it's
6675/// allowed to refer to a non-static member of a class even if there's no 'this'
6676/// object available.
6677template<typename Derived>
6678ExprResult
6679TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6680 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6681 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6682 else
6683 return getDerived().TransformExpr(E);
6684}
6685
Mike Stump11289f42009-09-09 15:08:12 +00006686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006688TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006689 ExprResult SubExpr;
6690 if (E->getOpcode() == UO_AddrOf)
6691 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6692 else
6693 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006698 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006699
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6701 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006702 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006703}
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006706ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006707TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6708 // Transform the type.
6709 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6710 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006711 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006712
Douglas Gregor882211c2010-04-28 22:16:22 +00006713 // Transform all of the components into components similar to what the
6714 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006715 // FIXME: It would be slightly more efficient in the non-dependent case to
6716 // just map FieldDecls, rather than requiring the rebuilder to look for
6717 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006718 // template code that we don't care.
6719 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006720 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006721 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006722 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006723 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6724 const Node &ON = E->getComponent(I);
6725 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006726 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006727 Comp.LocStart = ON.getSourceRange().getBegin();
6728 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006729 switch (ON.getKind()) {
6730 case Node::Array: {
6731 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006732 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006733 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006734 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006735
Douglas Gregor882211c2010-04-28 22:16:22 +00006736 ExprChanged = ExprChanged || Index.get() != FromIndex;
6737 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006738 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006739 break;
6740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006741
Douglas Gregor882211c2010-04-28 22:16:22 +00006742 case Node::Field:
6743 case Node::Identifier:
6744 Comp.isBrackets = false;
6745 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006746 if (!Comp.U.IdentInfo)
6747 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregor882211c2010-04-28 22:16:22 +00006749 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
Douglas Gregord1702062010-04-29 00:18:15 +00006751 case Node::Base:
6752 // Will be recomputed during the rebuild.
6753 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006755
Douglas Gregor882211c2010-04-28 22:16:22 +00006756 Components.push_back(Comp);
6757 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006758
Douglas Gregor882211c2010-04-28 22:16:22 +00006759 // If nothing changed, retain the existing expression.
6760 if (!getDerived().AlwaysRebuild() &&
6761 Type == E->getTypeSourceInfo() &&
6762 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006763 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006764
Douglas Gregor882211c2010-04-28 22:16:22 +00006765 // Build a new offsetof expression.
6766 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6767 Components.data(), Components.size(),
6768 E->getRParenLoc());
6769}
6770
6771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006772ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006773TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6774 assert(getDerived().AlreadyTransformed(E->getType()) &&
6775 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006776 return E;
John McCall8d69a212010-11-15 23:31:06 +00006777}
6778
6779template<typename Derived>
6780ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006781TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006782 // Rebuild the syntactic form. The original syntactic form has
6783 // opaque-value expressions in it, so strip those away and rebuild
6784 // the result. This is a really awful way of doing this, but the
6785 // better solution (rebuilding the semantic expressions and
6786 // rebinding OVEs as necessary) doesn't work; we'd need
6787 // TreeTransform to not strip away implicit conversions.
6788 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6789 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006790 if (result.isInvalid()) return ExprError();
6791
6792 // If that gives us a pseudo-object result back, the pseudo-object
6793 // expression must have been an lvalue-to-rvalue conversion which we
6794 // should reapply.
6795 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006796 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006797
6798 return result;
6799}
6800
6801template<typename Derived>
6802ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006803TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6804 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006805 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006806 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006807
John McCallbcd03502009-12-07 02:54:59 +00006808 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006809 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
John McCall4c98fd82009-11-04 07:28:41 +00006812 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006813 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006814
Peter Collingbournee190dee2011-03-11 19:24:49 +00006815 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6816 E->getKind(),
6817 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006818 }
Mike Stump11289f42009-09-09 15:08:12 +00006819
Eli Friedmane4f22df2012-02-29 04:03:55 +00006820 // C++0x [expr.sizeof]p1:
6821 // The operand is either an expression, which is an unevaluated operand
6822 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006823 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6824 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006825
Eli Friedmane4f22df2012-02-29 04:03:55 +00006826 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6827 if (SubExpr.isInvalid())
6828 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006829
Eli Friedmane4f22df2012-02-29 04:03:55 +00006830 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006831 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006832
Peter Collingbournee190dee2011-03-11 19:24:49 +00006833 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6834 E->getOperatorLoc(),
6835 E->getKind(),
6836 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006837}
Mike Stump11289f42009-09-09 15:08:12 +00006838
Douglas Gregora16548e2009-08-11 05:31:07 +00006839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006841TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006842 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006845
John McCalldadc5752010-08-24 06:29:42 +00006846 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006849
6850
Douglas Gregora16548e2009-08-11 05:31:07 +00006851 if (!getDerived().AlwaysRebuild() &&
6852 LHS.get() == E->getLHS() &&
6853 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006854 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006855
John McCallb268a282010-08-23 23:25:46 +00006856 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006858 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 E->getRBracketLoc());
6860}
Mike Stump11289f42009-09-09 15:08:12 +00006861
6862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006865 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006866 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006868 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006869
6870 // Transform arguments.
6871 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006872 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006873 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006874 &ArgChanged))
6875 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006876
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 if (!getDerived().AlwaysRebuild() &&
6878 Callee.get() == E->getCallee() &&
6879 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006880 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006883 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006884 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006885 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006886 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 E->getRParenLoc());
6888}
Mike Stump11289f42009-09-09 15:08:12 +00006889
6890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006891ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006893 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006894 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006896
Douglas Gregorea972d32011-02-28 21:54:11 +00006897 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006898 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006899 QualifierLoc
6900 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006901
Douglas Gregorea972d32011-02-28 21:54:11 +00006902 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006903 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006904 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006905 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006906
Eli Friedman2cfcef62009-12-04 06:40:45 +00006907 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006908 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6909 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006910 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006912
John McCall16df1e52010-03-30 21:47:33 +00006913 NamedDecl *FoundDecl = E->getFoundDecl();
6914 if (FoundDecl == E->getMemberDecl()) {
6915 FoundDecl = Member;
6916 } else {
6917 FoundDecl = cast_or_null<NamedDecl>(
6918 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6919 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006920 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006921 }
6922
Douglas Gregora16548e2009-08-11 05:31:07 +00006923 if (!getDerived().AlwaysRebuild() &&
6924 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006925 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006926 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006927 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006928 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006929
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006930 // Mark it referenced in the new context regardless.
6931 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006932 SemaRef.MarkMemberReferenced(E);
6933
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006934 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006935 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006936
John McCall6b51f282009-11-23 01:53:49 +00006937 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006938 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006939 TransArgs.setLAngleLoc(E->getLAngleLoc());
6940 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006941 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6942 E->getNumTemplateArgs(),
6943 TransArgs))
6944 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006946
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006948 SourceLocation FakeOperatorLoc =
6949 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006950
John McCall38836f02010-01-15 08:34:02 +00006951 // FIXME: to do this check properly, we will need to preserve the
6952 // first-qualifier-in-scope here, just in case we had a dependent
6953 // base (and therefore couldn't do the check) and a
6954 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00006955 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00006956
John McCallb268a282010-08-23 23:25:46 +00006957 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006959 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006960 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006961 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006962 Member,
John McCall16df1e52010-03-30 21:47:33 +00006963 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006964 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00006965 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00006966 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006972 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006975
John McCalldadc5752010-08-24 06:29:42 +00006976 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006977 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregora16548e2009-08-11 05:31:07 +00006980 if (!getDerived().AlwaysRebuild() &&
6981 LHS.get() == E->getLHS() &&
6982 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006983 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006984
Lang Hames5de91cc2012-10-02 04:45:10 +00006985 Sema::FPContractStateRAII FPContractState(getSema());
6986 getSema().FPFeatures.fp_contract = E->isFPContractable();
6987
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006989 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006990}
6991
Mike Stump11289f42009-09-09 15:08:12 +00006992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006993ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006994TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006995 CompoundAssignOperator *E) {
6996 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006997}
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007000ExprResult TreeTransform<Derived>::
7001TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7002 // Just rebuild the common and RHS expressions and see whether we
7003 // get any changes.
7004
7005 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7006 if (commonExpr.isInvalid())
7007 return ExprError();
7008
7009 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7010 if (rhs.isInvalid())
7011 return ExprError();
7012
7013 if (!getDerived().AlwaysRebuild() &&
7014 commonExpr.get() == e->getCommon() &&
7015 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007016 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007017
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007018 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007019 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007020 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007021 e->getColonLoc(),
7022 rhs.get());
7023}
7024
7025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007028 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007031
John McCalldadc5752010-08-24 06:29:42 +00007032 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007035
John McCalldadc5752010-08-24 06:29:42 +00007036 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007037 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007039
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 if (!getDerived().AlwaysRebuild() &&
7041 Cond.get() == E->getCond() &&
7042 LHS.get() == E->getLHS() &&
7043 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007044 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007045
John McCallb268a282010-08-23 23:25:46 +00007046 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007047 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007048 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007049 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007050 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007051}
Mike Stump11289f42009-09-09 15:08:12 +00007052
7053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007055TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007056 // Implicit casts are eliminated during transformation, since they
7057 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007058 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007059}
Mike Stump11289f42009-09-09 15:08:12 +00007060
Douglas Gregora16548e2009-08-11 05:31:07 +00007061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007064 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7065 if (!Type)
7066 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007067
John McCalldadc5752010-08-24 06:29:42 +00007068 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007069 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007070 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007072
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007074 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007075 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007076 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007077
John McCall97513962010-01-15 18:39:57 +00007078 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007079 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007081 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007082}
Mike Stump11289f42009-09-09 15:08:12 +00007083
Douglas Gregora16548e2009-08-11 05:31:07 +00007084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007086TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007087 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7088 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7089 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007091
John McCalldadc5752010-08-24 06:29:42 +00007092 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007095
Douglas Gregora16548e2009-08-11 05:31:07 +00007096 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007097 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007099 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007100
John McCall5d7aa7f2010-01-19 22:33:45 +00007101 // Note: the expression type doesn't necessarily match the
7102 // type-as-written, but that's okay, because it should always be
7103 // derivable from the initializer.
7104
John McCalle15bbff2010-01-18 19:35:47 +00007105 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007106 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007107 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007108}
Mike Stump11289f42009-09-09 15:08:12 +00007109
Douglas Gregora16548e2009-08-11 05:31:07 +00007110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007112TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007113 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007116
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 if (!getDerived().AlwaysRebuild() &&
7118 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007119 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007120
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007122 SourceLocation FakeOperatorLoc =
7123 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007124 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 E->getAccessorLoc(),
7126 E->getAccessor());
7127}
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007131TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007133
Benjamin Kramerf0623432012-08-23 22:51:59 +00007134 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007135 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007136 Inits, &InitChanged))
7137 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007138
Douglas Gregora16548e2009-08-11 05:31:07 +00007139 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007140 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007141
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007142 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007143 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007144}
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregora16548e2009-08-11 05:31:07 +00007146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007150
Douglas Gregorebe10102009-08-20 07:17:43 +00007151 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007152 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007154 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregorebe10102009-08-20 07:17:43 +00007156 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007157 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007158 bool ExprChanged = false;
7159 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7160 DEnd = E->designators_end();
7161 D != DEnd; ++D) {
7162 if (D->isFieldDesignator()) {
7163 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7164 D->getDotLoc(),
7165 D->getFieldLoc()));
7166 continue;
7167 }
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007170 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007173
7174 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007175 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007176
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007178 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007179 continue;
7180 }
Mike Stump11289f42009-09-09 15:08:12 +00007181
Douglas Gregora16548e2009-08-11 05:31:07 +00007182 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007183 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7185 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007187
John McCalldadc5752010-08-24 06:29:42 +00007188 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007189 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007191
7192 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007193 End.get(),
7194 D->getLBracketLoc(),
7195 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007196
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7198 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007199
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007200 ArrayExprs.push_back(Start.get());
7201 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007202 }
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (!getDerived().AlwaysRebuild() &&
7205 Init.get() == E->getInit() &&
7206 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007207 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007208
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007209 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007211 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007212}
Mike Stump11289f42009-09-09 15:08:12 +00007213
Douglas Gregora16548e2009-08-11 05:31:07 +00007214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007215ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007216TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007217 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007218 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007219
Douglas Gregor3da3c062009-10-28 00:29:27 +00007220 // FIXME: Will we ever have proper type location here? Will we actually
7221 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007222 QualType T = getDerived().TransformType(E->getType());
7223 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 if (!getDerived().AlwaysRebuild() &&
7227 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007228 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007229
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 return getDerived().RebuildImplicitValueInitExpr(T);
7231}
Mike Stump11289f42009-09-09 15:08:12 +00007232
Douglas Gregora16548e2009-08-11 05:31:07 +00007233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007235TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007236 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7237 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
John McCalldadc5752010-08-24 06:29:42 +00007240 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007245 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007247 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007248
John McCallb268a282010-08-23 23:25:46 +00007249 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007250 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007251}
7252
7253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007255TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007256 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007257 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007258 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7259 &ArgumentChanged))
7260 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007261
Douglas Gregora16548e2009-08-11 05:31:07 +00007262 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007263 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007264 E->getRParenLoc());
7265}
Mike Stump11289f42009-09-09 15:08:12 +00007266
Douglas Gregora16548e2009-08-11 05:31:07 +00007267/// \brief Transform an address-of-label expression.
7268///
7269/// By default, the transformation of an address-of-label expression always
7270/// rebuilds the expression, so that the label identifier can be resolved to
7271/// the corresponding label statement by semantic analysis.
7272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007274TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007275 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7276 E->getLabel());
7277 if (!LD)
7278 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007279
Douglas Gregora16548e2009-08-11 05:31:07 +00007280 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007281 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007282}
Mike Stump11289f42009-09-09 15:08:12 +00007283
7284template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007286TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007287 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007288 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007289 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007290 if (SubStmt.isInvalid()) {
7291 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007292 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007293 }
Mike Stump11289f42009-09-09 15:08:12 +00007294
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007296 SubStmt.get() == E->getSubStmt()) {
7297 // Calling this an 'error' is unintuitive, but it does the right thing.
7298 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007299 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007300 }
Mike Stump11289f42009-09-09 15:08:12 +00007301
7302 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007303 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007304 E->getRParenLoc());
7305}
Mike Stump11289f42009-09-09 15:08:12 +00007306
Douglas Gregora16548e2009-08-11 05:31:07 +00007307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007309TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007310 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007311 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007313
John McCalldadc5752010-08-24 06:29:42 +00007314 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007315 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007317
John McCalldadc5752010-08-24 06:29:42 +00007318 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007319 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007321
Douglas Gregora16548e2009-08-11 05:31:07 +00007322 if (!getDerived().AlwaysRebuild() &&
7323 Cond.get() == E->getCond() &&
7324 LHS.get() == E->getLHS() &&
7325 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007326 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007327
Douglas Gregora16548e2009-08-11 05:31:07 +00007328 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007329 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 E->getRParenLoc());
7331}
Mike Stump11289f42009-09-09 15:08:12 +00007332
Douglas Gregora16548e2009-08-11 05:31:07 +00007333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007335TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007336 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007337}
7338
7339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007341TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007342 switch (E->getOperator()) {
7343 case OO_New:
7344 case OO_Delete:
7345 case OO_Array_New:
7346 case OO_Array_Delete:
7347 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007348
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007349 case OO_Call: {
7350 // This is a call to an object's operator().
7351 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7352
7353 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007354 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007355 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007356 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007357
7358 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007359 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7360 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007361
7362 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007363 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007364 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007365 Args))
7366 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007367
John McCallb268a282010-08-23 23:25:46 +00007368 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007369 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007370 E->getLocEnd());
7371 }
7372
7373#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7374 case OO_##Name:
7375#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7376#include "clang/Basic/OperatorKinds.def"
7377 case OO_Subscript:
7378 // Handled below.
7379 break;
7380
7381 case OO_Conditional:
7382 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007383
7384 case OO_None:
7385 case NUM_OVERLOADED_OPERATORS:
7386 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007387 }
7388
John McCalldadc5752010-08-24 06:29:42 +00007389 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007392
Richard Smithdb2630f2012-10-21 03:28:35 +00007393 ExprResult First;
7394 if (E->getOperator() == OO_Amp)
7395 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7396 else
7397 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007398 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007399 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007400
John McCalldadc5752010-08-24 06:29:42 +00007401 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007402 if (E->getNumArgs() == 2) {
7403 Second = getDerived().TransformExpr(E->getArg(1));
7404 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007405 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 }
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (!getDerived().AlwaysRebuild() &&
7409 Callee.get() == E->getCallee() &&
7410 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007411 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007412 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007413
Lang Hames5de91cc2012-10-02 04:45:10 +00007414 Sema::FPContractStateRAII FPContractState(getSema());
7415 getSema().FPFeatures.fp_contract = E->isFPContractable();
7416
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7418 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007419 Callee.get(),
7420 First.get(),
7421 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007422}
Mike Stump11289f42009-09-09 15:08:12 +00007423
Douglas Gregora16548e2009-08-11 05:31:07 +00007424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007426TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7427 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007428}
Mike Stump11289f42009-09-09 15:08:12 +00007429
Douglas Gregora16548e2009-08-11 05:31:07 +00007430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007431ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007432TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7433 // Transform the callee.
7434 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7435 if (Callee.isInvalid())
7436 return ExprError();
7437
7438 // Transform exec config.
7439 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7440 if (EC.isInvalid())
7441 return ExprError();
7442
7443 // Transform arguments.
7444 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007445 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007446 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007447 &ArgChanged))
7448 return ExprError();
7449
7450 if (!getDerived().AlwaysRebuild() &&
7451 Callee.get() == E->getCallee() &&
7452 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007453 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007454
7455 // FIXME: Wrong source location information for the '('.
7456 SourceLocation FakeLParenLoc
7457 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7458 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007459 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007460 E->getRParenLoc(), EC.get());
7461}
7462
7463template<typename Derived>
7464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007465TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007466 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7467 if (!Type)
7468 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007469
John McCalldadc5752010-08-24 06:29:42 +00007470 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007471 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007473 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregora16548e2009-08-11 05:31:07 +00007475 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007476 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007477 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007478 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007479 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007480 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007481 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007482 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007483 E->getAngleBrackets().getEnd(),
7484 // FIXME. this should be '(' location
7485 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007486 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007487 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007488}
Mike Stump11289f42009-09-09 15:08:12 +00007489
Douglas Gregora16548e2009-08-11 05:31:07 +00007490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007492TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7493 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007494}
Mike Stump11289f42009-09-09 15:08:12 +00007495
7496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007498TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7499 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007500}
7501
Douglas Gregora16548e2009-08-11 05:31:07 +00007502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007503ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007504TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007505 CXXReinterpretCastExpr *E) {
7506 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007507}
Mike Stump11289f42009-09-09 15:08:12 +00007508
Douglas Gregora16548e2009-08-11 05:31:07 +00007509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007511TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7512 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007513}
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregora16548e2009-08-11 05:31:07 +00007515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007516ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007517TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007518 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007519 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7520 if (!Type)
7521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007522
John McCalldadc5752010-08-24 06:29:42 +00007523 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007524 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007527
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007529 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007531 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007532
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007533 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007534 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007535 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 E->getRParenLoc());
7537}
Mike Stump11289f42009-09-09 15:08:12 +00007538
Douglas Gregora16548e2009-08-11 05:31:07 +00007539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007541TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007543 TypeSourceInfo *TInfo
7544 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7545 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007549 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007550 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregor9da64192010-04-26 22:37:10 +00007552 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7553 E->getLocStart(),
7554 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 E->getLocEnd());
7556 }
Mike Stump11289f42009-09-09 15:08:12 +00007557
Eli Friedman456f0182012-01-20 01:26:23 +00007558 // We don't know whether the subexpression is potentially evaluated until
7559 // after we perform semantic analysis. We speculatively assume it is
7560 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007561 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7563 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007564
John McCalldadc5752010-08-24 06:29:42 +00007565 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 if (!getDerived().AlwaysRebuild() &&
7570 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007571 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007572
Douglas Gregor9da64192010-04-26 22:37:10 +00007573 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7574 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007575 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 E->getLocEnd());
7577}
7578
7579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007580ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007581TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7582 if (E->isTypeOperand()) {
7583 TypeSourceInfo *TInfo
7584 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7585 if (!TInfo)
7586 return ExprError();
7587
7588 if (!getDerived().AlwaysRebuild() &&
7589 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007591
Douglas Gregor69735112011-03-06 17:40:41 +00007592 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007593 E->getLocStart(),
7594 TInfo,
7595 E->getLocEnd());
7596 }
7597
Francois Pichet9f4f2072010-09-08 12:20:18 +00007598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7599
7600 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7601 if (SubExpr.isInvalid())
7602 return ExprError();
7603
7604 if (!getDerived().AlwaysRebuild() &&
7605 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007606 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007607
7608 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7609 E->getLocStart(),
7610 SubExpr.get(),
7611 E->getLocEnd());
7612}
7613
7614template<typename Derived>
7615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007616TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007617 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007618}
Mike Stump11289f42009-09-09 15:08:12 +00007619
Douglas Gregora16548e2009-08-11 05:31:07 +00007620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007621ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007622TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007623 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007624 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007625}
Mike Stump11289f42009-09-09 15:08:12 +00007626
Douglas Gregora16548e2009-08-11 05:31:07 +00007627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007629TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007630 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007631
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007632 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7633 // Make sure that we capture 'this'.
7634 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007635 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007637
Douglas Gregorb15af892010-01-07 23:12:05 +00007638 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007639}
Mike Stump11289f42009-09-09 15:08:12 +00007640
Douglas Gregora16548e2009-08-11 05:31:07 +00007641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007643TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007644 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007645 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007647
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 if (!getDerived().AlwaysRebuild() &&
7649 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007650 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007651
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007652 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7653 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007654}
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007658TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007659 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007660 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7661 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007663 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007664
Chandler Carruth794da4c2010-02-08 06:42:49 +00007665 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007667 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007668
Douglas Gregor033f6752009-12-23 23:03:06 +00007669 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007670}
Mike Stump11289f42009-09-09 15:08:12 +00007671
Douglas Gregora16548e2009-08-11 05:31:07 +00007672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007673ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007674TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7675 FieldDecl *Field
7676 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7677 E->getField()));
7678 if (!Field)
7679 return ExprError();
7680
7681 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007682 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007683
7684 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7685}
7686
7687template<typename Derived>
7688ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007689TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7690 CXXScalarValueInitExpr *E) {
7691 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7692 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007693 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007694
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007696 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007697 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007698
Chad Rosier1dcde962012-08-08 18:46:20 +00007699 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007700 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007701 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007706TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007707 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007708 TypeSourceInfo *AllocTypeInfo
7709 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7710 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007712
Douglas Gregora16548e2009-08-11 05:31:07 +00007713 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007714 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 // Transform the placement arguments (if any).
7719 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007720 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007721 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007722 E->getNumPlacementArgs(), true,
7723 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007724 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007725
Sebastian Redl6047f072012-02-16 12:22:20 +00007726 // Transform the initializer (if any).
7727 Expr *OldInit = E->getInitializer();
7728 ExprResult NewInit;
7729 if (OldInit)
7730 NewInit = getDerived().TransformExpr(OldInit);
7731 if (NewInit.isInvalid())
7732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007733
Sebastian Redl6047f072012-02-16 12:22:20 +00007734 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007735 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007736 if (E->getOperatorNew()) {
7737 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007738 getDerived().TransformDecl(E->getLocStart(),
7739 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007740 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007741 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007742 }
7743
Craig Topperc3ec1492014-05-26 06:22:03 +00007744 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007745 if (E->getOperatorDelete()) {
7746 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007747 getDerived().TransformDecl(E->getLocStart(),
7748 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007749 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007750 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007752
Douglas Gregora16548e2009-08-11 05:31:07 +00007753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007754 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007755 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007756 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007757 OperatorNew == E->getOperatorNew() &&
7758 OperatorDelete == E->getOperatorDelete() &&
7759 !ArgumentChanged) {
7760 // Mark any declarations we need as referenced.
7761 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007762 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007763 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007764 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007765 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007766
Sebastian Redl6047f072012-02-16 12:22:20 +00007767 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007768 QualType ElementType
7769 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7770 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7771 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7772 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007773 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007774 }
7775 }
7776 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007777
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007778 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007779 }
Mike Stump11289f42009-09-09 15:08:12 +00007780
Douglas Gregor0744ef62010-09-07 21:49:58 +00007781 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007782 if (!ArraySize.get()) {
7783 // If no array size was specified, but the new expression was
7784 // instantiated with an array type (e.g., "new T" where T is
7785 // instantiated with "int[4]"), extract the outer bound from the
7786 // array type as our array size. We do this with constant and
7787 // dependently-sized array types.
7788 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7789 if (!ArrayT) {
7790 // Do nothing
7791 } else if (const ConstantArrayType *ConsArrayT
7792 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007793 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7794 SemaRef.Context.getSizeType(),
7795 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007796 AllocType = ConsArrayT->getElementType();
7797 } else if (const DependentSizedArrayType *DepArrayT
7798 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7799 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007800 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007801 AllocType = DepArrayT->getElementType();
7802 }
7803 }
7804 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007805
Douglas Gregora16548e2009-08-11 05:31:07 +00007806 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7807 E->isGlobalNew(),
7808 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007809 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007810 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007811 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007813 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007814 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007815 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007816 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007817}
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregora16548e2009-08-11 05:31:07 +00007819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007822 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregord2d9da02010-02-26 00:38:10 +00007826 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007827 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007828 if (E->getOperatorDelete()) {
7829 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007830 getDerived().TransformDecl(E->getLocStart(),
7831 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007832 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007833 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007834 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007835
Douglas Gregora16548e2009-08-11 05:31:07 +00007836 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007837 Operand.get() == E->getArgument() &&
7838 OperatorDelete == E->getOperatorDelete()) {
7839 // Mark any declarations we need as referenced.
7840 // FIXME: instantiation-specific.
7841 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007842 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007843
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007844 if (!E->getArgument()->isTypeDependent()) {
7845 QualType Destroyed = SemaRef.Context.getBaseElementType(
7846 E->getDestroyedType());
7847 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7848 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007849 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007850 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007851 }
7852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007853
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007854 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007855 }
Mike Stump11289f42009-09-09 15:08:12 +00007856
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7858 E->isGlobalDelete(),
7859 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007860 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007861}
Mike Stump11289f42009-09-09 15:08:12 +00007862
Douglas Gregora16548e2009-08-11 05:31:07 +00007863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007864ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007865TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007866 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007867 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007868 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007870
John McCallba7bf592010-08-24 05:47:05 +00007871 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007872 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007873 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007874 E->getOperatorLoc(),
7875 E->isArrow()? tok::arrow : tok::period,
7876 ObjectTypePtr,
7877 MayBePseudoDestructor);
7878 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007879 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007880
John McCallba7bf592010-08-24 05:47:05 +00007881 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007882 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7883 if (QualifierLoc) {
7884 QualifierLoc
7885 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7886 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007887 return ExprError();
7888 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007889 CXXScopeSpec SS;
7890 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007891
Douglas Gregor678f90d2010-02-25 01:56:36 +00007892 PseudoDestructorTypeStorage Destroyed;
7893 if (E->getDestroyedTypeInfo()) {
7894 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007895 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007896 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007897 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007899 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007900 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007901 // We aren't likely to be able to resolve the identifier down to a type
7902 // now anyway, so just retain the identifier.
7903 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7904 E->getDestroyedTypeLoc());
7905 } else {
7906 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007907 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007908 *E->getDestroyedTypeIdentifier(),
7909 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007910 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007911 SS, ObjectTypePtr,
7912 false);
7913 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007914 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007915
Douglas Gregor678f90d2010-02-25 01:56:36 +00007916 Destroyed
7917 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7918 E->getDestroyedTypeLoc());
7919 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007920
Craig Topperc3ec1492014-05-26 06:22:03 +00007921 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007922 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007923 CXXScopeSpec EmptySS;
7924 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007925 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007926 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007927 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007929
John McCallb268a282010-08-23 23:25:46 +00007930 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007931 E->getOperatorLoc(),
7932 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007933 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007934 ScopeTypeInfo,
7935 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007936 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007937 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007938}
Mike Stump11289f42009-09-09 15:08:12 +00007939
Douglas Gregorad8a3362009-09-04 17:36:40 +00007940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007941ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007942TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007943 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007944 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7945 Sema::LookupOrdinaryName);
7946
7947 // Transform all the decls.
7948 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7949 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007950 NamedDecl *InstD = static_cast<NamedDecl*>(
7951 getDerived().TransformDecl(Old->getNameLoc(),
7952 *I));
John McCall84d87672009-12-10 09:41:52 +00007953 if (!InstD) {
7954 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7955 // This can happen because of dependent hiding.
7956 if (isa<UsingShadowDecl>(*I))
7957 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007958 else {
7959 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007960 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007961 }
John McCall84d87672009-12-10 09:41:52 +00007962 }
John McCalle66edc12009-11-24 19:00:30 +00007963
7964 // Expand using declarations.
7965 if (isa<UsingDecl>(InstD)) {
7966 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007967 for (auto *I : UD->shadows())
7968 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007969 continue;
7970 }
7971
7972 R.addDecl(InstD);
7973 }
7974
7975 // Resolve a kind, but don't do any further analysis. If it's
7976 // ambiguous, the callee needs to deal with it.
7977 R.resolveKind();
7978
7979 // Rebuild the nested-name qualifier, if present.
7980 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007981 if (Old->getQualifierLoc()) {
7982 NestedNameSpecifierLoc QualifierLoc
7983 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7984 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007985 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007986
Douglas Gregor0da1d432011-02-28 20:01:57 +00007987 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007988 }
7989
Douglas Gregor9262f472010-04-27 18:19:34 +00007990 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007991 CXXRecordDecl *NamingClass
7992 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7993 Old->getNameLoc(),
7994 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007995 if (!NamingClass) {
7996 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007997 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007999
Douglas Gregorda7be082010-04-27 16:10:10 +00008000 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008001 }
8002
Abramo Bagnara7945c982012-01-27 09:46:47 +00008003 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8004
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008005 // If we have neither explicit template arguments, nor the template keyword,
8006 // it's a normal declaration name.
8007 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008008 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8009
8010 // If we have template arguments, rebuild them, then rebuild the
8011 // templateid expression.
8012 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008013 if (Old->hasExplicitTemplateArgs() &&
8014 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008015 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008016 TransArgs)) {
8017 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008018 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008019 }
John McCalle66edc12009-11-24 19:00:30 +00008020
Abramo Bagnara7945c982012-01-27 09:46:47 +00008021 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008022 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008023}
Mike Stump11289f42009-09-09 15:08:12 +00008024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008026ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008027TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8028 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008029 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008030 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8031 TypeSourceInfo *From = E->getArg(I);
8032 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008033 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008034 TypeLocBuilder TLB;
8035 TLB.reserve(FromTL.getFullDataSize());
8036 QualType To = getDerived().TransformType(TLB, FromTL);
8037 if (To.isNull())
8038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008039
Douglas Gregor29c42f22012-02-24 07:38:34 +00008040 if (To == From->getType())
8041 Args.push_back(From);
8042 else {
8043 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8044 ArgChanged = true;
8045 }
8046 continue;
8047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008048
Douglas Gregor29c42f22012-02-24 07:38:34 +00008049 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008050
Douglas Gregor29c42f22012-02-24 07:38:34 +00008051 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008052 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008053 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8054 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8055 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008056
Douglas Gregor29c42f22012-02-24 07:38:34 +00008057 // Determine whether the set of unexpanded parameter packs can and should
8058 // be expanded.
8059 bool Expand = true;
8060 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008061 Optional<unsigned> OrigNumExpansions =
8062 ExpansionTL.getTypePtr()->getNumExpansions();
8063 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008064 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8065 PatternTL.getSourceRange(),
8066 Unexpanded,
8067 Expand, RetainExpansion,
8068 NumExpansions))
8069 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008070
Douglas Gregor29c42f22012-02-24 07:38:34 +00008071 if (!Expand) {
8072 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008073 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008074 // expansion.
8075 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008076
Douglas Gregor29c42f22012-02-24 07:38:34 +00008077 TypeLocBuilder TLB;
8078 TLB.reserve(From->getTypeLoc().getFullDataSize());
8079
8080 QualType To = getDerived().TransformType(TLB, PatternTL);
8081 if (To.isNull())
8082 return ExprError();
8083
Chad Rosier1dcde962012-08-08 18:46:20 +00008084 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008085 PatternTL.getSourceRange(),
8086 ExpansionTL.getEllipsisLoc(),
8087 NumExpansions);
8088 if (To.isNull())
8089 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008090
Douglas Gregor29c42f22012-02-24 07:38:34 +00008091 PackExpansionTypeLoc ToExpansionTL
8092 = TLB.push<PackExpansionTypeLoc>(To);
8093 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8094 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8095 continue;
8096 }
8097
8098 // Expand the pack expansion by substituting for each argument in the
8099 // pack(s).
8100 for (unsigned I = 0; I != *NumExpansions; ++I) {
8101 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8102 TypeLocBuilder TLB;
8103 TLB.reserve(PatternTL.getFullDataSize());
8104 QualType To = getDerived().TransformType(TLB, PatternTL);
8105 if (To.isNull())
8106 return ExprError();
8107
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008108 if (To->containsUnexpandedParameterPack()) {
8109 To = getDerived().RebuildPackExpansionType(To,
8110 PatternTL.getSourceRange(),
8111 ExpansionTL.getEllipsisLoc(),
8112 NumExpansions);
8113 if (To.isNull())
8114 return ExprError();
8115
8116 PackExpansionTypeLoc ToExpansionTL
8117 = TLB.push<PackExpansionTypeLoc>(To);
8118 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8119 }
8120
Douglas Gregor29c42f22012-02-24 07:38:34 +00008121 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008123
Douglas Gregor29c42f22012-02-24 07:38:34 +00008124 if (!RetainExpansion)
8125 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008126
Douglas Gregor29c42f22012-02-24 07:38:34 +00008127 // If we're supposed to retain a pack expansion, do so by temporarily
8128 // forgetting the partially-substituted parameter pack.
8129 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8130
8131 TypeLocBuilder TLB;
8132 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008133
Douglas Gregor29c42f22012-02-24 07:38:34 +00008134 QualType To = getDerived().TransformType(TLB, PatternTL);
8135 if (To.isNull())
8136 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008137
8138 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008139 PatternTL.getSourceRange(),
8140 ExpansionTL.getEllipsisLoc(),
8141 NumExpansions);
8142 if (To.isNull())
8143 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008144
Douglas Gregor29c42f22012-02-24 07:38:34 +00008145 PackExpansionTypeLoc ToExpansionTL
8146 = TLB.push<PackExpansionTypeLoc>(To);
8147 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8148 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008150
Douglas Gregor29c42f22012-02-24 07:38:34 +00008151 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008152 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008153
8154 return getDerived().RebuildTypeTrait(E->getTrait(),
8155 E->getLocStart(),
8156 Args,
8157 E->getLocEnd());
8158}
8159
8160template<typename Derived>
8161ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008162TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8163 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8164 if (!T)
8165 return ExprError();
8166
8167 if (!getDerived().AlwaysRebuild() &&
8168 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008169 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008170
8171 ExprResult SubExpr;
8172 {
8173 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8174 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8175 if (SubExpr.isInvalid())
8176 return ExprError();
8177
8178 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008179 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008180 }
8181
8182 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8183 E->getLocStart(),
8184 T,
8185 SubExpr.get(),
8186 E->getLocEnd());
8187}
8188
8189template<typename Derived>
8190ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008191TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8192 ExprResult SubExpr;
8193 {
8194 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8195 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8196 if (SubExpr.isInvalid())
8197 return ExprError();
8198
8199 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008200 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008201 }
8202
8203 return getDerived().RebuildExpressionTrait(
8204 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8205}
8206
8207template<typename Derived>
8208ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008209TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008210 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008211 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8212}
8213
8214template<typename Derived>
8215ExprResult
8216TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8217 DependentScopeDeclRefExpr *E,
8218 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008219 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008220 NestedNameSpecifierLoc QualifierLoc
8221 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8222 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008223 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008224 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008225
John McCall31f82722010-11-12 08:19:04 +00008226 // TODO: If this is a conversion-function-id, verify that the
8227 // destination type name (if present) resolves the same way after
8228 // instantiation as it did in the local scope.
8229
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008230 DeclarationNameInfo NameInfo
8231 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8232 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008234
John McCalle66edc12009-11-24 19:00:30 +00008235 if (!E->hasExplicitTemplateArgs()) {
8236 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008237 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008238 // Note: it is sufficient to compare the Name component of NameInfo:
8239 // if name has not changed, DNLoc has not changed either.
8240 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008241 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008242
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008243 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00008244 TemplateKWLoc,
8245 NameInfo,
8246 /*TemplateArgs*/nullptr,
8247 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008248 }
John McCall6b51f282009-11-23 01:53:49 +00008249
8250 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008251 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8252 E->getNumTemplateArgs(),
8253 TransArgs))
8254 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008255
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008256 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008257 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008258 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008259 &TransArgs,
8260 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008261}
8262
8263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008265TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008266 // CXXConstructExprs other than for list-initialization and
8267 // CXXTemporaryObjectExpr are always implicit, so when we have
8268 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008269 if ((E->getNumArgs() == 1 ||
8270 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008271 (!getDerived().DropCallArgument(E->getArg(0))) &&
8272 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008273 return getDerived().TransformExpr(E->getArg(0));
8274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8276
8277 QualType T = getDerived().TransformType(E->getType());
8278 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008279 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008280
8281 CXXConstructorDecl *Constructor
8282 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008283 getDerived().TransformDecl(E->getLocStart(),
8284 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008285 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008289 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008290 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008291 &ArgumentChanged))
8292 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008293
Douglas Gregora16548e2009-08-11 05:31:07 +00008294 if (!getDerived().AlwaysRebuild() &&
8295 T == E->getType() &&
8296 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008297 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008298 // Mark the constructor as referenced.
8299 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008300 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008301 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008302 }
Mike Stump11289f42009-09-09 15:08:12 +00008303
Douglas Gregordb121ba2009-12-14 16:27:04 +00008304 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8305 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008306 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008307 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008308 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008309 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008310 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008311 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008312}
Mike Stump11289f42009-09-09 15:08:12 +00008313
Douglas Gregora16548e2009-08-11 05:31:07 +00008314/// \brief Transform a C++ temporary-binding expression.
8315///
Douglas Gregor363b1512009-12-24 18:51:59 +00008316/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8317/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008320TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008321 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008322}
Mike Stump11289f42009-09-09 15:08:12 +00008323
John McCall5d413782010-12-06 08:20:24 +00008324/// \brief Transform a C++ expression that contains cleanups that should
8325/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008326///
John McCall5d413782010-12-06 08:20:24 +00008327/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008328/// just 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 McCall5d413782010-12-06 08:20:24 +00008331TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *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
Douglas Gregora16548e2009-08-11 05:31:07 +00008335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008336ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008337TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008338 CXXTemporaryObjectExpr *E) {
8339 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8340 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008342
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 CXXConstructorDecl *Constructor
8344 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008345 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008346 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008347 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008351 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008352 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008353 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008354 &ArgumentChanged))
8355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008358 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008359 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008360 !ArgumentChanged) {
8361 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008362 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008363 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008365
Richard Smithd59b8322012-12-19 01:39:02 +00008366 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008367 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8368 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008369 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 E->getLocEnd());
8371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008374ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008375TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008376
8377 // Transform any init-capture expressions before entering the scope of the
8378 // lambda body, because they are not semantically within that scope.
8379 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8380 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8381 E->explicit_capture_begin());
8382
8383 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8384 CEnd = E->capture_end();
8385 C != CEnd; ++C) {
8386 if (!C->isInitCapture())
8387 continue;
8388 EnterExpressionEvaluationContext EEEC(getSema(),
8389 Sema::PotentiallyEvaluated);
8390 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8391 C->getCapturedVar()->getInit(),
8392 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8393
8394 if (NewExprInitResult.isInvalid())
8395 return ExprError();
8396 Expr *NewExprInit = NewExprInitResult.get();
8397
8398 VarDecl *OldVD = C->getCapturedVar();
8399 QualType NewInitCaptureType =
8400 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8401 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8402 NewExprInit);
8403 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008404 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8405 std::make_pair(NewExprInitResult, NewInitCaptureType);
8406
8407 }
8408
Faisal Vali524ca282013-11-12 01:40:44 +00008409 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008410 // Transform the template parameters, and add them to the current
8411 // instantiation scope. The null case is handled correctly.
8412 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8413 E->getTemplateParameterList());
8414
8415 // Check to see if the TypeSourceInfo of the call operator needs to
8416 // be transformed, and if so do the transformation in the
8417 // CurrentInstantiationScope.
8418
8419 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8420 FunctionProtoTypeLoc OldCallOpFPTL =
8421 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008422 TypeSourceInfo *NewCallOpTSI = nullptr;
8423
Faisal Vali2cba1332013-10-23 06:44:28 +00008424 const bool CallOpWasAlreadyTransformed =
8425 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8426
8427 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8428 if (CallOpWasAlreadyTransformed)
8429 NewCallOpTSI = OldCallOpTSI;
8430 else {
8431 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8432 // The transformation MUST be done in the CurrentInstantiationScope since
8433 // it introduces a mapping of the original to the newly created
8434 // transformed parameters.
8435
8436 TypeLocBuilder NewCallOpTLBuilder;
8437 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8438 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008439 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008440 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8441 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008442 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008443 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8444 // the vector below - this will be used to synthesize the
8445 // NewCallOperator. Additionally, add the parameters of the untransformed
8446 // lambda call operator to the CurrentInstantiationScope.
8447 SmallVector<ParmVarDecl *, 4> Params;
8448 {
8449 FunctionProtoTypeLoc NewCallOpFPTL =
8450 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8451 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008452 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008453
8454 for (unsigned I = 0; I < NewNumArgs; ++I) {
8455 // If this call operator's type does not require transformation,
8456 // the parameters do not get added to the current instantiation scope,
8457 // - so ADD them! This allows the following to compile when the enclosing
8458 // template is specialized and the entire lambda expression has to be
8459 // transformed.
8460 // template<class T> void foo(T t) {
8461 // auto L = [](auto a) {
8462 // auto M = [](char b) { <-- note: non-generic lambda
8463 // auto N = [](auto c) {
8464 // int x = sizeof(a);
8465 // x = sizeof(b); <-- specifically this line
8466 // x = sizeof(c);
8467 // };
8468 // };
8469 // };
8470 // }
8471 // foo('a')
8472 if (CallOpWasAlreadyTransformed)
8473 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8474 NewParamDeclArray[I]);
8475 // Add to Params array, so these parameters can be used to create
8476 // the newly transformed call operator.
8477 Params.push_back(NewParamDeclArray[I]);
8478 }
8479 }
8480
8481 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008482 return ExprError();
8483
Eli Friedmand564afb2012-09-19 01:18:11 +00008484 // Create the local class that will describe the lambda.
8485 CXXRecordDecl *Class
8486 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008487 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008488 /*KnownDependent=*/false,
8489 E->getCaptureDefault());
8490
Eli Friedmand564afb2012-09-19 01:18:11 +00008491 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8492
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008493 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008494 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008495 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008496 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008497 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008498 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008499 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008500
Faisal Vali2cba1332013-10-23 06:44:28 +00008501 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8502
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008503 return getDerived().TransformLambdaScope(E, NewCallOperator,
8504 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008505}
8506
8507template<typename Derived>
8508ExprResult
8509TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008510 CXXMethodDecl *CallOperator,
8511 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008512 bool Invalid = false;
8513
Douglas Gregorb4328232012-02-14 00:00:48 +00008514 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008515 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8516 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008517
Faisal Vali2b391ab2013-09-26 19:54:12 +00008518 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008519 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008520 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008521 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008522 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008523 E->hasExplicitParameters(),
8524 E->hasExplicitResultType(),
8525 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008526
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008527 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008528 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008529 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008530 CEnd = E->capture_end();
8531 C != CEnd; ++C) {
8532 // When we hit the first implicit capture, tell Sema that we've finished
8533 // the list of explicit captures.
8534 if (!FinishedExplicitCaptures && C->isImplicit()) {
8535 getSema().finishLambdaExplicitCaptures(LSI);
8536 FinishedExplicitCaptures = true;
8537 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008538
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008539 // Capturing 'this' is trivial.
8540 if (C->capturesThis()) {
8541 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8542 continue;
8543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008544
Richard Smithba71c082013-05-16 06:20:58 +00008545 // Rebuild init-captures, including the implied field declaration.
8546 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008547
8548 InitCaptureInfoTy InitExprTypePair =
8549 InitCaptureExprsAndTypes[C - E->capture_begin()];
8550 ExprResult Init = InitExprTypePair.first;
8551 QualType InitQualType = InitExprTypePair.second;
8552 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008553 Invalid = true;
8554 continue;
8555 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008556 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008557 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8558 OldVD->getLocation(), InitExprTypePair.second,
8559 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008560 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008561 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008562 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008563 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008564 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008565 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008566 continue;
8567 }
8568
8569 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8570
Douglas Gregor3e308b12012-02-14 19:27:52 +00008571 // Determine the capture kind for Sema.
8572 Sema::TryCaptureKind Kind
8573 = C->isImplicit()? Sema::TryCapture_Implicit
8574 : C->getCaptureKind() == LCK_ByCopy
8575 ? Sema::TryCapture_ExplicitByVal
8576 : Sema::TryCapture_ExplicitByRef;
8577 SourceLocation EllipsisLoc;
8578 if (C->isPackExpansion()) {
8579 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8580 bool ShouldExpand = false;
8581 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008582 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008583 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8584 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008585 Unexpanded,
8586 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008587 NumExpansions)) {
8588 Invalid = true;
8589 continue;
8590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008591
Douglas Gregor3e308b12012-02-14 19:27:52 +00008592 if (ShouldExpand) {
8593 // The transform has determined that we should perform an expansion;
8594 // transform and capture each of the arguments.
8595 // expansion of the pattern. Do so.
8596 VarDecl *Pack = C->getCapturedVar();
8597 for (unsigned I = 0; I != *NumExpansions; ++I) {
8598 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8599 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008600 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008601 Pack));
8602 if (!CapturedVar) {
8603 Invalid = true;
8604 continue;
8605 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008606
Douglas Gregor3e308b12012-02-14 19:27:52 +00008607 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008608 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8609 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008610 continue;
8611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008612
Douglas Gregor3e308b12012-02-14 19:27:52 +00008613 EllipsisLoc = C->getEllipsisLoc();
8614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008615
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008616 // Transform the captured variable.
8617 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008618 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008619 C->getCapturedVar()));
8620 if (!CapturedVar) {
8621 Invalid = true;
8622 continue;
8623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008624
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008625 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008626 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008627 }
8628 if (!FinishedExplicitCaptures)
8629 getSema().finishLambdaExplicitCaptures(LSI);
8630
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008631
8632 // Enter a new evaluation context to insulate the lambda from any
8633 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008634 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008635
8636 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008637 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008638 /*IsInstantiation=*/true);
8639 return ExprError();
8640 }
8641
8642 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008643 StmtResult Body = getDerived().TransformStmt(E->getBody());
8644 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008645 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008646 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008647 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008648 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008649
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008650 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008651 /*CurScope=*/nullptr,
8652 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008653}
8654
8655template<typename Derived>
8656ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008657TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008658 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008659 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8660 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008662
Douglas Gregora16548e2009-08-11 05:31:07 +00008663 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008664 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008665 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008666 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008667 &ArgumentChanged))
8668 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008669
Douglas Gregora16548e2009-08-11 05:31:07 +00008670 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008671 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008673 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008676 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008678 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 E->getRParenLoc());
8680}
Mike Stump11289f42009-09-09 15:08:12 +00008681
Douglas Gregora16548e2009-08-11 05:31:07 +00008682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008683ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008684TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008685 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008687 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008688 Expr *OldBase;
8689 QualType BaseType;
8690 QualType ObjectType;
8691 if (!E->isImplicitAccess()) {
8692 OldBase = E->getBase();
8693 Base = getDerived().TransformExpr(OldBase);
8694 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008696
John McCall2d74de92009-12-01 22:10:20 +00008697 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008698 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008699 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008700 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008701 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008702 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008703 ObjectTy,
8704 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008705 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008706 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008707
John McCallba7bf592010-08-24 05:47:05 +00008708 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008709 BaseType = ((Expr*) Base.get())->getType();
8710 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008711 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008712 BaseType = getDerived().TransformType(E->getBaseType());
8713 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8714 }
Mike Stump11289f42009-09-09 15:08:12 +00008715
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008716 // Transform the first part of the nested-name-specifier that qualifies
8717 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008718 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008719 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008720 E->getFirstQualifierFoundInScope(),
8721 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008722
Douglas Gregore16af532011-02-28 18:50:33 +00008723 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008724 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008725 QualifierLoc
8726 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8727 ObjectType,
8728 FirstQualifierInScope);
8729 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008730 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008731 }
Mike Stump11289f42009-09-09 15:08:12 +00008732
Abramo Bagnara7945c982012-01-27 09:46:47 +00008733 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8734
John McCall31f82722010-11-12 08:19:04 +00008735 // TODO: If this is a conversion-function-id, verify that the
8736 // destination type name (if present) resolves the same way after
8737 // instantiation as it did in the local scope.
8738
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008739 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008740 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008741 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008743
John McCall2d74de92009-12-01 22:10:20 +00008744 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008745 // This is a reference to a member without an explicitly-specified
8746 // template argument list. Optimize for this common case.
8747 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008748 Base.get() == OldBase &&
8749 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008750 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008751 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008752 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008753 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008754
John McCallb268a282010-08-23 23:25:46 +00008755 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008756 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008757 E->isArrow(),
8758 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008759 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008760 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008761 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008762 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008763 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008764 }
8765
John McCall6b51f282009-11-23 01:53:49 +00008766 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008767 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8768 E->getNumTemplateArgs(),
8769 TransArgs))
8770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008771
John McCallb268a282010-08-23 23:25:46 +00008772 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008773 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008774 E->isArrow(),
8775 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008776 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008777 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008778 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008779 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008780 &TransArgs);
8781}
8782
8783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008786 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008787 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008788 QualType BaseType;
8789 if (!Old->isImplicitAccess()) {
8790 Base = getDerived().TransformExpr(Old->getBase());
8791 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008792 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008793 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008794 Old->isArrow());
8795 if (Base.isInvalid())
8796 return ExprError();
8797 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008798 } else {
8799 BaseType = getDerived().TransformType(Old->getBaseType());
8800 }
John McCall10eae182009-11-30 22:42:35 +00008801
Douglas Gregor0da1d432011-02-28 20:01:57 +00008802 NestedNameSpecifierLoc QualifierLoc;
8803 if (Old->getQualifierLoc()) {
8804 QualifierLoc
8805 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8806 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008807 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008808 }
8809
Abramo Bagnara7945c982012-01-27 09:46:47 +00008810 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8811
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008812 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008813 Sema::LookupOrdinaryName);
8814
8815 // Transform all the decls.
8816 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8817 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008818 NamedDecl *InstD = static_cast<NamedDecl*>(
8819 getDerived().TransformDecl(Old->getMemberLoc(),
8820 *I));
John McCall84d87672009-12-10 09:41:52 +00008821 if (!InstD) {
8822 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8823 // This can happen because of dependent hiding.
8824 if (isa<UsingShadowDecl>(*I))
8825 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008826 else {
8827 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008828 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008829 }
John McCall84d87672009-12-10 09:41:52 +00008830 }
John McCall10eae182009-11-30 22:42:35 +00008831
8832 // Expand using declarations.
8833 if (isa<UsingDecl>(InstD)) {
8834 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008835 for (auto *I : UD->shadows())
8836 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008837 continue;
8838 }
8839
8840 R.addDecl(InstD);
8841 }
8842
8843 R.resolveKind();
8844
Douglas Gregor9262f472010-04-27 18:19:34 +00008845 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008846 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008847 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008848 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008849 Old->getMemberLoc(),
8850 Old->getNamingClass()));
8851 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008852 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008853
Douglas Gregorda7be082010-04-27 16:10:10 +00008854 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008856
John McCall10eae182009-11-30 22:42:35 +00008857 TemplateArgumentListInfo TransArgs;
8858 if (Old->hasExplicitTemplateArgs()) {
8859 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8860 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008861 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8862 Old->getNumTemplateArgs(),
8863 TransArgs))
8864 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008865 }
John McCall38836f02010-01-15 08:34:02 +00008866
8867 // FIXME: to do this check properly, we will need to preserve the
8868 // first-qualifier-in-scope here, just in case we had a dependent
8869 // base (and therefore couldn't do the check) and a
8870 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008871 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008872
John McCallb268a282010-08-23 23:25:46 +00008873 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008874 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008875 Old->getOperatorLoc(),
8876 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008877 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008878 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008879 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008880 R,
8881 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008882 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008883}
8884
8885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008886ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008887TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008888 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008889 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8890 if (SubExpr.isInvalid())
8891 return ExprError();
8892
8893 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008894 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008895
8896 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8897}
8898
8899template<typename Derived>
8900ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008901TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008902 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8903 if (Pattern.isInvalid())
8904 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008906 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008907 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008908
Douglas Gregorb8840002011-01-14 21:20:45 +00008909 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8910 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008911}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008912
8913template<typename Derived>
8914ExprResult
8915TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8916 // If E is not value-dependent, then nothing will change when we transform it.
8917 // Note: This is an instantiation-centric view.
8918 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008919 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008920
8921 // Note: None of the implementations of TryExpandParameterPacks can ever
8922 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008923 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008924 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8925 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008926 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008927 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008928 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008929 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008930 ShouldExpand, RetainExpansion,
8931 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008932 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008933
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008934 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008935 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008936
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008937 NamedDecl *Pack = E->getPack();
8938 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008939 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008940 Pack));
8941 if (!Pack)
8942 return ExprError();
8943 }
8944
Chad Rosier1dcde962012-08-08 18:46:20 +00008945
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008946 // We now know the length of the parameter pack, so build a new expression
8947 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008948 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8949 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008950 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008951}
8952
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008953template<typename Derived>
8954ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008955TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8956 SubstNonTypeTemplateParmPackExpr *E) {
8957 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008958 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008959}
8960
8961template<typename Derived>
8962ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008963TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8964 SubstNonTypeTemplateParmExpr *E) {
8965 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008966 return E;
John McCall7c454bb2011-07-15 05:09:51 +00008967}
8968
8969template<typename Derived>
8970ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008971TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8972 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008973 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00008974}
8975
8976template<typename Derived>
8977ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008978TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8979 MaterializeTemporaryExpr *E) {
8980 return getDerived().TransformExpr(E->GetTemporaryExpr());
8981}
Chad Rosier1dcde962012-08-08 18:46:20 +00008982
Douglas Gregorfe314812011-06-21 17:03:29 +00008983template<typename Derived>
8984ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008985TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8986 CXXStdInitializerListExpr *E) {
8987 return getDerived().TransformExpr(E->getSubExpr());
8988}
8989
8990template<typename Derived>
8991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008992TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008993 return SemaRef.MaybeBindToTemporary(E);
8994}
8995
8996template<typename Derived>
8997ExprResult
8998TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008999 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009000}
9001
9002template<typename Derived>
9003ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009004TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9005 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9006 if (SubExpr.isInvalid())
9007 return ExprError();
9008
9009 if (!getDerived().AlwaysRebuild() &&
9010 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009011 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009012
9013 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009014}
9015
9016template<typename Derived>
9017ExprResult
9018TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9019 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009020 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009021 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009022 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009023 /*IsCall=*/false, Elements, &ArgChanged))
9024 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009025
Ted Kremeneke65b0862012-03-06 20:05:56 +00009026 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9027 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009028
Ted Kremeneke65b0862012-03-06 20:05:56 +00009029 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9030 Elements.data(),
9031 Elements.size());
9032}
9033
9034template<typename Derived>
9035ExprResult
9036TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009037 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009038 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009039 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009040 bool ArgChanged = false;
9041 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9042 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009043
Ted Kremeneke65b0862012-03-06 20:05:56 +00009044 if (OrigElement.isPackExpansion()) {
9045 // This key/value element is a pack expansion.
9046 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9047 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9048 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9049 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9050
9051 // Determine whether the set of unexpanded parameter packs can
9052 // and should be expanded.
9053 bool Expand = true;
9054 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009055 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9056 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009057 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9058 OrigElement.Value->getLocEnd());
9059 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9060 PatternRange,
9061 Unexpanded,
9062 Expand, RetainExpansion,
9063 NumExpansions))
9064 return ExprError();
9065
9066 if (!Expand) {
9067 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009069 // expansion.
9070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9071 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9072 if (Key.isInvalid())
9073 return ExprError();
9074
9075 if (Key.get() != OrigElement.Key)
9076 ArgChanged = true;
9077
9078 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9079 if (Value.isInvalid())
9080 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009081
Ted Kremeneke65b0862012-03-06 20:05:56 +00009082 if (Value.get() != OrigElement.Value)
9083 ArgChanged = true;
9084
Chad Rosier1dcde962012-08-08 18:46:20 +00009085 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009086 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9087 };
9088 Elements.push_back(Expansion);
9089 continue;
9090 }
9091
9092 // Record right away that the argument was changed. This needs
9093 // to happen even if the array expands to nothing.
9094 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
Ted Kremeneke65b0862012-03-06 20:05:56 +00009096 // The transform has determined that we should perform an elementwise
9097 // expansion of the pattern. Do so.
9098 for (unsigned I = 0; I != *NumExpansions; ++I) {
9099 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9100 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9101 if (Key.isInvalid())
9102 return ExprError();
9103
9104 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9105 if (Value.isInvalid())
9106 return ExprError();
9107
Chad Rosier1dcde962012-08-08 18:46:20 +00009108 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009109 Key.get(), Value.get(), SourceLocation(), NumExpansions
9110 };
9111
9112 // If any unexpanded parameter packs remain, we still have a
9113 // pack expansion.
9114 if (Key.get()->containsUnexpandedParameterPack() ||
9115 Value.get()->containsUnexpandedParameterPack())
9116 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009117
Ted Kremeneke65b0862012-03-06 20:05:56 +00009118 Elements.push_back(Element);
9119 }
9120
9121 // We've finished with this pack expansion.
9122 continue;
9123 }
9124
9125 // Transform and check key.
9126 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9127 if (Key.isInvalid())
9128 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009129
Ted Kremeneke65b0862012-03-06 20:05:56 +00009130 if (Key.get() != OrigElement.Key)
9131 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009132
Ted Kremeneke65b0862012-03-06 20:05:56 +00009133 // Transform and check value.
9134 ExprResult Value
9135 = getDerived().TransformExpr(OrigElement.Value);
9136 if (Value.isInvalid())
9137 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009138
Ted Kremeneke65b0862012-03-06 20:05:56 +00009139 if (Value.get() != OrigElement.Value)
9140 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009141
9142 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009143 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009144 };
9145 Elements.push_back(Element);
9146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009147
Ted Kremeneke65b0862012-03-06 20:05:56 +00009148 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9149 return SemaRef.MaybeBindToTemporary(E);
9150
9151 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9152 Elements.data(),
9153 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009154}
9155
Mike Stump11289f42009-09-09 15:08:12 +00009156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009158TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009159 TypeSourceInfo *EncodedTypeInfo
9160 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9161 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009163
Douglas Gregora16548e2009-08-11 05:31:07 +00009164 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009165 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009166 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009167
9168 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009169 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 E->getRParenLoc());
9171}
Mike Stump11289f42009-09-09 15:08:12 +00009172
Douglas Gregora16548e2009-08-11 05:31:07 +00009173template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009174ExprResult TreeTransform<Derived>::
9175TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009176 // This is a kind of implicit conversion, and it needs to get dropped
9177 // and recomputed for the same general reasons that ImplicitCastExprs
9178 // do, as well a more specific one: this expression is only valid when
9179 // it appears *immediately* as an argument expression.
9180 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009181}
9182
9183template<typename Derived>
9184ExprResult TreeTransform<Derived>::
9185TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009186 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009187 = getDerived().TransformType(E->getTypeInfoAsWritten());
9188 if (!TSInfo)
9189 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009190
John McCall31168b02011-06-15 23:02:42 +00009191 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009192 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009194
John McCall31168b02011-06-15 23:02:42 +00009195 if (!getDerived().AlwaysRebuild() &&
9196 TSInfo == E->getTypeInfoAsWritten() &&
9197 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009198 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
John McCall31168b02011-06-15 23:02:42 +00009200 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009201 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009202 Result.get());
9203}
9204
9205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009207TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009208 // Transform arguments.
9209 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009210 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009211 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009212 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009213 &ArgChanged))
9214 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009215
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009216 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9217 // Class message: transform the receiver type.
9218 TypeSourceInfo *ReceiverTypeInfo
9219 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9220 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009221 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009222
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009223 // If nothing changed, just retain the existing message send.
9224 if (!getDerived().AlwaysRebuild() &&
9225 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009226 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009227
9228 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009229 SmallVector<SourceLocation, 16> SelLocs;
9230 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009231 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9232 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009233 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009234 E->getMethodDecl(),
9235 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009236 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009237 E->getRightLoc());
9238 }
9239
9240 // Instance message: transform the receiver
9241 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9242 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009243 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009244 = getDerived().TransformExpr(E->getInstanceReceiver());
9245 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009246 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009247
9248 // If nothing changed, just retain the existing message send.
9249 if (!getDerived().AlwaysRebuild() &&
9250 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009251 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009252
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009253 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009254 SmallVector<SourceLocation, 16> SelLocs;
9255 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009256 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009257 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009258 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009259 E->getMethodDecl(),
9260 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009261 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009262 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009263}
9264
Mike Stump11289f42009-09-09 15:08:12 +00009265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009267TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009268 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009269}
9270
Mike Stump11289f42009-09-09 15:08:12 +00009271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009273TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009274 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009275}
9276
Mike Stump11289f42009-09-09 15:08:12 +00009277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009279TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009280 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009281 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009282 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009283 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009284
9285 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009286
Douglas Gregord51d90d2010-04-26 20:11:03 +00009287 // If nothing changed, just retain the existing expression.
9288 if (!getDerived().AlwaysRebuild() &&
9289 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009290 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009291
John McCallb268a282010-08-23 23:25:46 +00009292 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009293 E->getLocation(),
9294 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009295}
9296
Mike Stump11289f42009-09-09 15:08:12 +00009297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009299TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009300 // 'super' and types never change. Property never changes. Just
9301 // retain the existing expression.
9302 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009303 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009304
Douglas Gregor9faee212010-04-26 20:47:02 +00009305 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009306 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009307 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009309
Douglas Gregor9faee212010-04-26 20:47:02 +00009310 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Douglas Gregor9faee212010-04-26 20:47:02 +00009312 // If nothing changed, just retain the existing expression.
9313 if (!getDerived().AlwaysRebuild() &&
9314 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009315 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009316
John McCallb7bd14f2010-12-02 01:19:52 +00009317 if (E->isExplicitProperty())
9318 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9319 E->getExplicitProperty(),
9320 E->getLocation());
9321
9322 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009323 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009324 E->getImplicitPropertyGetter(),
9325 E->getImplicitPropertySetter(),
9326 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009327}
9328
Mike Stump11289f42009-09-09 15:08:12 +00009329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009330ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009331TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9332 // Transform the base expression.
9333 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9334 if (Base.isInvalid())
9335 return ExprError();
9336
9337 // Transform the key expression.
9338 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9339 if (Key.isInvalid())
9340 return ExprError();
9341
9342 // If nothing changed, just retain the existing expression.
9343 if (!getDerived().AlwaysRebuild() &&
9344 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009345 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009346
Chad Rosier1dcde962012-08-08 18:46:20 +00009347 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009348 Base.get(), Key.get(),
9349 E->getAtIndexMethodDecl(),
9350 E->setAtIndexMethodDecl());
9351}
9352
9353template<typename Derived>
9354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009355TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009356 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009357 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009358 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009359 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009360
Douglas Gregord51d90d2010-04-26 20:11:03 +00009361 // If nothing changed, just retain the existing expression.
9362 if (!getDerived().AlwaysRebuild() &&
9363 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009364 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009365
John McCallb268a282010-08-23 23:25:46 +00009366 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009367 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009368 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009369}
9370
Mike Stump11289f42009-09-09 15:08:12 +00009371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009373TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009374 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009375 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009376 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009377 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009378 SubExprs, &ArgumentChanged))
9379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009380
Douglas Gregora16548e2009-08-11 05:31:07 +00009381 if (!getDerived().AlwaysRebuild() &&
9382 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009383 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009384
Douglas Gregora16548e2009-08-11 05:31:07 +00009385 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009386 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009387 E->getRParenLoc());
9388}
9389
Mike Stump11289f42009-09-09 15:08:12 +00009390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009391ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009392TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9393 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9394 if (SrcExpr.isInvalid())
9395 return ExprError();
9396
9397 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9398 if (!Type)
9399 return ExprError();
9400
9401 if (!getDerived().AlwaysRebuild() &&
9402 Type == E->getTypeSourceInfo() &&
9403 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009404 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009405
9406 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9407 SrcExpr.get(), Type,
9408 E->getRParenLoc());
9409}
9410
9411template<typename Derived>
9412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009413TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009414 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009415
Craig Topperc3ec1492014-05-26 06:22:03 +00009416 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009417 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9418
9419 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009420 blockScope->TheDecl->setBlockMissingReturnType(
9421 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009422
Chris Lattner01cf8db2011-07-20 06:58:45 +00009423 SmallVector<ParmVarDecl*, 4> params;
9424 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009425
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009426 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009427 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9428 oldBlock->param_begin(),
9429 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009430 nullptr, paramTypes, &params)) {
9431 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009432 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009433 }
John McCall490112f2011-02-04 18:33:18 +00009434
Jordan Rosea0a86be2013-03-08 22:25:36 +00009435 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009436 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009437 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009438
Jordan Rose5c382722013-03-08 21:51:21 +00009439 QualType functionType =
9440 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009441 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009442 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009443
9444 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009445 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009446 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009447
9448 if (!oldBlock->blockMissingReturnType()) {
9449 blockScope->HasImplicitReturnType = false;
9450 blockScope->ReturnType = exprResultType;
9451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009452
John McCall3882ace2011-01-05 12:14:39 +00009453 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009454 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009455 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009456 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009457 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009458 }
John McCall3882ace2011-01-05 12:14:39 +00009459
John McCall490112f2011-02-04 18:33:18 +00009460#ifndef NDEBUG
9461 // In builds with assertions, make sure that we captured everything we
9462 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009463 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009464 for (const auto &I : oldBlock->captures()) {
9465 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009466
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009467 // Ignore parameter packs.
9468 if (isa<ParmVarDecl>(oldCapture) &&
9469 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9470 continue;
John McCall490112f2011-02-04 18:33:18 +00009471
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009472 VarDecl *newCapture =
9473 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9474 oldCapture));
9475 assert(blockScope->CaptureMap.count(newCapture));
9476 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009477 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009478 }
9479#endif
9480
9481 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009482 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009483}
9484
Mike Stump11289f42009-09-09 15:08:12 +00009485template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009486ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009487TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009488 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009489}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009490
9491template<typename Derived>
9492ExprResult
9493TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009494 QualType RetTy = getDerived().TransformType(E->getType());
9495 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009496 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009497 SubExprs.reserve(E->getNumSubExprs());
9498 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9499 SubExprs, &ArgumentChanged))
9500 return ExprError();
9501
9502 if (!getDerived().AlwaysRebuild() &&
9503 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009504 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009505
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009506 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009507 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009508}
Chad Rosier1dcde962012-08-08 18:46:20 +00009509
Douglas Gregora16548e2009-08-11 05:31:07 +00009510//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009511// Type reconstruction
9512//===----------------------------------------------------------------------===//
9513
Mike Stump11289f42009-09-09 15:08:12 +00009514template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009515QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9516 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009517 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518 getDerived().getBaseEntity());
9519}
9520
Mike Stump11289f42009-09-09 15:08:12 +00009521template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009522QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9523 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009524 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 getDerived().getBaseEntity());
9526}
9527
Mike Stump11289f42009-09-09 15:08:12 +00009528template<typename Derived>
9529QualType
John McCall70dd5f62009-10-30 00:06:24 +00009530TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9531 bool WrittenAsLValue,
9532 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009533 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009534 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009535}
9536
9537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009538QualType
John McCall70dd5f62009-10-30 00:06:24 +00009539TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9540 QualType ClassType,
9541 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009542 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9543 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009544}
9545
9546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009547QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009548TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9549 ArrayType::ArraySizeModifier SizeMod,
9550 const llvm::APInt *Size,
9551 Expr *SizeExpr,
9552 unsigned IndexTypeQuals,
9553 SourceRange BracketsRange) {
9554 if (SizeExpr || !Size)
9555 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9556 IndexTypeQuals, BracketsRange,
9557 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009558
9559 QualType Types[] = {
9560 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9561 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9562 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009564 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009565 QualType SizeType;
9566 for (unsigned I = 0; I != NumTypes; ++I)
9567 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9568 SizeType = Types[I];
9569 break;
9570 }
Mike Stump11289f42009-09-09 15:08:12 +00009571
Eli Friedman9562f392012-01-25 23:20:27 +00009572 // Note that we can return a VariableArrayType here in the case where
9573 // the element type was a dependent VariableArrayType.
9574 IntegerLiteral *ArraySize
9575 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9576 /*FIXME*/BracketsRange.getBegin());
9577 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009578 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009579 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009580}
Mike Stump11289f42009-09-09 15:08:12 +00009581
Douglas Gregord6ff3322009-08-04 16:50:30 +00009582template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009583QualType
9584TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009585 ArrayType::ArraySizeModifier SizeMod,
9586 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009587 unsigned IndexTypeQuals,
9588 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009589 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009590 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009591}
9592
9593template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009594QualType
Mike Stump11289f42009-09-09 15:08:12 +00009595TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009596 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009597 unsigned IndexTypeQuals,
9598 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009599 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009600 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009601}
Mike Stump11289f42009-09-09 15:08:12 +00009602
Douglas Gregord6ff3322009-08-04 16:50:30 +00009603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009604QualType
9605TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009606 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009607 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009608 unsigned IndexTypeQuals,
9609 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009610 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009611 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009612 IndexTypeQuals, BracketsRange);
9613}
9614
9615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009616QualType
9617TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009618 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009619 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009620 unsigned IndexTypeQuals,
9621 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009622 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009623 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009624 IndexTypeQuals, BracketsRange);
9625}
9626
9627template<typename Derived>
9628QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009629 unsigned NumElements,
9630 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009631 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009632 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009633}
Mike Stump11289f42009-09-09 15:08:12 +00009634
Douglas Gregord6ff3322009-08-04 16:50:30 +00009635template<typename Derived>
9636QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9637 unsigned NumElements,
9638 SourceLocation AttributeLoc) {
9639 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9640 NumElements, true);
9641 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009642 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9643 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009644 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009645}
Mike Stump11289f42009-09-09 15:08:12 +00009646
Douglas Gregord6ff3322009-08-04 16:50:30 +00009647template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009648QualType
9649TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009650 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009651 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009652 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009653}
Mike Stump11289f42009-09-09 15:08:12 +00009654
Douglas Gregord6ff3322009-08-04 16:50:30 +00009655template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009656QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9657 QualType T,
9658 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009659 const FunctionProtoType::ExtProtoInfo &EPI) {
9660 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009661 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009662 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009663 EPI);
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>
John McCall550e0c22009-10-21 00:40:46 +00009667QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9668 return SemaRef.Context.getFunctionNoProtoType(T);
9669}
9670
9671template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009672QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9673 assert(D && "no decl found");
9674 if (D->isInvalidDecl()) return QualType();
9675
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009676 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009677 TypeDecl *Ty;
9678 if (isa<UsingDecl>(D)) {
9679 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009680 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009681 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9682
9683 // A valid resolved using typename decl points to exactly one type decl.
9684 assert(++Using->shadow_begin() == Using->shadow_end());
9685 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
John McCallb96ec562009-12-04 22:46:56 +00009687 } else {
9688 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9689 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9690 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9691 }
9692
9693 return SemaRef.Context.getTypeDeclType(Ty);
9694}
9695
9696template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009697QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9698 SourceLocation Loc) {
9699 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009700}
9701
9702template<typename Derived>
9703QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9704 return SemaRef.Context.getTypeOfType(Underlying);
9705}
9706
9707template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009708QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9709 SourceLocation Loc) {
9710 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009711}
9712
9713template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009714QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9715 UnaryTransformType::UTTKind UKind,
9716 SourceLocation Loc) {
9717 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9718}
9719
9720template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009721QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009722 TemplateName Template,
9723 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009724 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009725 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregor1135c352009-08-06 05:28:30 +00009728template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009729QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9730 SourceLocation KWLoc) {
9731 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9732}
9733
9734template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009735TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009736TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009737 bool TemplateKW,
9738 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009739 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009740 Template);
9741}
9742
9743template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009744TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009745TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9746 const IdentifierInfo &Name,
9747 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009748 QualType ObjectType,
9749 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009750 UnqualifiedId TemplateName;
9751 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009752 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009753 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009754 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009755 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009756 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009757 /*EnteringContext=*/false,
9758 Template);
John McCall31f82722010-11-12 08:19:04 +00009759 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009760}
Mike Stump11289f42009-09-09 15:08:12 +00009761
Douglas Gregora16548e2009-08-11 05:31:07 +00009762template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009763TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009764TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009765 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009766 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009767 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009768 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009769 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009770 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009771 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009772 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009773 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009774 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009775 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009776 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009777 /*EnteringContext=*/false,
9778 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009779 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009780}
Chad Rosier1dcde962012-08-08 18:46:20 +00009781
Douglas Gregor71395fa2009-11-04 00:56:37 +00009782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009783ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009784TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9785 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009786 Expr *OrigCallee,
9787 Expr *First,
9788 Expr *Second) {
9789 Expr *Callee = OrigCallee->IgnoreParenCasts();
9790 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009791
Douglas Gregora16548e2009-08-11 05:31:07 +00009792 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009793 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009794 if (!First->getType()->isOverloadableType() &&
9795 !Second->getType()->isOverloadableType())
9796 return getSema().CreateBuiltinArraySubscriptExpr(First,
9797 Callee->getLocStart(),
9798 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009799 } else if (Op == OO_Arrow) {
9800 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009801 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9802 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009803 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009804 // The argument is not of overloadable type, so try to create a
9805 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009806 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009807 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009808
John McCallb268a282010-08-23 23:25:46 +00009809 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009810 }
9811 } else {
John McCallb268a282010-08-23 23:25:46 +00009812 if (!First->getType()->isOverloadableType() &&
9813 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009814 // Neither of the arguments is an overloadable type, so try to
9815 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009816 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009817 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009818 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009819 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009821
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009822 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009823 }
9824 }
Mike Stump11289f42009-09-09 15:08:12 +00009825
9826 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009827 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009828 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009829
John McCallb268a282010-08-23 23:25:46 +00009830 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009831 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009832 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009833 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009834 // If we've resolved this to a particular non-member function, just call
9835 // that function. If we resolved it to a member function,
9836 // CreateOverloaded* will find that function for us.
9837 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9838 if (!isa<CXXMethodDecl>(ND))
9839 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009840 }
Mike Stump11289f42009-09-09 15:08:12 +00009841
Douglas Gregora16548e2009-08-11 05:31:07 +00009842 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009843 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009844 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009845
Douglas Gregora16548e2009-08-11 05:31:07 +00009846 // Create the overloaded operator invocation for unary operators.
9847 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009848 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009849 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009850 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009851 }
Mike Stump11289f42009-09-09 15:08:12 +00009852
Douglas Gregore9d62932011-07-15 16:25:15 +00009853 if (Op == OO_Subscript) {
9854 SourceLocation LBrace;
9855 SourceLocation RBrace;
9856
9857 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9858 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9859 LBrace = SourceLocation::getFromRawEncoding(
9860 NameLoc.CXXOperatorName.BeginOpNameLoc);
9861 RBrace = SourceLocation::getFromRawEncoding(
9862 NameLoc.CXXOperatorName.EndOpNameLoc);
9863 } else {
9864 LBrace = Callee->getLocStart();
9865 RBrace = OpLoc;
9866 }
9867
9868 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9869 First, Second);
9870 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009871
Douglas Gregora16548e2009-08-11 05:31:07 +00009872 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009873 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009874 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009875 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9876 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009878
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009879 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009880}
Mike Stump11289f42009-09-09 15:08:12 +00009881
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009882template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009883ExprResult
John McCallb268a282010-08-23 23:25:46 +00009884TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009885 SourceLocation OperatorLoc,
9886 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009887 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009888 TypeSourceInfo *ScopeType,
9889 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009890 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009891 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009892 QualType BaseType = Base->getType();
9893 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009894 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009895 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009896 !BaseType->getAs<PointerType>()->getPointeeType()
9897 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009898 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009899 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009900 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009901 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009902 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009903 /*FIXME?*/true);
9904 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009905
Douglas Gregor678f90d2010-02-25 01:56:36 +00009906 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009907 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9908 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9909 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9910 NameInfo.setNamedTypeInfo(DestroyedType);
9911
Richard Smith8e4a3862012-05-15 06:15:11 +00009912 // The scope type is now known to be a valid nested name specifier
9913 // component. Tack it on to the end of the nested name specifier.
9914 if (ScopeType)
9915 SS.Extend(SemaRef.Context, SourceLocation(),
9916 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009917
Abramo Bagnara7945c982012-01-27 09:46:47 +00009918 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009919 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009920 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009921 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009922 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009923 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009924 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009925}
9926
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009927template<typename Derived>
9928StmtResult
9929TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009930 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +00009931 CapturedDecl *CD = S->getCapturedDecl();
9932 unsigned NumParams = CD->getNumParams();
9933 unsigned ContextParamPos = CD->getContextParamPosition();
9934 SmallVector<Sema::CapturedParamNameType, 4> Params;
9935 for (unsigned I = 0; I < NumParams; ++I) {
9936 if (I != ContextParamPos) {
9937 Params.push_back(
9938 std::make_pair(
9939 CD->getParam(I)->getName(),
9940 getDerived().TransformType(CD->getParam(I)->getType())));
9941 } else {
9942 Params.push_back(std::make_pair(StringRef(), QualType()));
9943 }
9944 }
Craig Topperc3ec1492014-05-26 06:22:03 +00009945 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +00009946 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +00009947 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9948
9949 if (Body.isInvalid()) {
9950 getSema().ActOnCapturedRegionError();
9951 return StmtError();
9952 }
9953
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009954 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009955}
9956
Douglas Gregord6ff3322009-08-04 16:50:30 +00009957} // end namespace clang
9958
9959#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H