blob: 165a1aff3b4457ada200c6b2b0c97278fef46e48 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCall781472f2010-08-25 08:40:02 +000041using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000042
Douglas Gregor577f75a2009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump1eb44332009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump1eb44332009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000102
Douglas Gregord3731192011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000107
Douglas Gregord3731192011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000115
Douglas Gregordfca6f52012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000124
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 }
132
John McCall60d7b3a2010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000135
Douglas Gregor577f75a2009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the location of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000150 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// provide an alternative implementation that provides better location
152 /// information.
153 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// \brief Returns the name of the entity being transformed, if that
156 /// information was not available elsewhere in the AST.
157 ///
158 /// By default, returns an empty name. Subclasses can provide an alternative
159 /// implementation with a more precise name.
160 DeclarationName getBaseEntity() { return DeclarationName(); }
161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief Sets the "base" location and entity when that
163 /// information is known based on another transformation.
164 ///
165 /// By default, the source location and entity are ignored. Subclasses can
166 /// override this function to provide a customized implementation.
167 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 /// \brief RAII object that temporarily sets the base location and entity
170 /// used for reporting diagnostics in types.
171 class TemporaryBase {
172 TreeTransform &Self;
173 SourceLocation OldLocation;
174 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 public:
177 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000178 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 OldLocation = Self.getDerived().getBaseLocation();
180 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000181
Douglas Gregorae201f72011-01-25 17:51:48 +0000182 if (Location.isValid())
183 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Douglas Gregorb98b1992009-08-11 05:31:07 +0000186 ~TemporaryBase() {
187 Self.getDerived().setBase(OldLocation, OldEntity);
188 }
189 };
Mike Stump1eb44332009-09-09 15:08:12 +0000190
191 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 /// transformed.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000195 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// not change. For example, template instantiation need not traverse
197 /// non-dependent types.
198 bool AlreadyTransformed(QualType T) {
199 return T.isNull();
200 }
201
Douglas Gregor6eef5192009-12-14 19:27:10 +0000202 /// \brief Determine whether the given call argument should be dropped, e.g.,
203 /// because it is a default argument.
204 ///
205 /// Subclasses can provide an alternative implementation of this routine to
206 /// determine which kinds of call arguments get dropped. By default,
207 /// CXXDefaultArgument nodes are dropped (prior to transformation).
208 bool DropCallArgument(Expr *E) {
209 return E->isDefaultArgument();
210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000211
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000212 /// \brief Determine whether we should expand a pack expansion with the
213 /// given set of parameter packs into separate arguments by repeatedly
214 /// transforming the pattern.
215 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000216 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000217 /// Subclasses can override this routine to provide different behavior.
218 ///
219 /// \param EllipsisLoc The location of the ellipsis that identifies the
220 /// pack expansion.
221 ///
222 /// \param PatternRange The source range that covers the entire pattern of
223 /// the pack expansion.
224 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000225 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000226 /// pattern.
227 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000228 /// \param ShouldExpand Will be set to \c true if the transformer should
229 /// expand the corresponding pack expansions into separate arguments. When
230 /// set, \c NumExpansions must also be set.
231 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000232 /// \param RetainExpansion Whether the caller should add an unexpanded
233 /// pack expansion after all of the expanded arguments. This is used
234 /// when extending explicitly-specified template argument packs per
235 /// C++0x [temp.arg.explicit]p9.
236 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000237 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000238 /// the expanded form of the corresponding pack expansion. This is both an
239 /// input and an output parameter, which can be set by the caller if the
240 /// number of expansions is known a priori (e.g., due to a prior substitution)
241 /// and will be set by the callee when the number of expansions is known.
242 /// The callee must set this value when \c ShouldExpand is \c true; it may
243 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000244 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000245 /// \returns true if an error occurred (e.g., because the parameter packs
246 /// are to be instantiated with arguments of different lengths), false
247 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 /// must be set.
249 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
250 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000251 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000253 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000254 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000255 ShouldExpand = false;
256 return false;
257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000258
Douglas Gregord3731192011-01-10 07:32:04 +0000259 /// \brief "Forget" about the partially-substituted pack template argument,
260 /// when performing an instantiation that must preserve the parameter pack
261 /// use.
262 ///
263 /// This routine is meant to be overridden by the template instantiator.
264 TemplateArgument ForgetPartiallySubstitutedPack() {
265 return TemplateArgument();
266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000267
Douglas Gregord3731192011-01-10 07:32:04 +0000268 /// \brief "Remember" the partially-substituted pack template argument
269 /// after performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000274
Douglas Gregor12c9c002011-01-07 16:43:16 +0000275 /// \brief Note to the derived class when a function parameter pack is
276 /// being expanded.
277 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transforms the given type into another type.
280 ///
John McCalla2becad2009-10-21 00:40:46 +0000281 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000282 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000283 /// function. This is expensive, but we don't mind, because
284 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000285 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000286 ///
287 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000288 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
John McCalla2becad2009-10-21 00:40:46 +0000290 /// \brief Transforms the given type-with-location into a new
291 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 ///
John McCalla2becad2009-10-21 00:40:46 +0000293 /// By default, this routine transforms a type by delegating to the
294 /// appropriate TransformXXXType to build a new type. Subclasses
295 /// may override this function (to take over all type
296 /// transformations) or some set of the TransformXXXType functions
297 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000298 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000299
300 /// \brief Transform the given type-with-location into a new
301 /// type, collecting location information in the given builder
302 /// as necessary.
303 ///
John McCall43fed0d2010-11-12 08:19:04 +0000304 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000307 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000308 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000309 /// appropriate TransformXXXStmt function to transform a specific kind of
310 /// statement or the TransformExpr() function to transform an expression.
311 /// Subclasses may override this function to transform statements using some
312 /// other mechanism.
313 ///
314 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000315 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000316
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000317 /// \brief Transform the given statement.
318 ///
319 /// By default, this routine transforms a statement by delegating to the
320 /// appropriate TransformOMPXXXClause function to transform a specific kind
321 /// of clause. Subclasses may override this function to transform statements
322 /// using some other mechanism.
323 ///
324 /// \returns the transformed OpenMP clause.
325 OMPClause *TransformOMPClause(OMPClause *S);
326
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000327 /// \brief Transform the given expression.
328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329 /// By default, this routine transforms an expression by delegating to the
330 /// appropriate TransformXXXExpr function to build a new expression.
331 /// Subclasses may override this function to transform expressions using some
332 /// other mechanism.
333 ///
334 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000335 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Richard Smithc83c2302012-12-19 01:39:02 +0000337 /// \brief Transform the given initializer.
338 ///
339 /// By default, this routine transforms an initializer by stripping off the
340 /// semantic nodes added by initialization, then passing the result to
341 /// TransformExpr or TransformExprs.
342 ///
343 /// \returns the transformed initializer.
344 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
345
Douglas Gregoraa165f82011-01-03 19:04:46 +0000346 /// \brief Transform the given list of expressions.
347 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// This routine transforms a list of expressions by invoking
349 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// support for variadic templates by expanding any pack expansions (if the
351 /// derived class permits such expansion) along the way. When pack expansions
352 /// are present, the number of outputs may not equal the number of inputs.
353 ///
354 /// \param Inputs The set of expressions to be transformed.
355 ///
356 /// \param NumInputs The number of expressions in \c Inputs.
357 ///
358 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 /// be.
361 ///
362 /// \param Outputs The transformed input expressions will be added to this
363 /// vector.
364 ///
365 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
366 /// due to transformation.
367 ///
368 /// \returns true if an error occurred, false otherwise.
369 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000370 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000371 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Transform the given declaration, which is referenced from a type
374 /// or expression.
375 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000376 /// By default, acts as the identity function on declarations, unless the
377 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000379 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 llvm::DenseMap<Decl *, Decl *>::iterator Known
381 = TransformedLocalDecls.find(D);
382 if (Known != TransformedLocalDecls.end())
383 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000384
385 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000386 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000387
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000389 /// place them on the new declaration.
390 ///
391 /// By default, this operation does nothing. Subclasses may override this
392 /// behavior to transform attributes.
393 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregordfca6f52012-02-13 22:00:16 +0000395 /// \brief Note that a local declaration has been transformed by this
396 /// transformer.
397 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
400 /// the transformer itself has to transform the declarations. This routine
401 /// can be overridden by a subclass that keeps track of such mappings.
402 void transformedLocalDecl(Decl *Old, Decl *New) {
403 TransformedLocalDecls[Old] = New;
404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000405
Douglas Gregor43959a92009-08-20 07:17:43 +0000406 /// \brief Transform the definition of the given declaration.
407 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000408 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000409 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000410 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
411 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 /// \brief Transform the given declaration, which was the first part of a
415 /// nested-name-specifier in a member access expression.
416 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000417 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// identifier in a nested-name-specifier of a member access expression, e.g.,
419 /// the \c T in \c x->T::member
420 ///
421 /// By default, invokes TransformDecl() to transform the declaration.
422 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000423 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
424 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000427 /// \brief Transform the given nested-name-specifier with source-location
428 /// information.
429 ///
430 /// By default, transforms all of the types and declarations within the
431 /// nested-name-specifier. Subclasses may override this function to provide
432 /// alternate behavior.
433 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
434 NestedNameSpecifierLoc NNS,
435 QualType ObjectType = QualType(),
436 NamedDecl *FirstQualifierInScope = 0);
437
Douglas Gregor81499bb2009-09-03 22:13:48 +0000438 /// \brief Transform the given declaration name.
439 ///
440 /// By default, transforms the types of conversion function, constructor,
441 /// and destructor names and then (if needed) rebuilds the declaration name.
442 /// Identifiers and selectors are returned unmodified. Sublcasses may
443 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000444 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000445 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000449 /// \param SS The nested-name-specifier that qualifies the template
450 /// name. This nested-name-specifier must already have been transformed.
451 ///
452 /// \param Name The template name to transform.
453 ///
454 /// \param NameLoc The source location of the template name.
455 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000456 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000457 /// access expression, this is the type of the object whose member template
458 /// is being referenced.
459 ///
460 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
461 /// also refers to a name within the current (lexical) scope, this is the
462 /// declaration it refers to.
463 ///
464 /// By default, transforms the template name by transforming the declarations
465 /// and nested-name-specifiers that occur within the template name.
466 /// Subclasses may override this function to provide alternate behavior.
467 TemplateName TransformTemplateName(CXXScopeSpec &SS,
468 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000469 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000470 QualType ObjectType = QualType(),
471 NamedDecl *FirstQualifierInScope = 0);
472
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 /// \brief Transform the given template argument.
474 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000475 /// By default, this operation transforms the type, expression, or
476 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000477 /// new template argument from the transformed result. Subclasses may
478 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000479 ///
480 /// Returns true if there was an error.
481 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
482 TemplateArgumentLoc &Output);
483
Douglas Gregorfcc12532010-12-20 17:31:10 +0000484 /// \brief Transform the given set of template arguments.
485 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000486 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000487 /// in the input set using \c TransformTemplateArgument(), and appends
488 /// the transformed arguments to the output list.
489 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000490 /// Note that this overload of \c TransformTemplateArguments() is merely
491 /// a convenience function. Subclasses that wish to override this behavior
492 /// should override the iterator-based member template version.
493 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000494 /// \param Inputs The set of template arguments to be transformed.
495 ///
496 /// \param NumInputs The number of template arguments in \p Inputs.
497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
502 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
503 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000504 TemplateArgumentListInfo &Outputs) {
505 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
506 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000507
508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000512 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000513 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000514 /// \param First An iterator to the first template argument.
515 ///
516 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
518 /// \param Outputs The set of transformed template arguments output by this
519 /// routine.
520 ///
521 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000522 template<typename InputIterator>
523 bool TransformTemplateArguments(InputIterator First,
524 InputIterator Last,
525 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000526
John McCall833ca992009-10-29 08:12:44 +0000527 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
528 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
529 TemplateArgumentLoc &ArgLoc);
530
John McCalla93c9342009-12-07 02:54:59 +0000531 /// \brief Fakes up a TypeSourceInfo for a type.
532 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
533 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000534 getDerived().getBaseLocation());
535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
John McCalla2becad2009-10-21 00:40:46 +0000537#define ABSTRACT_TYPELOC(CLASS, PARENT)
538#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000539 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000540#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000542 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
543 FunctionProtoTypeLoc TL,
544 CXXRecordDecl *ThisContext,
545 unsigned ThisTypeQuals);
546
John Wiegley28bbe4b2011-04-28 01:08:34 +0000547 StmtResult
548 TransformSEHHandler(Stmt *Handler);
549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000551 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
552 TemplateSpecializationTypeLoc TL,
553 TemplateName Template);
554
Chad Rosier4a9d7952012-08-08 18:46:20 +0000555 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000556 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
557 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000558 TemplateName Template,
559 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000560
Chad Rosier4a9d7952012-08-08 18:46:20 +0000561 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000562 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000563 DependentTemplateSpecializationTypeLoc TL,
564 NestedNameSpecifierLoc QualifierLoc);
565
John McCall21ef0fa2010-03-11 09:03:00 +0000566 /// \brief Transforms the parameters of a function type into the
567 /// given vectors.
568 ///
569 /// The result vectors should be kept in sync; null entries in the
570 /// variables vector are acceptable.
571 ///
572 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000573 bool TransformFunctionTypeParams(SourceLocation Loc,
574 ParmVarDecl **Params, unsigned NumParams,
575 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000576 SmallVectorImpl<QualType> &PTypes,
577 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000578
579 /// \brief Transforms a single function-type parameter. Return null
580 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000581 ///
582 /// \param indexAdjustment - A number to add to the parameter's
583 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000584 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000585 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000586 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000587 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000588
John McCall43fed0d2010-11-12 08:19:04 +0000589 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000590
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
592 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Richard Smith612409e2012-07-25 03:56:55 +0000594 /// \brief Transform the captures and body of a lambda expression.
595 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
596
Richard Smithefeeccf2012-10-21 03:28:35 +0000597 ExprResult TransformAddressOfOperand(Expr *E);
598 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
599 bool IsAddressOfOperand);
600
Douglas Gregor43959a92009-08-20 07:17:43 +0000601#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000602 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000603#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000604 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000605#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000606#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000608#define OPENMP_CLAUSE(Name, Class) \
609 OMPClause *Transform ## Class(Class *S);
610#include "clang/Basic/OpenMPKinds.def"
611
Douglas Gregor577f75a2009-08-04 16:50:30 +0000612 /// \brief Build a new pointer type given its pointee type.
613 ///
614 /// By default, performs semantic analysis when building the pointer type.
615 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000616 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617
618 /// \brief Build a new block pointer type given its pointee type.
619 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000620 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000622 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623
John McCall85737a72009-10-30 00:06:24 +0000624 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 ///
John McCall85737a72009-10-30 00:06:24 +0000626 /// By default, performs semantic analysis when building the
627 /// reference type. Subclasses may override this routine to provide
628 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 ///
John McCall85737a72009-10-30 00:06:24 +0000630 /// \param LValue whether the type was written with an lvalue sigil
631 /// or an rvalue sigil.
632 QualType RebuildReferenceType(QualType ReferentType,
633 bool LValue,
634 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new member pointer type given the pointee type and the
637 /// class type it refers into.
638 ///
639 /// By default, performs semantic analysis when building the member pointer
640 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000641 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
642 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new array type given the element type, size
645 /// modifier, size of the array (if known), size expression, and index type
646 /// qualifiers.
647 ///
648 /// By default, performs semantic analysis when building the array type.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000650 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 QualType RebuildArrayType(QualType ElementType,
652 ArrayType::ArraySizeModifier SizeMod,
653 const llvm::APInt *Size,
654 Expr *SizeExpr,
655 unsigned IndexTypeQuals,
656 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// \brief Build a new constant array type given the element type, size
659 /// modifier, (known) size of the array, and index type qualifiers.
660 ///
661 /// By default, performs semantic analysis when building the array type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000663 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000664 ArrayType::ArraySizeModifier SizeMod,
665 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000666 unsigned IndexTypeQuals,
667 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 /// \brief Build a new incomplete array type given the element type, size
670 /// modifier, and index type qualifiers.
671 ///
672 /// By default, performs semantic analysis when building the array type.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000674 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000675 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678
Mike Stump1eb44332009-09-09 15:08:12 +0000679 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// size modifier, size expression, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000684 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000686 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
689
Mike Stump1eb44332009-09-09 15:08:12 +0000690 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 /// size modifier, size expression, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000695 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000697 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
700
701 /// \brief Build a new vector type given the element type and
702 /// number of elements.
703 ///
704 /// By default, performs semantic analysis when building the vector type.
705 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000706 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000707 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000708
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 /// \brief Build a new extended vector type given the element type and
710 /// number of elements.
711 ///
712 /// By default, performs semantic analysis when building the vector type.
713 /// Subclasses may override this routine to provide different behavior.
714 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
715 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
717 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000718 /// given the element type and number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000722 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000723 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new function type.
727 ///
728 /// By default, performs semantic analysis when building the function type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000731 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000732 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000733
John McCalla2becad2009-10-21 00:40:46 +0000734 /// \brief Build a new unprototyped function type.
735 QualType RebuildFunctionNoProtoType(QualType ResultType);
736
John McCalled976492009-12-04 22:46:56 +0000737 /// \brief Rebuild an unresolved typename type, given the decl that
738 /// the UnresolvedUsingTypenameDecl was transformed to.
739 QualType RebuildUnresolvedUsingType(Decl *D);
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000742 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743 return SemaRef.Context.getTypeDeclType(Typedef);
744 }
745
746 /// \brief Build a new class/struct/union type.
747 QualType RebuildRecordType(RecordDecl *Record) {
748 return SemaRef.Context.getTypeDeclType(Record);
749 }
750
751 /// \brief Build a new Enum type.
752 QualType RebuildEnumType(EnumDecl *Enum) {
753 return SemaRef.Context.getTypeDeclType(Enum);
754 }
John McCall7da24312009-09-05 00:15:47 +0000755
Mike Stump1eb44332009-09-09 15:08:12 +0000756 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000757 ///
758 /// By default, performs semantic analysis when building the typeof type.
759 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000760 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761
Mike Stump1eb44332009-09-09 15:08:12 +0000762 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000763 ///
764 /// By default, builds a new TypeOfType with the given underlying type.
765 QualType RebuildTypeOfType(QualType Underlying);
766
Sean Huntca63c202011-05-24 22:41:36 +0000767 /// \brief Build a new unary transform type.
768 QualType RebuildUnaryTransformType(QualType BaseType,
769 UnaryTransformType::UTTKind UKind,
770 SourceLocation Loc);
771
Richard Smitha2c36462013-04-26 16:15:35 +0000772 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the decltype type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000776 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Richard Smitha2c36462013-04-26 16:15:35 +0000778 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000779 ///
780 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000781 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000782 // Note, IsDependent is always false here: we implicitly convert an 'auto'
783 // which has been deduced to a dependent type into an undeduced 'auto', so
784 // that we'll retry deduction after the transformation.
Manuel Klimek152b4e42013-08-22 12:12:24 +0000785 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000786 }
787
Douglas Gregor577f75a2009-08-04 16:50:30 +0000788 /// \brief Build a new template specialization type.
789 ///
790 /// By default, performs semantic analysis when building the template
791 /// specialization type. Subclasses may override this routine to provide
792 /// different behavior.
793 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000794 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000795 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000796
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000797 /// \brief Build a new parenthesized type.
798 ///
799 /// By default, builds a new ParenType type from the inner type.
800 /// Subclasses may override this routine to provide different behavior.
801 QualType RebuildParenType(QualType InnerType) {
802 return SemaRef.Context.getParenType(InnerType);
803 }
804
Douglas Gregor577f75a2009-08-04 16:50:30 +0000805 /// \brief Build a new qualified name type.
806 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000807 /// By default, builds a new ElaboratedType type from the keyword,
808 /// the nested-name-specifier and the named type.
809 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000810 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
811 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000812 NestedNameSpecifierLoc QualifierLoc,
813 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000814 return SemaRef.Context.getElaboratedType(Keyword,
815 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000816 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000817 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000818
819 /// \brief Build a new typename type that refers to a template-id.
820 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000821 /// By default, builds a new DependentNameType type from the
822 /// nested-name-specifier and the given type. Subclasses may override
823 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000824 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 ElaboratedTypeKeyword Keyword,
826 NestedNameSpecifierLoc QualifierLoc,
827 const IdentifierInfo *Name,
828 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000829 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 // Rebuild the template name.
831 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000832 CXXScopeSpec SS;
833 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000834 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000835 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000836
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000837 if (InstName.isNull())
838 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 // If it's still dependent, make a dependent specialization.
841 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000842 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
843 QualifierLoc.getNestedNameSpecifier(),
844 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000845 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000846
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000847 // Otherwise, make an elaborated type wrapping a non-dependent
848 // specialization.
849 QualType T =
850 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
851 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000852
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000853 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
854 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000855
856 return SemaRef.Context.getElaboratedType(Keyword,
857 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 T);
859 }
860
Douglas Gregor577f75a2009-08-04 16:50:30 +0000861 /// \brief Build a new typename type that refers to an identifier.
862 ///
863 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000865 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000866 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000867 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 NestedNameSpecifierLoc QualifierLoc,
869 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000871 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000872 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873
Douglas Gregor2494dd02011-03-01 01:34:45 +0000874 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000875 // If the name is still dependent, just build a new dependent name type.
876 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000877 return SemaRef.Context.getDependentNameType(Keyword,
878 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000880 }
881
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000882 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000883 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000884 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000885
886 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
887
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000888 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000889 // into a non-dependent elaborated-type-specifier. Find the tag we're
890 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000891 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000892 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
893 if (!DC)
894 return QualType();
895
John McCall56138762010-05-27 06:40:31 +0000896 if (SemaRef.RequireCompleteDeclContext(SS, DC))
897 return QualType();
898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 TagDecl *Tag = 0;
900 SemaRef.LookupQualifiedName(Result, DC);
901 switch (Result.getResultKind()) {
902 case LookupResult::NotFound:
903 case LookupResult::NotFoundInCurrentInstantiation:
904 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000905
Douglas Gregor40336422010-03-31 22:19:08 +0000906 case LookupResult::Found:
907 Tag = Result.getAsSingle<TagDecl>();
908 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000909
Douglas Gregor40336422010-03-31 22:19:08 +0000910 case LookupResult::FoundOverloaded:
911 case LookupResult::FoundUnresolvedValue:
912 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000913
Douglas Gregor40336422010-03-31 22:19:08 +0000914 case LookupResult::Ambiguous:
915 // Let the LookupResult structure handle ambiguities.
916 return QualType();
917 }
918
919 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000920 // Check where the name exists but isn't a tag type and use that to emit
921 // better diagnostics.
922 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
923 SemaRef.LookupQualifiedName(Result, DC);
924 switch (Result.getResultKind()) {
925 case LookupResult::Found:
926 case LookupResult::FoundOverloaded:
927 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000928 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000929 unsigned Kind = 0;
930 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000931 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
932 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000933 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
934 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
935 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000936 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000937 default:
938 // FIXME: Would be nice to highlight just the source range.
939 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
940 << Kind << Id << DC;
941 break;
942 }
Douglas Gregor40336422010-03-31 22:19:08 +0000943 return QualType();
944 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000945
Richard Trieubbf34c02011-06-10 03:11:26 +0000946 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
947 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000948 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000949 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
950 return QualType();
951 }
952
953 // Build the elaborated-type-specifier type.
954 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000955 return SemaRef.Context.getElaboratedType(Keyword,
956 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000957 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000958 }
Mike Stump1eb44332009-09-09 15:08:12 +0000959
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000960 /// \brief Build a new pack expansion type.
961 ///
962 /// By default, builds a new PackExpansionType type from the given pattern.
963 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000964 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000965 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000966 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000967 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000968 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
969 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 }
971
Eli Friedmanb001de72011-10-06 23:00:33 +0000972 /// \brief Build a new atomic type given its value type.
973 ///
974 /// By default, performs semantic analysis when building the atomic type.
975 /// Subclasses may override this routine to provide different behavior.
976 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
977
Douglas Gregord1067e52009-08-06 06:41:21 +0000978 /// \brief Build a new template name given a nested name specifier, a flag
979 /// indicating whether the "template" keyword was provided, and the template
980 /// that the template name refers to.
981 ///
982 /// By default, builds the new template name directly. Subclasses may override
983 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000984 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000985 bool TemplateKW,
986 TemplateDecl *Template);
987
Douglas Gregord1067e52009-08-06 06:41:21 +0000988 /// \brief Build a new template name given a nested name specifier and the
989 /// name that is referred to as a template.
990 ///
991 /// By default, performs semantic analysis to determine whether the name can
992 /// be resolved to a specific template, then builds the appropriate kind of
993 /// template name. Subclasses may override this routine to provide different
994 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
996 const IdentifierInfo &Name,
997 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000998 QualType ObjectType,
999 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001000
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001001 /// \brief Build a new template name given a nested name specifier and the
1002 /// overloaded operator name that is referred to as a template.
1003 ///
1004 /// By default, performs semantic analysis to determine whether the name can
1005 /// be resolved to a specific template, then builds the appropriate kind of
1006 /// template name. Subclasses may override this routine to provide different
1007 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001008 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001009 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001010 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001011 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001012
1013 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001014 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001015 ///
1016 /// By default, performs semantic analysis to determine whether the name can
1017 /// be resolved to a specific template, then builds the appropriate kind of
1018 /// template name. Subclasses may override this routine to provide different
1019 /// behavior.
1020 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1021 const TemplateArgument &ArgPack) {
1022 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1023 }
1024
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 /// \brief Build a new compound statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001029 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 MultiStmtArg Statements,
1031 SourceLocation RBraceLoc,
1032 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001033 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 IsStmtExpr);
1035 }
1036
1037 /// \brief Build a new case statement.
1038 ///
1039 /// By default, performs semantic analysis to build the new statement.
1040 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001041 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001042 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001044 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001046 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 ColonLoc);
1048 }
Mike Stump1eb44332009-09-09 15:08:12 +00001049
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 /// \brief Attach the body to a new case statement.
1051 ///
1052 /// By default, performs semantic analysis to build the new statement.
1053 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001054 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001055 getSema().ActOnCaseStmtBody(S, Body);
1056 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 }
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 /// \brief Build a new default statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001063 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001065 Stmt *SubStmt) {
1066 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 /*CurScope=*/0);
1068 }
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /// \brief Build a new label statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001074 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1075 SourceLocation ColonLoc, Stmt *SubStmt) {
1076 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 }
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Richard Smith534986f2012-04-14 00:33:13 +00001079 /// \brief Build a new label statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001083 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1084 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001085 Stmt *SubStmt) {
1086 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1087 }
1088
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 /// \brief Build a new "if" statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001093 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001094 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001096 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 }
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregor43959a92009-08-20 07:17:43 +00001099 /// \brief Start building a new switch statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001104 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001105 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001106 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001107 }
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 /// \brief Attach the body to the switch statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001113 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001114 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001115 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001116 }
1117
1118 /// \brief Build a new while statement.
1119 ///
1120 /// By default, performs semantic analysis to build the new statement.
1121 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001122 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1123 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 /// \brief Build a new do-while statement.
1128 ///
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001131 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 SourceLocation WhileLoc, SourceLocation LParenLoc,
1133 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001134 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1135 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 }
1137
1138 /// \brief Build a new for statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001142 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001143 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001144 VarDecl *CondVar, Sema::FullExprArg Inc,
1145 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001146 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new goto statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001154 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1155 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001156 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001157 }
1158
1159 /// \brief Build a new indirect goto statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001163 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001164 SourceLocation StarLoc,
1165 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001166 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001167 }
Mike Stump1eb44332009-09-09 15:08:12 +00001168
Douglas Gregor43959a92009-08-20 07:17:43 +00001169 /// \brief Build a new return statement.
1170 ///
1171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001173 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001174 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001175 }
Mike Stump1eb44332009-09-09 15:08:12 +00001176
Douglas Gregor43959a92009-08-20 07:17:43 +00001177 /// \brief Build a new declaration statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001181 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1182 SourceLocation StartLoc, SourceLocation EndLoc) {
1183 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001184 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001185 }
Mike Stump1eb44332009-09-09 15:08:12 +00001186
Anders Carlsson703e3942010-01-24 05:50:09 +00001187 /// \brief Build a new inline asm statement.
1188 ///
1189 /// By default, performs semantic analysis to build the new statement.
1190 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001191 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1192 bool IsVolatile, unsigned NumOutputs,
1193 unsigned NumInputs, IdentifierInfo **Names,
1194 MultiExprArg Constraints, MultiExprArg Exprs,
1195 Expr *AsmString, MultiExprArg Clobbers,
1196 SourceLocation RParenLoc) {
1197 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1198 NumInputs, Names, Constraints, Exprs,
1199 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001200 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001201
Chad Rosier8cd64b42012-06-11 20:47:18 +00001202 /// \brief Build a new MS style inline asm statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001206 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001207 ArrayRef<Token> AsmToks,
1208 StringRef AsmString,
1209 unsigned NumOutputs, unsigned NumInputs,
1210 ArrayRef<StringRef> Constraints,
1211 ArrayRef<StringRef> Clobbers,
1212 ArrayRef<Expr*> Exprs,
1213 SourceLocation EndLoc) {
1214 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1215 NumOutputs, NumInputs,
1216 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001217 }
1218
James Dennett699c9042012-06-15 07:13:21 +00001219 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001223 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001225 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001227 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001229 }
1230
Douglas Gregorbe270a02010-04-26 17:57:08 +00001231 /// \brief Rebuild an Objective-C exception declaration.
1232 ///
1233 /// By default, performs semantic analysis to build the new declaration.
1234 /// Subclasses may override this routine to provide different behavior.
1235 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1236 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001237 return getSema().BuildObjCExceptionDecl(TInfo, T,
1238 ExceptionDecl->getInnerLocStart(),
1239 ExceptionDecl->getLocation(),
1240 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001247 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001248 SourceLocation RParenLoc,
1249 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001250 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001251 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001252 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001254
James Dennett699c9042012-06-15 07:13:21 +00001255 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001256 ///
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001259 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001260 Stmt *Body) {
1261 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001262 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001263
James Dennett699c9042012-06-15 07:13:21 +00001264 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001268 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001269 Expr *Operand) {
1270 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001272
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001273 /// \brief Build a new OpenMP parallel directive.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1278 Stmt *AStmt,
1279 SourceLocation StartLoc,
1280 SourceLocation EndLoc) {
1281 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1282 StartLoc, EndLoc);
1283 }
1284
1285 /// \brief Build a new OpenMP 'default' clause.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
1289 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1290 SourceLocation KindKwLoc,
1291 SourceLocation StartLoc,
1292 SourceLocation LParenLoc,
1293 SourceLocation EndLoc) {
1294 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1295 StartLoc, LParenLoc, EndLoc);
1296 }
1297
1298 /// \brief Build a new OpenMP 'private' clause.
1299 ///
1300 /// By default, performs semantic analysis to build the new statement.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1303 SourceLocation StartLoc,
1304 SourceLocation LParenLoc,
1305 SourceLocation EndLoc) {
1306 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1307 EndLoc);
1308 }
1309
James Dennett699c9042012-06-15 07:13:21 +00001310 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
1314 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1315 Expr *object) {
1316 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1317 }
1318
James Dennett699c9042012-06-15 07:13:21 +00001319 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001320 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001321 /// By default, performs semantic analysis to build the new statement.
1322 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001323 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001324 Expr *Object, Stmt *Body) {
1325 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001326 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001327
James Dennett699c9042012-06-15 07:13:21 +00001328 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001329 ///
1330 /// By default, performs semantic analysis to build the new statement.
1331 /// Subclasses may override this routine to provide different behavior.
1332 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1333 Stmt *Body) {
1334 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1335 }
John McCall990567c2011-07-27 01:07:15 +00001336
Douglas Gregorc3203e72010-04-22 23:10:45 +00001337 /// \brief Build a new Objective-C fast enumeration statement.
1338 ///
1339 /// By default, performs semantic analysis to build the new statement.
1340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001341 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001342 Stmt *Element,
1343 Expr *Collection,
1344 SourceLocation RParenLoc,
1345 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001346 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001347 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001348 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001349 RParenLoc);
1350 if (ForEachStmt.isInvalid())
1351 return StmtError();
1352
1353 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001354 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001355
Douglas Gregor43959a92009-08-20 07:17:43 +00001356 /// \brief Build a new C++ exception declaration.
1357 ///
1358 /// By default, performs semantic analysis to build the new decaration.
1359 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001360 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001361 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001362 SourceLocation StartLoc,
1363 SourceLocation IdLoc,
1364 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001365 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1366 StartLoc, IdLoc, Id);
1367 if (Var)
1368 getSema().CurContext->addDecl(Var);
1369 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001370 }
1371
1372 /// \brief Build a new C++ catch statement.
1373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001376 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001377 VarDecl *ExceptionDecl,
1378 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001379 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1380 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001381 }
Mike Stump1eb44332009-09-09 15:08:12 +00001382
Douglas Gregor43959a92009-08-20 07:17:43 +00001383 /// \brief Build a new C++ try statement.
1384 ///
1385 /// By default, performs semantic analysis to build the new statement.
1386 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001387 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1388 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001389 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001390 }
Mike Stump1eb44332009-09-09 15:08:12 +00001391
Richard Smithad762fc2011-04-14 22:09:26 +00001392 /// \brief Build a new C++0x range-based for statement.
1393 ///
1394 /// By default, performs semantic analysis to build the new statement.
1395 /// Subclasses may override this routine to provide different behavior.
1396 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1397 SourceLocation ColonLoc,
1398 Stmt *Range, Stmt *BeginEnd,
1399 Expr *Cond, Expr *Inc,
1400 Stmt *LoopVar,
1401 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001402 // If we've just learned that the range is actually an Objective-C
1403 // collection, treat this as an Objective-C fast enumeration loop.
1404 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1405 if (RangeStmt->isSingleDecl()) {
1406 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001407 if (RangeVar->isInvalidDecl())
1408 return StmtError();
1409
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001410 Expr *RangeExpr = RangeVar->getInit();
1411 if (!RangeExpr->isTypeDependent() &&
1412 RangeExpr->getType()->isObjCObjectPointerType())
1413 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1414 RParenLoc);
1415 }
1416 }
1417 }
1418
Richard Smithad762fc2011-04-14 22:09:26 +00001419 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001420 Cond, Inc, LoopVar, RParenLoc,
1421 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001422 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001423
1424 /// \brief Build a new C++0x range-based for statement.
1425 ///
1426 /// By default, performs semantic analysis to build the new statement.
1427 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001428 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001429 bool IsIfExists,
1430 NestedNameSpecifierLoc QualifierLoc,
1431 DeclarationNameInfo NameInfo,
1432 Stmt *Nested) {
1433 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1434 QualifierLoc, NameInfo, Nested);
1435 }
1436
Richard Smithad762fc2011-04-14 22:09:26 +00001437 /// \brief Attach body to a C++0x range-based for statement.
1438 ///
1439 /// By default, performs semantic analysis to finish the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
1441 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1442 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1443 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001444
John Wiegley28bbe4b2011-04-28 01:08:34 +00001445 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1446 SourceLocation TryLoc,
1447 Stmt *TryBlock,
1448 Stmt *Handler) {
1449 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1450 }
1451
1452 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1453 Expr *FilterExpr,
1454 Stmt *Block) {
1455 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1456 }
1457
1458 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1459 Stmt *Block) {
1460 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1461 }
1462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// \brief Build a new expression that references a declaration.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001468 LookupResult &R,
1469 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001470 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1471 }
1472
1473
1474 /// \brief Build a new expression that references a declaration.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001478 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001479 ValueDecl *VD,
1480 const DeclarationNameInfo &NameInfo,
1481 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001482 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001483 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001484
1485 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001486
1487 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 }
Mike Stump1eb44332009-09-09 15:08:12 +00001489
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001491 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001494 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 }
1498
Douglas Gregora71d8192009-09-04 17:36:40 +00001499 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001500 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001503 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001504 SourceLocation OperatorLoc,
1505 bool isArrow,
1506 CXXScopeSpec &SS,
1507 TypeSourceInfo *ScopeType,
1508 SourceLocation CCLoc,
1509 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001510 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001517 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001518 Expr *SubExpr) {
1519 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 }
Mike Stump1eb44332009-09-09 15:08:12 +00001521
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001522 /// \brief Build a new builtin offsetof expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001526 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001527 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001528 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001529 unsigned NumComponents,
1530 SourceLocation RParenLoc) {
1531 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1532 NumComponents, RParenLoc);
1533 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001534
1535 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001536 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001537 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001540 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1541 SourceLocation OpLoc,
1542 UnaryExprOrTypeTrait ExprKind,
1543 SourceRange R) {
1544 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 }
1546
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001547 /// \brief Build a new sizeof, alignof or vec step expression with an
1548 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001549 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001552 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1553 UnaryExprOrTypeTrait ExprKind,
1554 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001555 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001556 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001558 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001559
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001560 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 }
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001564 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001567 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001569 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001571 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1572 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 RBracketLoc);
1574 }
1575
1576 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001577 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001582 SourceLocation RParenLoc,
1583 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001585 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 }
1587
1588 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001589 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001592 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001593 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001594 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001595 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001596 const DeclarationNameInfo &MemberNameInfo,
1597 ValueDecl *Member,
1598 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001599 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001600 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001601 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1602 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001603 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001604 // We have a reference to an unnamed field. This is always the
1605 // base of an anonymous struct/union member access, i.e. the
1606 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001607 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001608 assert(Member->getType()->isRecordType() &&
1609 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001610
Richard Smith9138b4e2011-10-26 19:06:56 +00001611 BaseResult =
1612 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001613 QualifierLoc.getNestedNameSpecifier(),
1614 FoundDecl, Member);
1615 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001616 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001617 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001618 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001619 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001620 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001621 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001622 cast<FieldDecl>(Member)->getType(),
1623 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001624 return getSema().Owned(ME);
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001627 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001628 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001629
John Wiegley429bb272011-04-08 18:41:53 +00001630 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001631 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001632
John McCall6bb80172010-03-30 21:47:33 +00001633 // FIXME: this involves duplicating earlier analysis in a lot of
1634 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001635 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001636 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001637 R.resolveKind();
1638
John McCall9ae2f072010-08-23 23:25:46 +00001639 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001640 SS, TemplateKWLoc,
1641 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001642 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 }
Mike Stump1eb44332009-09-09 15:08:12 +00001644
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001646 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001649 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001650 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001651 Expr *LHS, Expr *RHS) {
1652 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 }
1654
1655 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001656 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001660 SourceLocation QuestionLoc,
1661 Expr *LHS,
1662 SourceLocation ColonLoc,
1663 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001664 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1665 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 }
1667
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001669 ///
Douglas Gregorb98b1992009-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.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001673 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001676 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001677 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001681 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001685 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001687 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001688 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
Mike Stump1eb44332009-09-09 15:08:12 +00001691
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001693 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001696 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 SourceLocation OpLoc,
1698 SourceLocation AccessorLoc,
1699 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001700
John McCall129e2df2009-11-30 22:42:35 +00001701 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001702 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001703 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001704 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001705 SS, SourceLocation(),
1706 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001707 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001708 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 }
Mike Stump1eb44332009-09-09 15:08:12 +00001710
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001712 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001715 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001716 MultiExprArg Inits,
1717 SourceLocation RBraceLoc,
1718 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001720 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001721 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001722 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001723
Douglas Gregore48319a2009-11-09 17:16:50 +00001724 // Patch in the result type we were given, which may have been computed
1725 // when the initial InitListExpr was built.
1726 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1727 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001728 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 }
Mike Stump1eb44332009-09-09 15:08:12 +00001730
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001732 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 MultiExprArg ArrayExprs,
1737 SourceLocation EqualOrColonLoc,
1738 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001739 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001742 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001745
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001746 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001750 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// By default, builds the implicit value initialization without performing
1752 /// any semantic analysis. Subclasses may override this routine to provide
1753 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1756 }
Mike Stump1eb44332009-09-09 15:08:12 +00001757
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001759 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001762 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001763 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001764 SourceLocation RParenLoc) {
1765 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001766 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001767 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 }
1769
1770 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001771 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001774 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001775 MultiExprArg SubExprs,
1776 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001777 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 }
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001781 ///
1782 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// rather than attempting to map the label statement itself.
1784 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001785 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001786 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001787 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 }
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001791 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001794 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001795 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001797 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
Mike Stump1eb44332009-09-09 15:08:12 +00001799
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 /// \brief Build a new __builtin_choose_expr expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001804 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001805 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation RParenLoc) {
1807 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 RParenLoc);
1810 }
Mike Stump1eb44332009-09-09 15:08:12 +00001811
Peter Collingbournef111d932011-04-15 00:35:48 +00001812 /// \brief Build a new generic selection expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
1816 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1817 SourceLocation DefaultLoc,
1818 SourceLocation RParenLoc,
1819 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001820 ArrayRef<TypeSourceInfo *> Types,
1821 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001822 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001823 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001824 }
1825
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 /// \brief Build a new overloaded operator call expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// The semantic analysis provides the behavior of template instantiation,
1830 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001831 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 /// argument-dependent lookup, etc. Subclasses may override this routine to
1833 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001836 Expr *Callee,
1837 Expr *First,
1838 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001839
1840 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 /// reinterpret_cast.
1842 ///
1843 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001844 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 Stmt::StmtClass Class,
1848 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001849 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 SourceLocation RAngleLoc,
1851 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001852 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RParenLoc) {
1854 switch (Class) {
1855 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001856 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001857 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001858 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859
1860 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001861 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001862 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001863 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001864
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001866 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001867 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001870
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001872 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001873 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001874 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001877 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 }
Mike Stump1eb44332009-09-09 15:08:12 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 /// \brief Build a new C++ static_cast expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001885 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001887 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RAngleLoc,
1889 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001890 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001892 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001893 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001894 SourceRange(LAngleLoc, RAngleLoc),
1895 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
1897
1898 /// \brief Build a new C++ dynamic_cast expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001902 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001904 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 SourceLocation RAngleLoc,
1906 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001907 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001909 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001910 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001911 SourceRange(LAngleLoc, RAngleLoc),
1912 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 }
1914
1915 /// \brief Build a new C++ reinterpret_cast expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001919 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001921 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 SourceLocation RAngleLoc,
1923 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001924 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001926 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001927 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001928 SourceRange(LAngleLoc, RAngleLoc),
1929 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 }
1931
1932 /// \brief Build a new C++ const_cast expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001936 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001938 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 SourceLocation RAngleLoc,
1940 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001941 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001943 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001944 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001945 SourceRange(LAngleLoc, RAngleLoc),
1946 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
Mike Stump1eb44332009-09-09 15:08:12 +00001948
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 /// \brief Build a new C++ functional-style cast expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001953 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1954 SourceLocation LParenLoc,
1955 Expr *Sub,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001958 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 RParenLoc);
1960 }
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 /// \brief Build a new C++ typeid(type) expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001967 SourceLocation TypeidLoc,
1968 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001970 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001971 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 }
Mike Stump1eb44332009-09-09 15:08:12 +00001973
Francois Pichet01b7c302010-09-08 12:20:18 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 /// \brief Build a new C++ typeid(expr) expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001979 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001980 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001981 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001983 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001984 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001985 }
1986
Francois Pichet01b7c302010-09-08 12:20:18 +00001987 /// \brief Build a new C++ __uuidof(type) expression.
1988 ///
1989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
1991 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1992 SourceLocation TypeidLoc,
1993 TypeSourceInfo *Operand,
1994 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001995 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001996 RParenLoc);
1997 }
1998
1999 /// \brief Build a new C++ __uuidof(expr) expression.
2000 ///
2001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
2003 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2004 SourceLocation TypeidLoc,
2005 Expr *Operand,
2006 SourceLocation RParenLoc) {
2007 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2008 RParenLoc);
2009 }
2010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new C++ "this" expression.
2012 ///
2013 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002014 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002016 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002017 QualType ThisType,
2018 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002019 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002021 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2022 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 }
2024
2025 /// \brief Build a new C++ throw expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002029 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2030 bool IsThrownVariableInScope) {
2031 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 }
2033
2034 /// \brief Build a new C++ default-argument expression.
2035 ///
2036 /// By default, builds a new default-argument expression, which does not
2037 /// require any semantic analysis. Subclasses may override this routine to
2038 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002039 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002040 ParmVarDecl *Param) {
2041 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2042 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 }
2044
Richard Smithc3bf52c2013-04-20 22:23:05 +00002045 /// \brief Build a new C++11 default-initialization expression.
2046 ///
2047 /// By default, builds a new default field initialization expression, which
2048 /// does not require any semantic analysis. Subclasses may override this
2049 /// routine to provide different behavior.
2050 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2051 FieldDecl *Field) {
2052 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2053 Field));
2054 }
2055
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 /// \brief Build a new C++ zero-initialization expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002060 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2061 SourceLocation LParenLoc,
2062 SourceLocation RParenLoc) {
2063 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002064 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002065 }
Mike Stump1eb44332009-09-09 15:08:12 +00002066
Douglas Gregorb98b1992009-08-11 05:31:07 +00002067 /// \brief Build a new C++ "new" expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002071 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002072 bool UseGlobal,
2073 SourceLocation PlacementLParen,
2074 MultiExprArg PlacementArgs,
2075 SourceLocation PlacementRParen,
2076 SourceRange TypeIdParens,
2077 QualType AllocatedType,
2078 TypeSourceInfo *AllocatedTypeInfo,
2079 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002080 SourceRange DirectInitRange,
2081 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002082 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002084 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002085 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002086 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002087 AllocatedType,
2088 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002089 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002090 DirectInitRange,
2091 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002092 }
Mike Stump1eb44332009-09-09 15:08:12 +00002093
Douglas Gregorb98b1992009-08-11 05:31:07 +00002094 /// \brief Build a new C++ "delete" expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002098 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 bool IsGlobalDelete,
2100 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002101 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002102 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002103 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 }
Mike Stump1eb44332009-09-09 15:08:12 +00002105
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 /// \brief Build a new unary type trait expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002111 SourceLocation StartLoc,
2112 TypeSourceInfo *T,
2113 SourceLocation RParenLoc) {
2114 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 }
2116
Francois Pichet6ad6f282010-12-07 00:08:36 +00002117 /// \brief Build a new binary type trait expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
2121 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2122 SourceLocation StartLoc,
2123 TypeSourceInfo *LhsT,
2124 TypeSourceInfo *RhsT,
2125 SourceLocation RParenLoc) {
2126 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2127 }
2128
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002129 /// \brief Build a new type trait expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
2133 ExprResult RebuildTypeTrait(TypeTrait Trait,
2134 SourceLocation StartLoc,
2135 ArrayRef<TypeSourceInfo *> Args,
2136 SourceLocation RParenLoc) {
2137 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2138 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002139
John Wiegley21ff2e52011-04-28 00:16:57 +00002140 /// \brief Build a new array type trait expression.
2141 ///
2142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
2144 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2145 SourceLocation StartLoc,
2146 TypeSourceInfo *TSInfo,
2147 Expr *DimExpr,
2148 SourceLocation RParenLoc) {
2149 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2150 }
2151
John Wiegley55262202011-04-25 06:54:41 +00002152 /// \brief Build a new expression trait expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
2156 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2157 SourceLocation StartLoc,
2158 Expr *Queried,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2161 }
2162
Mike Stump1eb44332009-09-09 15:08:12 +00002163 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 /// expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002168 ExprResult RebuildDependentScopeDeclRefExpr(
2169 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002170 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002171 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002172 const TemplateArgumentListInfo *TemplateArgs,
2173 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002175 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002176
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002177 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002178 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002179 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002180
Richard Smithefeeccf2012-10-21 03:28:35 +00002181 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2182 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 }
2184
2185 /// \brief Build a new template-id expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002189 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002190 SourceLocation TemplateKWLoc,
2191 LookupResult &R,
2192 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002193 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002194 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2195 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 }
2197
2198 /// \brief Build a new object-construction expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002202 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002203 SourceLocation Loc,
2204 CXXConstructorDecl *Constructor,
2205 bool IsElidable,
2206 MultiExprArg Args,
2207 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002208 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002209 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002210 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002211 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002212 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002213 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002214 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002215 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002216
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002217 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002218 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002219 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002220 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002221 RequiresZeroInit, ConstructKind,
2222 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002223 }
2224
2225 /// \brief Build a new object-construction expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002229 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2230 SourceLocation LParenLoc,
2231 MultiExprArg Args,
2232 SourceLocation RParenLoc) {
2233 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002234 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002235 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002236 RParenLoc);
2237 }
2238
2239 /// \brief Build a new object-construction expression.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002243 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2244 SourceLocation LParenLoc,
2245 MultiExprArg Args,
2246 SourceLocation RParenLoc) {
2247 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002248 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002249 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002250 RParenLoc);
2251 }
Mike Stump1eb44332009-09-09 15:08:12 +00002252
Douglas Gregorb98b1992009-08-11 05:31:07 +00002253 /// \brief Build a new member reference expression.
2254 ///
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002257 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002258 QualType BaseType,
2259 bool IsArrow,
2260 SourceLocation OperatorLoc,
2261 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002262 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002263 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002264 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002265 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002267 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002268
John McCall9ae2f072010-08-23 23:25:46 +00002269 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002270 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002271 SS, TemplateKWLoc,
2272 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002273 MemberNameInfo,
2274 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275 }
2276
John McCall129e2df2009-11-30 22:42:35 +00002277 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002278 ///
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002281 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2282 SourceLocation OperatorLoc,
2283 bool IsArrow,
2284 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002285 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002286 NamedDecl *FirstQualifierInScope,
2287 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002288 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002289 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002290 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002291
John McCall9ae2f072010-08-23 23:25:46 +00002292 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002293 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002294 SS, TemplateKWLoc,
2295 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002296 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002297 }
Mike Stump1eb44332009-09-09 15:08:12 +00002298
Sebastian Redl2e156222010-09-10 20:55:43 +00002299 /// \brief Build a new noexcept expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
2303 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2304 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2305 }
2306
Douglas Gregoree8aff02011-01-04 17:33:58 +00002307 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002308 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2309 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002310 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002311 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002312 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002313 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2314 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002315 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002316
2317 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2318 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002319 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002320 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002321
Patrick Beardeb382ec2012-04-19 00:25:12 +00002322 /// \brief Build a new Objective-C boxed expression.
2323 ///
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
2326 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2327 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2328 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002330 /// \brief Build a new Objective-C array literal.
2331 ///
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
2334 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2335 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002336 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002337 MultiExprArg(Elements, NumElements));
2338 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339
2340 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002341 Expr *Base, Expr *Key,
2342 ObjCMethodDecl *getterMethod,
2343 ObjCMethodDecl *setterMethod) {
2344 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2345 getterMethod, setterMethod);
2346 }
2347
2348 /// \brief Build a new Objective-C dictionary literal.
2349 ///
2350 /// By default, performs semantic analysis to build the new expression.
2351 /// Subclasses may override this routine to provide different behavior.
2352 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2353 ObjCDictionaryElement *Elements,
2354 unsigned NumElements) {
2355 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2356 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357
James Dennett699c9042012-06-15 07:13:21 +00002358 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002359 ///
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002362 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002363 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002364 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002365 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002366 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002367 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002368
Douglas Gregor92e986e2010-04-22 16:44:27 +00002369 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002370 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002371 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002372 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002373 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002374 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002375 MultiExprArg Args,
2376 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002377 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2378 ReceiverTypeInfo->getType(),
2379 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002380 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002381 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002382 }
2383
2384 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002385 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002386 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002387 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002388 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002389 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 MultiExprArg Args,
2391 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002392 return SemaRef.BuildInstanceMessage(Receiver,
2393 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002394 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002395 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002396 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002397 }
2398
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002399 /// \brief Build a new Objective-C ivar reference expression.
2400 ///
2401 /// By default, performs semantic analysis to build the new expression.
2402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002403 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 SourceLocation IvarLoc,
2405 bool IsArrow, bool IsFreeIvar) {
2406 // FIXME: We lose track of the IsFreeIvar bit.
2407 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002408 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002409 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2410 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002411 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002413 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002414 false);
John Wiegley429bb272011-04-08 18:41:53 +00002415 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002416 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002417
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002418 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002419 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002420
John Wiegley429bb272011-04-08 18:41:53 +00002421 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002422 /*FIXME:*/IvarLoc, IsArrow,
2423 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002425 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002426 /*TemplateArgs=*/0);
2427 }
Douglas Gregore3303542010-04-26 20:47:02 +00002428
2429 /// \brief Build a new Objective-C property reference expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002433 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002434 ObjCPropertyDecl *Property,
2435 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002436 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002437 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002438 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2439 Sema::LookupMemberName);
2440 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002441 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002442 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002443 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002444 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002445 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446
Douglas Gregore3303542010-04-26 20:47:02 +00002447 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002448 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002449
John Wiegley429bb272011-04-08 18:41:53 +00002450 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002452 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002453 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002455 /*TemplateArgs=*/0);
2456 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002457
John McCall12f78a62010-12-02 01:19:52 +00002458 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002459 ///
2460 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002461 /// Subclasses may override this routine to provide different behavior.
2462 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2463 ObjCMethodDecl *Getter,
2464 ObjCMethodDecl *Setter,
2465 SourceLocation PropertyLoc) {
2466 // Since these expressions can only be value-dependent, we do not
2467 // need to perform semantic analysis again.
2468 return Owned(
2469 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2470 VK_LValue, OK_ObjCProperty,
2471 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002472 }
2473
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002474 /// \brief Build a new Objective-C "isa" expression.
2475 ///
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002478 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002479 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002480 bool IsArrow) {
2481 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002482 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002483 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2484 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002485 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002486 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002487 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002488 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002489 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002490
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002491 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002492 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002493
John Wiegley429bb272011-04-08 18:41:53 +00002494 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002495 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002496 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002497 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002498 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002499 /*TemplateArgs=*/0);
2500 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002501
Douglas Gregorb98b1992009-08-11 05:31:07 +00002502 /// \brief Build a new shuffle vector expression.
2503 ///
2504 /// By default, performs semantic analysis to build the new expression.
2505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002506 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002507 MultiExprArg SubExprs,
2508 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002509 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002510 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002511 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2512 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2513 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002514 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002515
Douglas Gregorb98b1992009-08-11 05:31:07 +00002516 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002517 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002518 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2519 SemaRef.Context.BuiltinFnTy,
2520 VK_RValue, BuiltinLoc);
2521 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2522 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2523 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002524
2525 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002526 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002527 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002528 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002529 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002530 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002531
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002533 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002534 }
John McCall43fed0d2010-11-12 08:19:04 +00002535
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002536 /// \brief Build a new template argument pack expansion.
2537 ///
2538 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002539 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002540 /// different behavior.
2541 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002542 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002543 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002544 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002545 case TemplateArgument::Expression: {
2546 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002547 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2548 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002549 if (Result.isInvalid())
2550 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002551
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002552 return TemplateArgumentLoc(Result.get(), Result.get());
2553 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002554
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002555 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002556 return TemplateArgumentLoc(TemplateArgument(
2557 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002558 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002559 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002560 Pattern.getTemplateNameLoc(),
2561 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002562
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002563 case TemplateArgument::Null:
2564 case TemplateArgument::Integral:
2565 case TemplateArgument::Declaration:
2566 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002567 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002568 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002569 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002570
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002571 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002572 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002573 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002574 EllipsisLoc,
2575 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2577 Expansion);
2578 break;
2579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002580
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002581 return TemplateArgumentLoc();
2582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002584 /// \brief Build a new expression pack expansion.
2585 ///
2586 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002587 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002588 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002589 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002590 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002591 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002592 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002593
2594 /// \brief Build a new atomic operation expression.
2595 ///
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
2598 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2599 MultiExprArg SubExprs,
2600 QualType RetTy,
2601 AtomicExpr::AtomicOp Op,
2602 SourceLocation RParenLoc) {
2603 // Just create the expression; there is not any interesting semantic
2604 // analysis here because we can't actually build an AtomicExpr until
2605 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002606 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002607 RParenLoc);
2608 }
2609
John McCall43fed0d2010-11-12 08:19:04 +00002610private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002611 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2612 QualType ObjectType,
2613 NamedDecl *FirstQualifierInScope,
2614 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002615
2616 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2617 QualType ObjectType,
2618 NamedDecl *FirstQualifierInScope,
2619 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002620};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002621
Douglas Gregor43959a92009-08-20 07:17:43 +00002622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002623StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002624 if (!S)
2625 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002626
Douglas Gregor43959a92009-08-20 07:17:43 +00002627 switch (S->getStmtClass()) {
2628 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002629
Douglas Gregor43959a92009-08-20 07:17:43 +00002630 // Transform individual statement nodes
2631#define STMT(Node, Parent) \
2632 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002633#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002634#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002635#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002636
Douglas Gregor43959a92009-08-20 07:17:43 +00002637 // Transform expressions by calling TransformExpr.
2638#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002639#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002640#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002641#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002642 {
John McCall60d7b3a2010-08-24 06:29:42 +00002643 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002644 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002645 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002646
Richard Smith41956372013-01-14 22:39:08 +00002647 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002648 }
Mike Stump1eb44332009-09-09 15:08:12 +00002649 }
2650
John McCall3fa5cae2010-10-26 07:05:15 +00002651 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002652}
Mike Stump1eb44332009-09-09 15:08:12 +00002653
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002654template<typename Derived>
2655OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2656 if (!S)
2657 return S;
2658
2659 switch (S->getClauseKind()) {
2660 default: break;
2661 // Transform individual clause nodes
2662#define OPENMP_CLAUSE(Name, Class) \
2663 case OMPC_ ## Name : \
2664 return getDerived().Transform ## Class(cast<Class>(S));
2665#include "clang/Basic/OpenMPKinds.def"
2666 }
2667
2668 return S;
2669}
2670
Mike Stump1eb44332009-09-09 15:08:12 +00002671
Douglas Gregor670444e2009-08-04 22:27:00 +00002672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002673ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002674 if (!E)
2675 return SemaRef.Owned(E);
2676
2677 switch (E->getStmtClass()) {
2678 case Stmt::NoStmtClass: break;
2679#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002680#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002681#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002682 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002683#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002684 }
2685
John McCall3fa5cae2010-10-26 07:05:15 +00002686 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002687}
2688
2689template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002690ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2691 bool CXXDirectInit) {
2692 // Initializers are instantiated like expressions, except that various outer
2693 // layers are stripped.
2694 if (!Init)
2695 return SemaRef.Owned(Init);
2696
2697 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2698 Init = ExprTemp->getSubExpr();
2699
Richard Smith858c2c32013-05-30 22:40:16 +00002700 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2701 Init = MTE->GetTemporaryExpr();
2702
Richard Smithc83c2302012-12-19 01:39:02 +00002703 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2704 Init = Binder->getSubExpr();
2705
2706 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2707 Init = ICE->getSubExprAsWritten();
2708
Richard Smith7c3e6152013-06-12 22:31:48 +00002709 if (CXXStdInitializerListExpr *ILE =
2710 dyn_cast<CXXStdInitializerListExpr>(Init))
2711 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2712
Richard Smith5cf15892012-12-21 08:13:35 +00002713 // If this is not a direct-initializer, we only need to reconstruct
2714 // InitListExprs. Other forms of copy-initialization will be a no-op if
2715 // the initializer is already the right type.
2716 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2717 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2718 return getDerived().TransformExpr(Init);
2719
2720 // Revert value-initialization back to empty parens.
2721 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2722 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002723 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002724 Parens.getEnd());
2725 }
2726
2727 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2728 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002729 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002730 SourceLocation());
2731
2732 // Revert initialization by constructor back to a parenthesized or braced list
2733 // of expressions. Any other form of initializer can just be reused directly.
2734 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002735 return getDerived().TransformExpr(Init);
2736
2737 SmallVector<Expr*, 8> NewArgs;
2738 bool ArgChanged = false;
2739 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2740 /*IsCall*/true, NewArgs, &ArgChanged))
2741 return ExprError();
2742
2743 // If this was list initialization, revert to list form.
2744 if (Construct->isListInitialization())
2745 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2746 Construct->getLocEnd(),
2747 Construct->getType());
2748
Richard Smithc83c2302012-12-19 01:39:02 +00002749 // Build a ParenListExpr to represent anything else.
2750 SourceRange Parens = Construct->getParenRange();
2751 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2752 Parens.getEnd());
2753}
2754
2755template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002756bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2757 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002758 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002759 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002760 bool *ArgChanged) {
2761 for (unsigned I = 0; I != NumInputs; ++I) {
2762 // If requested, drop call arguments that need to be dropped.
2763 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2764 if (ArgChanged)
2765 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002766
Douglas Gregoraa165f82011-01-03 19:04:46 +00002767 break;
2768 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002770 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2771 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772
Chris Lattner686775d2011-07-20 06:58:45 +00002773 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002774 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2775 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002777 // Determine whether the set of unexpanded parameter packs can and should
2778 // be expanded.
2779 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002780 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002781 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2782 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002783 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2784 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002785 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002786 Expand, RetainExpansion,
2787 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002788 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002789
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002790 if (!Expand) {
2791 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002792 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002793 // expansion.
2794 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2795 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2796 if (OutPattern.isInvalid())
2797 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
2799 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002800 Expansion->getEllipsisLoc(),
2801 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002802 if (Out.isInvalid())
2803 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002805 if (ArgChanged)
2806 *ArgChanged = true;
2807 Outputs.push_back(Out.get());
2808 continue;
2809 }
John McCallc8fc90a2011-07-06 07:30:07 +00002810
2811 // Record right away that the argument was changed. This needs
2812 // to happen even if the array expands to nothing.
2813 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002814
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002815 // The transform has determined that we should perform an elementwise
2816 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002817 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002818 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2819 ExprResult Out = getDerived().TransformExpr(Pattern);
2820 if (Out.isInvalid())
2821 return true;
2822
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002823 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002824 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2825 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002826 if (Out.isInvalid())
2827 return true;
2828 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002829
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002830 Outputs.push_back(Out.get());
2831 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002833 continue;
2834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002835
Richard Smithc83c2302012-12-19 01:39:02 +00002836 ExprResult Result =
2837 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2838 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002839 if (Result.isInvalid())
2840 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002841
Douglas Gregoraa165f82011-01-03 19:04:46 +00002842 if (Result.get() != Inputs[I] && ArgChanged)
2843 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844
2845 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002846 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002847
Douglas Gregoraa165f82011-01-03 19:04:46 +00002848 return false;
2849}
2850
2851template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002852NestedNameSpecifierLoc
2853TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2854 NestedNameSpecifierLoc NNS,
2855 QualType ObjectType,
2856 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002857 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002859 Qualifier = Qualifier.getPrefix())
2860 Qualifiers.push_back(Qualifier);
2861
2862 CXXScopeSpec SS;
2863 while (!Qualifiers.empty()) {
2864 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2865 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002867 switch (QNNS->getKind()) {
2868 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002870 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002872 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002874 FirstQualifierInScope, false))
2875 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002879 case NestedNameSpecifier::Namespace: {
2880 NamespaceDecl *NS
2881 = cast_or_null<NamespaceDecl>(
2882 getDerived().TransformDecl(
2883 Q.getLocalBeginLoc(),
2884 QNNS->getAsNamespace()));
2885 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2886 break;
2887 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002888
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002889 case NestedNameSpecifier::NamespaceAlias: {
2890 NamespaceAliasDecl *Alias
2891 = cast_or_null<NamespaceAliasDecl>(
2892 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2893 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002894 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002895 Q.getLocalEndLoc());
2896 break;
2897 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 case NestedNameSpecifier::Global:
2900 // There is no meaningful transformation that one could perform on the
2901 // global scope.
2902 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2903 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002904
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002905 case NestedNameSpecifier::TypeSpecWithTemplate:
2906 case NestedNameSpecifier::TypeSpec: {
2907 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2908 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002910 if (!TL)
2911 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002913 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002914 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002915 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002917 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002918 if (TL.getType()->isEnumeralType())
2919 SemaRef.Diag(TL.getBeginLoc(),
2920 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002921 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2922 Q.getLocalEndLoc());
2923 break;
2924 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002925 // If the nested-name-specifier is an invalid type def, don't emit an
2926 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002927 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2928 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002929 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002930 << TL.getType() << SS.getRange();
2931 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002932 return NestedNameSpecifierLoc();
2933 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002934 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002936 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002937 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002938 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002941 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002942 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002943 !getDerived().AlwaysRebuild())
2944 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
2946 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002947 // nested-name-specifier, do so.
2948 if (SS.location_size() == NNS.getDataLength() &&
2949 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2950 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2951
2952 // Allocate new nested-name-specifier location information.
2953 return SS.getWithLocInContext(SemaRef.Context);
2954}
2955
2956template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002957DeclarationNameInfo
2958TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002959::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002960 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002961 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002962 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002963
2964 switch (Name.getNameKind()) {
2965 case DeclarationName::Identifier:
2966 case DeclarationName::ObjCZeroArgSelector:
2967 case DeclarationName::ObjCOneArgSelector:
2968 case DeclarationName::ObjCMultiArgSelector:
2969 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002970 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002971 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002972 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002973
Douglas Gregor81499bb2009-09-03 22:13:48 +00002974 case DeclarationName::CXXConstructorName:
2975 case DeclarationName::CXXDestructorName:
2976 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002977 TypeSourceInfo *NewTInfo;
2978 CanQualType NewCanTy;
2979 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002980 NewTInfo = getDerived().TransformType(OldTInfo);
2981 if (!NewTInfo)
2982 return DeclarationNameInfo();
2983 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002984 }
2985 else {
2986 NewTInfo = 0;
2987 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002988 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002989 if (NewT.isNull())
2990 return DeclarationNameInfo();
2991 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2992 }
Mike Stump1eb44332009-09-09 15:08:12 +00002993
Abramo Bagnara25777432010-08-11 22:01:17 +00002994 DeclarationName NewName
2995 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2996 NewCanTy);
2997 DeclarationNameInfo NewNameInfo(NameInfo);
2998 NewNameInfo.setName(NewName);
2999 NewNameInfo.setNamedTypeInfo(NewTInfo);
3000 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003001 }
Mike Stump1eb44332009-09-09 15:08:12 +00003002 }
3003
David Blaikieb219cfc2011-09-23 05:06:16 +00003004 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003005}
3006
3007template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003008TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003009TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3010 TemplateName Name,
3011 SourceLocation NameLoc,
3012 QualType ObjectType,
3013 NamedDecl *FirstQualifierInScope) {
3014 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3015 TemplateDecl *Template = QTN->getTemplateDecl();
3016 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003017
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003018 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003019 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003020 Template));
3021 if (!TransTemplate)
3022 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003023
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003024 if (!getDerived().AlwaysRebuild() &&
3025 SS.getScopeRep() == QTN->getQualifier() &&
3026 TransTemplate == Template)
3027 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003028
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003029 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3030 TransTemplate);
3031 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003033 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3034 if (SS.getScopeRep()) {
3035 // These apply to the scope specifier, not the template.
3036 ObjectType = QualType();
3037 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003038 }
3039
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003040 if (!getDerived().AlwaysRebuild() &&
3041 SS.getScopeRep() == DTN->getQualifier() &&
3042 ObjectType.isNull())
3043 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003045 if (DTN->isIdentifier()) {
3046 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003048 NameLoc,
3049 ObjectType,
3050 FirstQualifierInScope);
3051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003053 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3054 ObjectType);
3055 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003056
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003057 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3058 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003059 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003060 Template));
3061 if (!TransTemplate)
3062 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003063
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003064 if (!getDerived().AlwaysRebuild() &&
3065 TransTemplate == Template)
3066 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003067
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003068 return TemplateName(TransTemplate);
3069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003071 if (SubstTemplateTemplateParmPackStorage *SubstPack
3072 = Name.getAsSubstTemplateTemplateParmPack()) {
3073 TemplateTemplateParmDecl *TransParam
3074 = cast_or_null<TemplateTemplateParmDecl>(
3075 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3076 if (!TransParam)
3077 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003079 if (!getDerived().AlwaysRebuild() &&
3080 TransParam == SubstPack->getParameterPack())
3081 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003082
3083 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003084 SubstPack->getArgumentPack());
3085 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003086
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003087 // These should be getting filtered out before they reach the AST.
3088 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003089}
3090
3091template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003092void TreeTransform<Derived>::InventTemplateArgumentLoc(
3093 const TemplateArgument &Arg,
3094 TemplateArgumentLoc &Output) {
3095 SourceLocation Loc = getDerived().getBaseLocation();
3096 switch (Arg.getKind()) {
3097 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003098 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003099 break;
3100
3101 case TemplateArgument::Type:
3102 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003103 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
John McCall833ca992009-10-29 08:12:44 +00003105 break;
3106
Douglas Gregor788cd062009-11-11 01:00:40 +00003107 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003108 case TemplateArgument::TemplateExpansion: {
3109 NestedNameSpecifierLocBuilder Builder;
3110 TemplateName Template = Arg.getAsTemplate();
3111 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3112 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3113 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3114 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003116 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003118 Builder.getWithLocInContext(SemaRef.Context),
3119 Loc);
3120 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003122 Builder.getWithLocInContext(SemaRef.Context),
3123 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124
Douglas Gregor788cd062009-11-11 01:00:40 +00003125 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003126 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003127
John McCall833ca992009-10-29 08:12:44 +00003128 case TemplateArgument::Expression:
3129 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3130 break;
3131
3132 case TemplateArgument::Declaration:
3133 case TemplateArgument::Integral:
3134 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003135 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003136 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003137 break;
3138 }
3139}
3140
3141template<typename Derived>
3142bool TreeTransform<Derived>::TransformTemplateArgument(
3143 const TemplateArgumentLoc &Input,
3144 TemplateArgumentLoc &Output) {
3145 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003146 switch (Arg.getKind()) {
3147 case TemplateArgument::Null:
3148 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003149 case TemplateArgument::Pack:
3150 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003151 case TemplateArgument::NullPtr:
3152 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003153
Douglas Gregor670444e2009-08-04 22:27:00 +00003154 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003155 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003156 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003157 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003158
3159 DI = getDerived().TransformType(DI);
3160 if (!DI) return true;
3161
3162 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3163 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003164 }
Mike Stump1eb44332009-09-09 15:08:12 +00003165
Douglas Gregor788cd062009-11-11 01:00:40 +00003166 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003167 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3168 if (QualifierLoc) {
3169 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3170 if (!QualifierLoc)
3171 return true;
3172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173
Douglas Gregor1d752d72011-03-02 18:46:51 +00003174 CXXScopeSpec SS;
3175 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003176 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003177 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3178 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003179 if (Template.isNull())
3180 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003182 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003183 Input.getTemplateNameLoc());
3184 return false;
3185 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003186
3187 case TemplateArgument::TemplateExpansion:
3188 llvm_unreachable("Caller should expand pack expansions");
3189
Douglas Gregor670444e2009-08-04 22:27:00 +00003190 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003191 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003192 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003193 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003194
John McCall833ca992009-10-29 08:12:44 +00003195 Expr *InputExpr = Input.getSourceExpression();
3196 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3197
Chris Lattner223de242011-04-25 20:37:58 +00003198 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003199 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003200 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003201 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003202 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003203 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003204 }
Mike Stump1eb44332009-09-09 15:08:12 +00003205
Douglas Gregor670444e2009-08-04 22:27:00 +00003206 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003207 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003208}
3209
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003210/// \brief Iterator adaptor that invents template argument location information
3211/// for each of the template arguments in its underlying iterator.
3212template<typename Derived, typename InputIterator>
3213class TemplateArgumentLocInventIterator {
3214 TreeTransform<Derived> &Self;
3215 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003217public:
3218 typedef TemplateArgumentLoc value_type;
3219 typedef TemplateArgumentLoc reference;
3220 typedef typename std::iterator_traits<InputIterator>::difference_type
3221 difference_type;
3222 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003223
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003224 class pointer {
3225 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003226
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003227 public:
3228 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003230 const TemplateArgumentLoc *operator->() const { return &Arg; }
3231 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003233 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003235 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3236 InputIterator Iter)
3237 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003239 TemplateArgumentLocInventIterator &operator++() {
3240 ++Iter;
3241 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003244 TemplateArgumentLocInventIterator operator++(int) {
3245 TemplateArgumentLocInventIterator Old(*this);
3246 ++(*this);
3247 return Old;
3248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003249
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003250 reference operator*() const {
3251 TemplateArgumentLoc Result;
3252 Self.InventTemplateArgumentLoc(*Iter, Result);
3253 return Result;
3254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003256 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003258 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3259 const TemplateArgumentLocInventIterator &Y) {
3260 return X.Iter == Y.Iter;
3261 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003262
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003263 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3264 const TemplateArgumentLocInventIterator &Y) {
3265 return X.Iter != Y.Iter;
3266 }
3267};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003269template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003270template<typename InputIterator>
3271bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3272 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003273 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003274 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003275 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003276 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003278 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3279 // Unpack argument packs, which we translate them into separate
3280 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003281 // FIXME: We could do much better if we could guarantee that the
3282 // TemplateArgumentLocInfo for the pack expansion would be usable for
3283 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003285 TemplateArgument::pack_iterator>
3286 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003288 In.getArgument().pack_begin()),
3289 PackLocIterator(*this,
3290 In.getArgument().pack_end()),
3291 Outputs))
3292 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003293
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003294 continue;
3295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003296
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003297 if (In.getArgument().isPackExpansion()) {
3298 // We have a pack expansion, for which we will be substituting into
3299 // the pattern.
3300 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003301 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003302 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003303 = getSema().getTemplateArgumentPackExpansionPattern(
3304 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003305
Chris Lattner686775d2011-07-20 06:58:45 +00003306 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3308 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003310 // Determine whether the set of unexpanded parameter packs can and should
3311 // be expanded.
3312 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003313 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003314 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003315 if (getDerived().TryExpandParameterPacks(Ellipsis,
3316 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003317 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003318 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003319 RetainExpansion,
3320 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003321 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003323 if (!Expand) {
3324 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003325 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003326 // expansion.
3327 TemplateArgumentLoc OutPattern;
3328 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3329 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3330 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331
Douglas Gregorcded4f62011-01-14 17:04:44 +00003332 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3333 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003334 if (Out.getArgument().isNull())
3335 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003336
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003337 Outputs.addArgument(Out);
3338 continue;
3339 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003340
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003341 // The transform has determined that we should perform an elementwise
3342 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003343 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3345
3346 if (getDerived().TransformTemplateArgument(Pattern, Out))
3347 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003348
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003349 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003350 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3351 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003352 if (Out.getArgument().isNull())
3353 return true;
3354 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003355
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003356 Outputs.addArgument(Out);
3357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003359 // If we're supposed to retain a pack expansion, do so by temporarily
3360 // forgetting the partially-substituted parameter pack.
3361 if (RetainExpansion) {
3362 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003363
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003364 if (getDerived().TransformTemplateArgument(Pattern, Out))
3365 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003366
Douglas Gregorcded4f62011-01-14 17:04:44 +00003367 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3368 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003369 if (Out.getArgument().isNull())
3370 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003372 Outputs.addArgument(Out);
3373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003375 continue;
3376 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
3378 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003379 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003380 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003381
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003382 Outputs.addArgument(Out);
3383 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003385 return false;
3386
3387}
3388
Douglas Gregor577f75a2009-08-04 16:50:30 +00003389//===----------------------------------------------------------------------===//
3390// Type transformation
3391//===----------------------------------------------------------------------===//
3392
3393template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003394QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003395 if (getDerived().AlreadyTransformed(T))
3396 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003397
John McCalla2becad2009-10-21 00:40:46 +00003398 // Temporary workaround. All of these transformations should
3399 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003400 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3401 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402
John McCall43fed0d2010-11-12 08:19:04 +00003403 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003404
John McCalla2becad2009-10-21 00:40:46 +00003405 if (!NewDI)
3406 return QualType();
3407
3408 return NewDI->getType();
3409}
3410
3411template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003412TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003413 // Refine the base location to the type's location.
3414 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3415 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003416 if (getDerived().AlreadyTransformed(DI->getType()))
3417 return DI;
3418
3419 TypeLocBuilder TLB;
3420
3421 TypeLoc TL = DI->getTypeLoc();
3422 TLB.reserve(TL.getFullDataSize());
3423
John McCall43fed0d2010-11-12 08:19:04 +00003424 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003425 if (Result.isNull())
3426 return 0;
3427
John McCalla93c9342009-12-07 02:54:59 +00003428 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003429}
3430
3431template<typename Derived>
3432QualType
John McCall43fed0d2010-11-12 08:19:04 +00003433TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003434 switch (T.getTypeLocClass()) {
3435#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003436#define TYPELOC(CLASS, PARENT) \
3437 case TypeLoc::CLASS: \
3438 return getDerived().Transform##CLASS##Type(TLB, \
3439 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003440#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003441 }
Mike Stump1eb44332009-09-09 15:08:12 +00003442
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003443 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003444}
3445
3446/// FIXME: By default, this routine adds type qualifiers only to types
3447/// that can have qualifiers, and silently suppresses those qualifiers
3448/// that are not permitted (e.g., qualifiers on reference or function
3449/// types). This is the right thing for template instantiation, but
3450/// probably not for other clients.
3451template<typename Derived>
3452QualType
3453TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003454 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003455 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003456
John McCall43fed0d2010-11-12 08:19:04 +00003457 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003458 if (Result.isNull())
3459 return QualType();
3460
3461 // Silently suppress qualifiers if the result type can't be qualified.
3462 // FIXME: this is the right thing for template instantiation, but
3463 // probably not for other clients.
3464 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003465 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003466
John McCallf85e1932011-06-15 23:02:42 +00003467 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003468 // resulting type.
3469 if (Quals.hasObjCLifetime()) {
3470 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3471 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003472 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003474 // A lifetime qualifier applied to a substituted template parameter
3475 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003476 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003478 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3479 QualType Replacement = SubstTypeParam->getReplacementType();
3480 Qualifiers Qs = Replacement.getQualifiers();
3481 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003482 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003483 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3484 Qs);
3485 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003486 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003487 Replacement);
3488 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003489 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3490 // 'auto' types behave the same way as template parameters.
3491 QualType Deduced = AutoTy->getDeducedType();
3492 Qualifiers Qs = Deduced.getQualifiers();
3493 Qs.removeObjCLifetime();
3494 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3495 Qs);
Manuel Klimek152b4e42013-08-22 12:12:24 +00003496 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003497 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003498 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003499 // Otherwise, complain about the addition of a qualifier to an
3500 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003501 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003502 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003503 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504
Douglas Gregore559ca12011-06-17 22:11:49 +00003505 Quals.removeObjCLifetime();
3506 }
3507 }
3508 }
John McCall28654742010-06-05 06:41:15 +00003509 if (!Quals.empty()) {
3510 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003511 // BuildQualifiedType might not add qualifiers if they are invalid.
3512 if (Result.hasLocalQualifiers())
3513 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003514 // No location information to preserve.
3515 }
John McCalla2becad2009-10-21 00:40:46 +00003516
3517 return Result;
3518}
3519
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003520template<typename Derived>
3521TypeLoc
3522TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3523 QualType ObjectType,
3524 NamedDecl *UnqualLookup,
3525 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003526 QualType T = TL.getType();
3527 if (getDerived().AlreadyTransformed(T))
3528 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003529
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003530 TypeLocBuilder TLB;
3531 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003532
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003533 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003534 TemplateSpecializationTypeLoc SpecTL =
3535 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003536
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003537 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003538 getDerived().TransformTemplateName(SS,
3539 SpecTL.getTypePtr()->getTemplateName(),
3540 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003541 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003542 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003543 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544
3545 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003546 Template);
3547 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003548 DependentTemplateSpecializationTypeLoc SpecTL =
3549 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
Douglas Gregora88f09f2011-02-28 17:23:35 +00003551 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003552 = getDerived().RebuildTemplateName(SS,
3553 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003554 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003555 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003556 if (Template.isNull())
3557 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003558
3559 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003560 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003561 Template,
3562 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003563 } else {
3564 // Nothing special needs to be done for these.
3565 Result = getDerived().TransformType(TLB, TL);
3566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003567
3568 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003569 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003570
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003571 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3572}
3573
Douglas Gregorb71d8212011-03-02 18:32:08 +00003574template<typename Derived>
3575TypeSourceInfo *
3576TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3577 QualType ObjectType,
3578 NamedDecl *UnqualLookup,
3579 CXXScopeSpec &SS) {
3580 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003581
Douglas Gregorb71d8212011-03-02 18:32:08 +00003582 QualType T = TSInfo->getType();
3583 if (getDerived().AlreadyTransformed(T))
3584 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003585
Douglas Gregorb71d8212011-03-02 18:32:08 +00003586 TypeLocBuilder TLB;
3587 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003588
Douglas Gregorb71d8212011-03-02 18:32:08 +00003589 TypeLoc TL = TSInfo->getTypeLoc();
3590 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003591 TemplateSpecializationTypeLoc SpecTL =
3592 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593
Douglas Gregorb71d8212011-03-02 18:32:08 +00003594 TemplateName Template
3595 = getDerived().TransformTemplateName(SS,
3596 SpecTL.getTypePtr()->getTemplateName(),
3597 SpecTL.getTemplateNameLoc(),
3598 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003599 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003600 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003601
3602 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003603 Template);
3604 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003605 DependentTemplateSpecializationTypeLoc SpecTL =
3606 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003607
Douglas Gregorb71d8212011-03-02 18:32:08 +00003608 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003609 = getDerived().RebuildTemplateName(SS,
3610 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003611 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003612 ObjectType, UnqualLookup);
3613 if (Template.isNull())
3614 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615
3616 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003617 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003618 Template,
3619 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003620 } else {
3621 // Nothing special needs to be done for these.
3622 Result = getDerived().TransformType(TLB, TL);
3623 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003624
3625 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003626 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003627
Douglas Gregorb71d8212011-03-02 18:32:08 +00003628 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3629}
3630
John McCalla2becad2009-10-21 00:40:46 +00003631template <class TyLoc> static inline
3632QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3633 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3634 NewT.setNameLoc(T.getNameLoc());
3635 return T.getType();
3636}
3637
John McCalla2becad2009-10-21 00:40:46 +00003638template<typename Derived>
3639QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003640 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003641 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3642 NewT.setBuiltinLoc(T.getBuiltinLoc());
3643 if (T.needsExtraLocalData())
3644 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3645 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003646}
Mike Stump1eb44332009-09-09 15:08:12 +00003647
Douglas Gregor577f75a2009-08-04 16:50:30 +00003648template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003649QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003650 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003651 // FIXME: recurse?
3652 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003653}
Mike Stump1eb44332009-09-09 15:08:12 +00003654
Douglas Gregor577f75a2009-08-04 16:50:30 +00003655template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003656QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3657 DecayedTypeLoc TL) {
3658 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3659 if (OriginalType.isNull())
3660 return QualType();
3661
3662 QualType Result = TL.getType();
3663 if (getDerived().AlwaysRebuild() ||
3664 OriginalType != TL.getOriginalLoc().getType())
3665 Result = SemaRef.Context.getDecayedType(OriginalType);
3666 TLB.push<DecayedTypeLoc>(Result);
3667 // Nothing to set for DecayedTypeLoc.
3668 return Result;
3669}
3670
3671template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003672QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003673 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003674 QualType PointeeType
3675 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003676 if (PointeeType.isNull())
3677 return QualType();
3678
3679 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003680 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003681 // A dependent pointer type 'T *' has is being transformed such
3682 // that an Objective-C class type is being replaced for 'T'. The
3683 // resulting pointer type is an ObjCObjectPointerType, not a
3684 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003685 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003686
John McCallc12c5bb2010-05-15 11:32:37 +00003687 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3688 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003689 return Result;
3690 }
John McCall43fed0d2010-11-12 08:19:04 +00003691
Douglas Gregor92e986e2010-04-22 16:44:27 +00003692 if (getDerived().AlwaysRebuild() ||
3693 PointeeType != TL.getPointeeLoc().getType()) {
3694 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3695 if (Result.isNull())
3696 return QualType();
3697 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003698
John McCallf85e1932011-06-15 23:02:42 +00003699 // Objective-C ARC can add lifetime qualifiers to the type that we're
3700 // pointing to.
3701 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003702
Douglas Gregor92e986e2010-04-22 16:44:27 +00003703 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3704 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003705 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003706}
Mike Stump1eb44332009-09-09 15:08:12 +00003707
3708template<typename Derived>
3709QualType
John McCalla2becad2009-10-21 00:40:46 +00003710TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003711 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003712 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003713 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3714 if (PointeeType.isNull())
3715 return QualType();
3716
3717 QualType Result = TL.getType();
3718 if (getDerived().AlwaysRebuild() ||
3719 PointeeType != TL.getPointeeLoc().getType()) {
3720 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003721 TL.getSigilLoc());
3722 if (Result.isNull())
3723 return QualType();
3724 }
3725
Douglas Gregor39968ad2010-04-22 16:50:51 +00003726 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003727 NewT.setSigilLoc(TL.getSigilLoc());
3728 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729}
3730
John McCall85737a72009-10-30 00:06:24 +00003731/// Transforms a reference type. Note that somewhat paradoxically we
3732/// don't care whether the type itself is an l-value type or an r-value
3733/// type; we only care if the type was *written* as an l-value type
3734/// or an r-value type.
3735template<typename Derived>
3736QualType
3737TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003738 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003739 const ReferenceType *T = TL.getTypePtr();
3740
3741 // Note that this works with the pointee-as-written.
3742 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3743 if (PointeeType.isNull())
3744 return QualType();
3745
3746 QualType Result = TL.getType();
3747 if (getDerived().AlwaysRebuild() ||
3748 PointeeType != T->getPointeeTypeAsWritten()) {
3749 Result = getDerived().RebuildReferenceType(PointeeType,
3750 T->isSpelledAsLValue(),
3751 TL.getSigilLoc());
3752 if (Result.isNull())
3753 return QualType();
3754 }
3755
John McCallf85e1932011-06-15 23:02:42 +00003756 // Objective-C ARC can add lifetime qualifiers to the type that we're
3757 // referring to.
3758 TLB.TypeWasModifiedSafely(
3759 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3760
John McCall85737a72009-10-30 00:06:24 +00003761 // r-value references can be rebuilt as l-value references.
3762 ReferenceTypeLoc NewTL;
3763 if (isa<LValueReferenceType>(Result))
3764 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3765 else
3766 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3767 NewTL.setSigilLoc(TL.getSigilLoc());
3768
3769 return Result;
3770}
3771
Mike Stump1eb44332009-09-09 15:08:12 +00003772template<typename Derived>
3773QualType
John McCalla2becad2009-10-21 00:40:46 +00003774TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003775 LValueReferenceTypeLoc TL) {
3776 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003777}
3778
Mike Stump1eb44332009-09-09 15:08:12 +00003779template<typename Derived>
3780QualType
John McCalla2becad2009-10-21 00:40:46 +00003781TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003782 RValueReferenceTypeLoc TL) {
3783 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003784}
Mike Stump1eb44332009-09-09 15:08:12 +00003785
Douglas Gregor577f75a2009-08-04 16:50:30 +00003786template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003787QualType
John McCalla2becad2009-10-21 00:40:46 +00003788TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003789 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003790 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003791 if (PointeeType.isNull())
3792 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003793
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003794 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3795 TypeSourceInfo* NewClsTInfo = 0;
3796 if (OldClsTInfo) {
3797 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3798 if (!NewClsTInfo)
3799 return QualType();
3800 }
3801
3802 const MemberPointerType *T = TL.getTypePtr();
3803 QualType OldClsType = QualType(T->getClass(), 0);
3804 QualType NewClsType;
3805 if (NewClsTInfo)
3806 NewClsType = NewClsTInfo->getType();
3807 else {
3808 NewClsType = getDerived().TransformType(OldClsType);
3809 if (NewClsType.isNull())
3810 return QualType();
3811 }
Mike Stump1eb44332009-09-09 15:08:12 +00003812
John McCalla2becad2009-10-21 00:40:46 +00003813 QualType Result = TL.getType();
3814 if (getDerived().AlwaysRebuild() ||
3815 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003816 NewClsType != OldClsType) {
3817 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003818 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003819 if (Result.isNull())
3820 return QualType();
3821 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003822
John McCalla2becad2009-10-21 00:40:46 +00003823 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3824 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003825 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003826
3827 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003828}
3829
Mike Stump1eb44332009-09-09 15:08:12 +00003830template<typename Derived>
3831QualType
John McCalla2becad2009-10-21 00:40:46 +00003832TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003833 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003834 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003835 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003836 if (ElementType.isNull())
3837 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003838
John McCalla2becad2009-10-21 00:40:46 +00003839 QualType Result = TL.getType();
3840 if (getDerived().AlwaysRebuild() ||
3841 ElementType != T->getElementType()) {
3842 Result = getDerived().RebuildConstantArrayType(ElementType,
3843 T->getSizeModifier(),
3844 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003845 T->getIndexTypeCVRQualifiers(),
3846 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003847 if (Result.isNull())
3848 return QualType();
3849 }
Eli Friedman457a3772012-01-25 22:19:07 +00003850
3851 // We might have either a ConstantArrayType or a VariableArrayType now:
3852 // a ConstantArrayType is allowed to have an element type which is a
3853 // VariableArrayType if the type is dependent. Fortunately, all array
3854 // types have the same location layout.
3855 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003856 NewTL.setLBracketLoc(TL.getLBracketLoc());
3857 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003858
John McCalla2becad2009-10-21 00:40:46 +00003859 Expr *Size = TL.getSizeExpr();
3860 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003861 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3862 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003863 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003864 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003865 }
3866 NewTL.setSizeExpr(Size);
3867
3868 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003869}
Mike Stump1eb44332009-09-09 15:08:12 +00003870
Douglas Gregor577f75a2009-08-04 16:50:30 +00003871template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003873 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003874 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003875 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003876 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877 if (ElementType.isNull())
3878 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003879
John McCalla2becad2009-10-21 00:40:46 +00003880 QualType Result = TL.getType();
3881 if (getDerived().AlwaysRebuild() ||
3882 ElementType != T->getElementType()) {
3883 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003884 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003885 T->getIndexTypeCVRQualifiers(),
3886 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003887 if (Result.isNull())
3888 return QualType();
3889 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003890
John McCalla2becad2009-10-21 00:40:46 +00003891 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3892 NewTL.setLBracketLoc(TL.getLBracketLoc());
3893 NewTL.setRBracketLoc(TL.getRBracketLoc());
3894 NewTL.setSizeExpr(0);
3895
3896 return Result;
3897}
3898
3899template<typename Derived>
3900QualType
3901TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003902 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003903 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003904 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3905 if (ElementType.isNull())
3906 return QualType();
3907
John McCall60d7b3a2010-08-24 06:29:42 +00003908 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003909 = getDerived().TransformExpr(T->getSizeExpr());
3910 if (SizeResult.isInvalid())
3911 return QualType();
3912
John McCall9ae2f072010-08-23 23:25:46 +00003913 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003914
3915 QualType Result = TL.getType();
3916 if (getDerived().AlwaysRebuild() ||
3917 ElementType != T->getElementType() ||
3918 Size != T->getSizeExpr()) {
3919 Result = getDerived().RebuildVariableArrayType(ElementType,
3920 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003921 Size,
John McCalla2becad2009-10-21 00:40:46 +00003922 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003923 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003924 if (Result.isNull())
3925 return QualType();
3926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003927
John McCalla2becad2009-10-21 00:40:46 +00003928 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3929 NewTL.setLBracketLoc(TL.getLBracketLoc());
3930 NewTL.setRBracketLoc(TL.getRBracketLoc());
3931 NewTL.setSizeExpr(Size);
3932
3933 return Result;
3934}
3935
3936template<typename Derived>
3937QualType
3938TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003939 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003940 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003941 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3942 if (ElementType.isNull())
3943 return QualType();
3944
Richard Smithf6702a32011-12-20 02:08:33 +00003945 // Array bounds are constant expressions.
3946 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3947 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003948
John McCall3b657512011-01-19 10:06:00 +00003949 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3950 Expr *origSize = TL.getSizeExpr();
3951 if (!origSize) origSize = T->getSizeExpr();
3952
3953 ExprResult sizeResult
3954 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003955 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003956 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003957 return QualType();
3958
John McCall3b657512011-01-19 10:06:00 +00003959 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003960
3961 QualType Result = TL.getType();
3962 if (getDerived().AlwaysRebuild() ||
3963 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003964 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003965 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3966 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003967 size,
John McCalla2becad2009-10-21 00:40:46 +00003968 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003969 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003970 if (Result.isNull())
3971 return QualType();
3972 }
John McCalla2becad2009-10-21 00:40:46 +00003973
3974 // We might have any sort of array type now, but fortunately they
3975 // all have the same location layout.
3976 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3977 NewTL.setLBracketLoc(TL.getLBracketLoc());
3978 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003979 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003980
3981 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003982}
Mike Stump1eb44332009-09-09 15:08:12 +00003983
3984template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003985QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003986 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003987 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003988 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003989
3990 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003991 QualType ElementType = getDerived().TransformType(T->getElementType());
3992 if (ElementType.isNull())
3993 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003994
Richard Smithf6702a32011-12-20 02:08:33 +00003995 // Vector sizes are constant expressions.
3996 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3997 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003998
John McCall60d7b3a2010-08-24 06:29:42 +00003999 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004000 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004001 if (Size.isInvalid())
4002 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004003
John McCalla2becad2009-10-21 00:40:46 +00004004 QualType Result = TL.getType();
4005 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004006 ElementType != T->getElementType() ||
4007 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004008 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004009 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004010 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004011 if (Result.isNull())
4012 return QualType();
4013 }
John McCalla2becad2009-10-21 00:40:46 +00004014
4015 // Result might be dependent or not.
4016 if (isa<DependentSizedExtVectorType>(Result)) {
4017 DependentSizedExtVectorTypeLoc NewTL
4018 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4019 NewTL.setNameLoc(TL.getNameLoc());
4020 } else {
4021 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4022 NewTL.setNameLoc(TL.getNameLoc());
4023 }
4024
4025 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004026}
Mike Stump1eb44332009-09-09 15:08:12 +00004027
4028template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004029QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004030 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004031 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004032 QualType ElementType = getDerived().TransformType(T->getElementType());
4033 if (ElementType.isNull())
4034 return QualType();
4035
John McCalla2becad2009-10-21 00:40:46 +00004036 QualType Result = TL.getType();
4037 if (getDerived().AlwaysRebuild() ||
4038 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004039 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004040 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
4043 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004044
John McCalla2becad2009-10-21 00:40:46 +00004045 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4046 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004047
John McCalla2becad2009-10-21 00:40:46 +00004048 return Result;
4049}
4050
4051template<typename Derived>
4052QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004053 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004054 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004055 QualType ElementType = getDerived().TransformType(T->getElementType());
4056 if (ElementType.isNull())
4057 return QualType();
4058
4059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 ElementType != T->getElementType()) {
4062 Result = getDerived().RebuildExtVectorType(ElementType,
4063 T->getNumElements(),
4064 /*FIXME*/ SourceLocation());
4065 if (Result.isNull())
4066 return QualType();
4067 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068
John McCalla2becad2009-10-21 00:40:46 +00004069 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4070 NewTL.setNameLoc(TL.getNameLoc());
4071
4072 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004073}
Mike Stump1eb44332009-09-09 15:08:12 +00004074
David Blaikiedc84cd52013-02-20 22:23:23 +00004075template <typename Derived>
4076ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4077 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4078 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004079 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004080 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004082 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004084 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004085 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004086 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004088 TypeLocBuilder TLB;
4089 TypeLoc NewTL = OldDI->getTypeLoc();
4090 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004091
4092 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 OldExpansionTL.getPatternLoc());
4094 if (Result.isNull())
4095 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096
4097 Result = RebuildPackExpansionType(Result,
4098 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004099 OldExpansionTL.getEllipsisLoc(),
4100 NumExpansions);
4101 if (Result.isNull())
4102 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004104 PackExpansionTypeLoc NewExpansionTL
4105 = TLB.push<PackExpansionTypeLoc>(Result);
4106 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4107 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4108 } else
4109 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004110 if (!NewDI)
4111 return 0;
4112
John McCallfb44de92011-05-01 22:35:37 +00004113 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004114 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004115
4116 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4117 OldParm->getDeclContext(),
4118 OldParm->getInnerLocStart(),
4119 OldParm->getLocation(),
4120 OldParm->getIdentifier(),
4121 NewDI->getType(),
4122 NewDI,
4123 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004124 /* DefArg */ NULL);
4125 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4126 OldParm->getFunctionScopeIndex() + indexAdjustment);
4127 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004128}
4129
4130template<typename Derived>
4131bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004132 TransformFunctionTypeParams(SourceLocation Loc,
4133 ParmVarDecl **Params, unsigned NumParams,
4134 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004135 SmallVectorImpl<QualType> &OutParamTypes,
4136 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004137 int indexAdjustment = 0;
4138
Douglas Gregora009b592011-01-07 00:20:55 +00004139 for (unsigned i = 0; i != NumParams; ++i) {
4140 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004141 assert(OldParm->getFunctionScopeIndex() == i);
4142
David Blaikiedc84cd52013-02-20 22:23:23 +00004143 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004144 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 if (OldParm->isParameterPack()) {
4146 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004147 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004148
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004150 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004151 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004152 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4153 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004154 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4155
Douglas Gregor603cfb42011-01-05 23:12:31 +00004156 // Determine whether we should expand the parameter packs.
4157 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004158 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004159 Optional<unsigned> OrigNumExpansions =
4160 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004161 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004162 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4163 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164 Unexpanded,
4165 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004166 RetainExpansion,
4167 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 return true;
4169 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004170
Douglas Gregor603cfb42011-01-05 23:12:31 +00004171 if (ShouldExpand) {
4172 // Expand the function parameter pack into multiple, separate
4173 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004174 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004175 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004177 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004178 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004179 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004180 OrigNumExpansions,
4181 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004182 if (!NewParm)
4183 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004184
Douglas Gregora009b592011-01-07 00:20:55 +00004185 OutParamTypes.push_back(NewParm->getType());
4186 if (PVars)
4187 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004188 }
Douglas Gregord3731192011-01-10 07:32:04 +00004189
4190 // If we're supposed to retain a pack expansion, do so by temporarily
4191 // forgetting the partially-substituted parameter pack.
4192 if (RetainExpansion) {
4193 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004195 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004196 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004197 OrigNumExpansions,
4198 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004199 if (!NewParm)
4200 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004201
Douglas Gregord3731192011-01-10 07:32:04 +00004202 OutParamTypes.push_back(NewParm->getType());
4203 if (PVars)
4204 PVars->push_back(NewParm);
4205 }
4206
John McCallfb44de92011-05-01 22:35:37 +00004207 // The next parameter should have the same adjustment as the
4208 // last thing we pushed, but we post-incremented indexAdjustment
4209 // on every push. Also, if we push nothing, the adjustment should
4210 // go down by one.
4211 indexAdjustment--;
4212
Douglas Gregor603cfb42011-01-05 23:12:31 +00004213 // We're done with the pack expansion.
4214 continue;
4215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004216
4217 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4220 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004221 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004222 NumExpansions,
4223 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004224 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004225 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004226 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004227 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004228
John McCall21ef0fa2010-03-11 09:03:00 +00004229 if (!NewParm)
4230 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004231
Douglas Gregora009b592011-01-07 00:20:55 +00004232 OutParamTypes.push_back(NewParm->getType());
4233 if (PVars)
4234 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004235 continue;
4236 }
John McCall21ef0fa2010-03-11 09:03:00 +00004237
4238 // Deal with the possibility that we don't have a parameter
4239 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004240 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004241 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004242 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004243 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004244 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004245 = dyn_cast<PackExpansionType>(OldType)) {
4246 // We have a function parameter pack that may need to be expanded.
4247 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004248 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004249 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004250
Douglas Gregor603cfb42011-01-05 23:12:31 +00004251 // Determine whether we should expand the parameter packs.
4252 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004253 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004254 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255 Unexpanded,
4256 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004257 RetainExpansion,
4258 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004259 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004260 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004261
Douglas Gregor603cfb42011-01-05 23:12:31 +00004262 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004263 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004264 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004265 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004266 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4267 QualType NewType = getDerived().TransformType(Pattern);
4268 if (NewType.isNull())
4269 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004270
Douglas Gregora009b592011-01-07 00:20:55 +00004271 OutParamTypes.push_back(NewType);
4272 if (PVars)
4273 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004275
Douglas Gregor603cfb42011-01-05 23:12:31 +00004276 // We're done with the pack expansion.
4277 continue;
4278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004279
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004280 // If we're supposed to retain a pack expansion, do so by temporarily
4281 // forgetting the partially-substituted parameter pack.
4282 if (RetainExpansion) {
4283 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4284 QualType NewType = getDerived().TransformType(Pattern);
4285 if (NewType.isNull())
4286 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004287
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004288 OutParamTypes.push_back(NewType);
4289 if (PVars)
4290 PVars->push_back(0);
4291 }
Douglas Gregord3731192011-01-10 07:32:04 +00004292
Chad Rosier4a9d7952012-08-08 18:46:20 +00004293 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004294 // expansion.
4295 OldType = Expansion->getPattern();
4296 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004297 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4298 NewType = getDerived().TransformType(OldType);
4299 } else {
4300 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004302
Douglas Gregor603cfb42011-01-05 23:12:31 +00004303 if (NewType.isNull())
4304 return true;
4305
4306 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004307 NewType = getSema().Context.getPackExpansionType(NewType,
4308 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004309
Douglas Gregora009b592011-01-07 00:20:55 +00004310 OutParamTypes.push_back(NewType);
4311 if (PVars)
4312 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004313 }
4314
John McCallfb44de92011-05-01 22:35:37 +00004315#ifndef NDEBUG
4316 if (PVars) {
4317 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4318 if (ParmVarDecl *parm = (*PVars)[i])
4319 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004320 }
John McCallfb44de92011-05-01 22:35:37 +00004321#endif
4322
4323 return false;
4324}
John McCall21ef0fa2010-03-11 09:03:00 +00004325
4326template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004327QualType
John McCalla2becad2009-10-21 00:40:46 +00004328TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004329 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004330 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4331}
4332
4333template<typename Derived>
4334QualType
4335TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4336 FunctionProtoTypeLoc TL,
4337 CXXRecordDecl *ThisContext,
4338 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004339 // Transform the parameters and return type.
4340 //
Richard Smithe6975e92012-04-17 00:58:00 +00004341 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004342 // When the function has a trailing return type, we instantiate the
4343 // parameters before the return type, since the return type can then refer
4344 // to the parameters themselves (via decltype, sizeof, etc.).
4345 //
Chris Lattner686775d2011-07-20 06:58:45 +00004346 SmallVector<QualType, 4> ParamTypes;
4347 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004348 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004349
Douglas Gregordab60ad2010-10-01 18:44:50 +00004350 QualType ResultType;
4351
Richard Smith9fbf3272012-08-14 22:51:13 +00004352 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004353 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004354 TL.getParmArray(),
4355 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004356 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004357 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004358 return QualType();
4359
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004360 {
4361 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004362 // If a declaration declares a member function or member function
4363 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004364 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004365 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004366 // declarator.
4367 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004368
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004369 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4370 if (ResultType.isNull())
4371 return QualType();
4372 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004373 }
4374 else {
4375 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4376 if (ResultType.isNull())
4377 return QualType();
4378
Chad Rosier4a9d7952012-08-08 18:46:20 +00004379 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004380 TL.getParmArray(),
4381 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004382 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004383 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004384 return QualType();
4385 }
4386
Richard Smithe6975e92012-04-17 00:58:00 +00004387 // FIXME: Need to transform the exception-specification too.
4388
John McCalla2becad2009-10-21 00:40:46 +00004389 QualType Result = TL.getType();
4390 if (getDerived().AlwaysRebuild() ||
4391 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004392 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004393 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004394 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004395 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004396 if (Result.isNull())
4397 return QualType();
4398 }
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCalla2becad2009-10-21 00:40:46 +00004400 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004401 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004402 NewTL.setLParenLoc(TL.getLParenLoc());
4403 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004404 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004405 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4406 NewTL.setArg(i, ParamDecls[i]);
4407
4408 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004409}
Mike Stump1eb44332009-09-09 15:08:12 +00004410
Douglas Gregor577f75a2009-08-04 16:50:30 +00004411template<typename Derived>
4412QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004413 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004414 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004415 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004416 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4417 if (ResultType.isNull())
4418 return QualType();
4419
4420 QualType Result = TL.getType();
4421 if (getDerived().AlwaysRebuild() ||
4422 ResultType != T->getResultType())
4423 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4424
4425 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004426 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004427 NewTL.setLParenLoc(TL.getLParenLoc());
4428 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004429 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004430
4431 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004432}
Mike Stump1eb44332009-09-09 15:08:12 +00004433
John McCalled976492009-12-04 22:46:56 +00004434template<typename Derived> QualType
4435TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004436 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004437 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004438 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004439 if (!D)
4440 return QualType();
4441
4442 QualType Result = TL.getType();
4443 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4444 Result = getDerived().RebuildUnresolvedUsingType(D);
4445 if (Result.isNull())
4446 return QualType();
4447 }
4448
4449 // We might get an arbitrary type spec type back. We should at
4450 // least always get a type spec type, though.
4451 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4452 NewTL.setNameLoc(TL.getNameLoc());
4453
4454 return Result;
4455}
4456
Douglas Gregor577f75a2009-08-04 16:50:30 +00004457template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004458QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004459 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004460 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004461 TypedefNameDecl *Typedef
4462 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4463 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004464 if (!Typedef)
4465 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004466
John McCalla2becad2009-10-21 00:40:46 +00004467 QualType Result = TL.getType();
4468 if (getDerived().AlwaysRebuild() ||
4469 Typedef != T->getDecl()) {
4470 Result = getDerived().RebuildTypedefType(Typedef);
4471 if (Result.isNull())
4472 return QualType();
4473 }
Mike Stump1eb44332009-09-09 15:08:12 +00004474
John McCalla2becad2009-10-21 00:40:46 +00004475 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4476 NewTL.setNameLoc(TL.getNameLoc());
4477
4478 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004479}
Mike Stump1eb44332009-09-09 15:08:12 +00004480
Douglas Gregor577f75a2009-08-04 16:50:30 +00004481template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004482QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004483 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004484 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004485 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4486 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCall60d7b3a2010-08-24 06:29:42 +00004488 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004489 if (E.isInvalid())
4490 return QualType();
4491
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004492 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4493 if (E.isInvalid())
4494 return QualType();
4495
John McCalla2becad2009-10-21 00:40:46 +00004496 QualType Result = TL.getType();
4497 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004498 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004499 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004500 if (Result.isNull())
4501 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 }
John McCalla2becad2009-10-21 00:40:46 +00004503 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004506 NewTL.setTypeofLoc(TL.getTypeofLoc());
4507 NewTL.setLParenLoc(TL.getLParenLoc());
4508 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004509
4510 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004511}
Mike Stump1eb44332009-09-09 15:08:12 +00004512
4513template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004514QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004515 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004516 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4517 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4518 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004520
John McCalla2becad2009-10-21 00:40:46 +00004521 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004522 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4523 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004524 if (Result.isNull())
4525 return QualType();
4526 }
Mike Stump1eb44332009-09-09 15:08:12 +00004527
John McCalla2becad2009-10-21 00:40:46 +00004528 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004529 NewTL.setTypeofLoc(TL.getTypeofLoc());
4530 NewTL.setLParenLoc(TL.getLParenLoc());
4531 NewTL.setRParenLoc(TL.getRParenLoc());
4532 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004533
4534 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535}
Mike Stump1eb44332009-09-09 15:08:12 +00004536
4537template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004538QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004539 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004540 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004541
Douglas Gregor670444e2009-08-04 22:27:00 +00004542 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004543 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4544 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004545
John McCall60d7b3a2010-08-24 06:29:42 +00004546 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004547 if (E.isInvalid())
4548 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004549
Richard Smith76f3f692012-02-22 02:04:18 +00004550 E = getSema().ActOnDecltypeExpression(E.take());
4551 if (E.isInvalid())
4552 return QualType();
4553
John McCalla2becad2009-10-21 00:40:46 +00004554 QualType Result = TL.getType();
4555 if (getDerived().AlwaysRebuild() ||
4556 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004557 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004558 if (Result.isNull())
4559 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004560 }
John McCalla2becad2009-10-21 00:40:46 +00004561 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004562
John McCalla2becad2009-10-21 00:40:46 +00004563 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4564 NewTL.setNameLoc(TL.getNameLoc());
4565
4566 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004567}
4568
4569template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004570QualType TreeTransform<Derived>::TransformUnaryTransformType(
4571 TypeLocBuilder &TLB,
4572 UnaryTransformTypeLoc TL) {
4573 QualType Result = TL.getType();
4574 if (Result->isDependentType()) {
4575 const UnaryTransformType *T = TL.getTypePtr();
4576 QualType NewBase =
4577 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4578 Result = getDerived().RebuildUnaryTransformType(NewBase,
4579 T->getUTTKind(),
4580 TL.getKWLoc());
4581 if (Result.isNull())
4582 return QualType();
4583 }
4584
4585 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4586 NewTL.setKWLoc(TL.getKWLoc());
4587 NewTL.setParensRange(TL.getParensRange());
4588 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4589 return Result;
4590}
4591
4592template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004593QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4594 AutoTypeLoc TL) {
4595 const AutoType *T = TL.getTypePtr();
4596 QualType OldDeduced = T->getDeducedType();
4597 QualType NewDeduced;
4598 if (!OldDeduced.isNull()) {
4599 NewDeduced = getDerived().TransformType(OldDeduced);
4600 if (NewDeduced.isNull())
4601 return QualType();
4602 }
4603
4604 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004605 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4606 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004607 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004608 if (Result.isNull())
4609 return QualType();
4610 }
4611
4612 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4613 NewTL.setNameLoc(TL.getNameLoc());
4614
4615 return Result;
4616}
4617
4618template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004619QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004620 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004621 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004622 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004623 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4624 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004625 if (!Record)
4626 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004627
John McCalla2becad2009-10-21 00:40:46 +00004628 QualType Result = TL.getType();
4629 if (getDerived().AlwaysRebuild() ||
4630 Record != T->getDecl()) {
4631 Result = getDerived().RebuildRecordType(Record);
4632 if (Result.isNull())
4633 return QualType();
4634 }
Mike Stump1eb44332009-09-09 15:08:12 +00004635
John McCalla2becad2009-10-21 00:40:46 +00004636 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4637 NewTL.setNameLoc(TL.getNameLoc());
4638
4639 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004640}
Mike Stump1eb44332009-09-09 15:08:12 +00004641
4642template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004643QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004644 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004645 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004646 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004647 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4648 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004649 if (!Enum)
4650 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004651
John McCalla2becad2009-10-21 00:40:46 +00004652 QualType Result = TL.getType();
4653 if (getDerived().AlwaysRebuild() ||
4654 Enum != T->getDecl()) {
4655 Result = getDerived().RebuildEnumType(Enum);
4656 if (Result.isNull())
4657 return QualType();
4658 }
Mike Stump1eb44332009-09-09 15:08:12 +00004659
John McCalla2becad2009-10-21 00:40:46 +00004660 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4661 NewTL.setNameLoc(TL.getNameLoc());
4662
4663 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004664}
John McCall7da24312009-09-05 00:15:47 +00004665
John McCall3cb0ebd2010-03-10 03:28:59 +00004666template<typename Derived>
4667QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4668 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004669 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004670 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4671 TL.getTypePtr()->getDecl());
4672 if (!D) return QualType();
4673
4674 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4675 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4676 return T;
4677}
4678
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679template<typename Derived>
4680QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004681 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004682 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004683 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004684}
4685
Mike Stump1eb44332009-09-09 15:08:12 +00004686template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004687QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004688 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004689 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004690 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004691
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004692 // Substitute into the replacement type, which itself might involve something
4693 // that needs to be transformed. This only tends to occur with default
4694 // template arguments of template template parameters.
4695 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4696 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4697 if (Replacement.isNull())
4698 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004699
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004700 // Always canonicalize the replacement type.
4701 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4702 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004703 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004704 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004705
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004706 // Propagate type-source information.
4707 SubstTemplateTypeParmTypeLoc NewTL
4708 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4709 NewTL.setNameLoc(TL.getNameLoc());
4710 return Result;
4711
John McCall49a832b2009-10-18 09:09:24 +00004712}
4713
4714template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004715QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4716 TypeLocBuilder &TLB,
4717 SubstTemplateTypeParmPackTypeLoc TL) {
4718 return TransformTypeSpecType(TLB, TL);
4719}
4720
4721template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004722QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004723 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004724 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004725 const TemplateSpecializationType *T = TL.getTypePtr();
4726
Douglas Gregor1d752d72011-03-02 18:46:51 +00004727 // The nested-name-specifier never matters in a TemplateSpecializationType,
4728 // because we can't have a dependent nested-name-specifier anyway.
4729 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004730 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004731 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4732 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004733 if (Template.isNull())
4734 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004735
John McCall43fed0d2010-11-12 08:19:04 +00004736 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4737}
4738
Eli Friedmanb001de72011-10-06 23:00:33 +00004739template<typename Derived>
4740QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4741 AtomicTypeLoc TL) {
4742 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4743 if (ValueType.isNull())
4744 return QualType();
4745
4746 QualType Result = TL.getType();
4747 if (getDerived().AlwaysRebuild() ||
4748 ValueType != TL.getValueLoc().getType()) {
4749 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4750 if (Result.isNull())
4751 return QualType();
4752 }
4753
4754 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4755 NewTL.setKWLoc(TL.getKWLoc());
4756 NewTL.setLParenLoc(TL.getLParenLoc());
4757 NewTL.setRParenLoc(TL.getRParenLoc());
4758
4759 return Result;
4760}
4761
Chad Rosier4a9d7952012-08-08 18:46:20 +00004762 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004763 /// container that provides a \c getArgLoc() member function.
4764 ///
4765 /// This iterator is intended to be used with the iterator form of
4766 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4767 template<typename ArgLocContainer>
4768 class TemplateArgumentLocContainerIterator {
4769 ArgLocContainer *Container;
4770 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004771
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004772 public:
4773 typedef TemplateArgumentLoc value_type;
4774 typedef TemplateArgumentLoc reference;
4775 typedef int difference_type;
4776 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004777
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004778 class pointer {
4779 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004780
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004781 public:
4782 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004783
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004784 const TemplateArgumentLoc *operator->() const {
4785 return &Arg;
4786 }
4787 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004788
4789
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004790 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004791
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004792 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4793 unsigned Index)
4794 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004795
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004796 TemplateArgumentLocContainerIterator &operator++() {
4797 ++Index;
4798 return *this;
4799 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004801 TemplateArgumentLocContainerIterator operator++(int) {
4802 TemplateArgumentLocContainerIterator Old(*this);
4803 ++(*this);
4804 return Old;
4805 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004807 TemplateArgumentLoc operator*() const {
4808 return Container->getArgLoc(Index);
4809 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004811 pointer operator->() const {
4812 return pointer(Container->getArgLoc(Index));
4813 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004814
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004815 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004816 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004817 return X.Container == Y.Container && X.Index == Y.Index;
4818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004821 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 return !(X == Y);
4823 }
4824 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
4826
John McCall43fed0d2010-11-12 08:19:04 +00004827template <typename Derived>
4828QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4829 TypeLocBuilder &TLB,
4830 TemplateSpecializationTypeLoc TL,
4831 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004832 TemplateArgumentListInfo NewTemplateArgs;
4833 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4834 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004835 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4836 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004838 ArgIterator(TL, TL.getNumArgs()),
4839 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004841
John McCall833ca992009-10-29 08:12:44 +00004842 // FIXME: maybe don't rebuild if all the template arguments are the same.
4843
4844 QualType Result =
4845 getDerived().RebuildTemplateSpecializationType(Template,
4846 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004847 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004848
4849 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004850 // Specializations of template template parameters are represented as
4851 // TemplateSpecializationTypes, and substitution of type alias templates
4852 // within a dependent context can transform them into
4853 // DependentTemplateSpecializationTypes.
4854 if (isa<DependentTemplateSpecializationType>(Result)) {
4855 DependentTemplateSpecializationTypeLoc NewTL
4856 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004857 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004858 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004859 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004860 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004861 NewTL.setLAngleLoc(TL.getLAngleLoc());
4862 NewTL.setRAngleLoc(TL.getRAngleLoc());
4863 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4864 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4865 return Result;
4866 }
4867
John McCall833ca992009-10-29 08:12:44 +00004868 TemplateSpecializationTypeLoc NewTL
4869 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004870 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004871 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4872 NewTL.setLAngleLoc(TL.getLAngleLoc());
4873 NewTL.setRAngleLoc(TL.getRAngleLoc());
4874 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4875 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004876 }
Mike Stump1eb44332009-09-09 15:08:12 +00004877
John McCall833ca992009-10-29 08:12:44 +00004878 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004879}
Mike Stump1eb44332009-09-09 15:08:12 +00004880
Douglas Gregora88f09f2011-02-28 17:23:35 +00004881template <typename Derived>
4882QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4883 TypeLocBuilder &TLB,
4884 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004885 TemplateName Template,
4886 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004887 TemplateArgumentListInfo NewTemplateArgs;
4888 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4889 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4890 typedef TemplateArgumentLocContainerIterator<
4891 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004892 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004893 ArgIterator(TL, TL.getNumArgs()),
4894 NewTemplateArgs))
4895 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004896
Douglas Gregora88f09f2011-02-28 17:23:35 +00004897 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004898
Douglas Gregora88f09f2011-02-28 17:23:35 +00004899 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4900 QualType Result
4901 = getSema().Context.getDependentTemplateSpecializationType(
4902 TL.getTypePtr()->getKeyword(),
4903 DTN->getQualifier(),
4904 DTN->getIdentifier(),
4905 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004906
Douglas Gregora88f09f2011-02-28 17:23:35 +00004907 DependentTemplateSpecializationTypeLoc NewTL
4908 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004909 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004910 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004911 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004912 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004913 NewTL.setLAngleLoc(TL.getLAngleLoc());
4914 NewTL.setRAngleLoc(TL.getRAngleLoc());
4915 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4916 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4917 return Result;
4918 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004919
4920 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004921 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004922 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004923 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004924
Douglas Gregora88f09f2011-02-28 17:23:35 +00004925 if (!Result.isNull()) {
4926 /// FIXME: Wrap this in an elaborated-type-specifier?
4927 TemplateSpecializationTypeLoc NewTL
4928 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004929 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004930 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004931 NewTL.setLAngleLoc(TL.getLAngleLoc());
4932 NewTL.setRAngleLoc(TL.getRAngleLoc());
4933 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4934 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4935 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004936
Douglas Gregora88f09f2011-02-28 17:23:35 +00004937 return Result;
4938}
4939
Mike Stump1eb44332009-09-09 15:08:12 +00004940template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004941QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004942TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004943 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004944 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004945
Douglas Gregor9e876872011-03-01 18:12:44 +00004946 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004947 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004948 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004950 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4951 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004952 return QualType();
4953 }
Mike Stump1eb44332009-09-09 15:08:12 +00004954
John McCall43fed0d2010-11-12 08:19:04 +00004955 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4956 if (NamedT.isNull())
4957 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004958
Richard Smith3e4c6c42011-05-05 21:57:07 +00004959 // C++0x [dcl.type.elab]p2:
4960 // If the identifier resolves to a typedef-name or the simple-template-id
4961 // resolves to an alias template specialization, the
4962 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004963 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4964 if (const TemplateSpecializationType *TST =
4965 NamedT->getAs<TemplateSpecializationType>()) {
4966 TemplateName Template = TST->getTemplateName();
4967 if (TypeAliasTemplateDecl *TAT =
4968 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4969 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4970 diag::err_tag_reference_non_tag) << 4;
4971 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4972 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004973 }
4974 }
4975
John McCalla2becad2009-10-21 00:40:46 +00004976 QualType Result = TL.getType();
4977 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004978 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004979 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004980 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004981 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004982 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004983 if (Result.isNull())
4984 return QualType();
4985 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004986
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004987 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004988 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004989 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004990 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004991}
Mike Stump1eb44332009-09-09 15:08:12 +00004992
4993template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004994QualType TreeTransform<Derived>::TransformAttributedType(
4995 TypeLocBuilder &TLB,
4996 AttributedTypeLoc TL) {
4997 const AttributedType *oldType = TL.getTypePtr();
4998 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4999 if (modifiedType.isNull())
5000 return QualType();
5001
5002 QualType result = TL.getType();
5003
5004 // FIXME: dependent operand expressions?
5005 if (getDerived().AlwaysRebuild() ||
5006 modifiedType != oldType->getModifiedType()) {
5007 // TODO: this is really lame; we should really be rebuilding the
5008 // equivalent type from first principles.
5009 QualType equivalentType
5010 = getDerived().TransformType(oldType->getEquivalentType());
5011 if (equivalentType.isNull())
5012 return QualType();
5013 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5014 modifiedType,
5015 equivalentType);
5016 }
5017
5018 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5019 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5020 if (TL.hasAttrOperand())
5021 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5022 if (TL.hasAttrExprOperand())
5023 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5024 else if (TL.hasAttrEnumOperand())
5025 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5026
5027 return result;
5028}
5029
5030template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005031QualType
5032TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5033 ParenTypeLoc TL) {
5034 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5035 if (Inner.isNull())
5036 return QualType();
5037
5038 QualType Result = TL.getType();
5039 if (getDerived().AlwaysRebuild() ||
5040 Inner != TL.getInnerLoc().getType()) {
5041 Result = getDerived().RebuildParenType(Inner);
5042 if (Result.isNull())
5043 return QualType();
5044 }
5045
5046 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5047 NewTL.setLParenLoc(TL.getLParenLoc());
5048 NewTL.setRParenLoc(TL.getRParenLoc());
5049 return Result;
5050}
5051
5052template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005053QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005054 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005055 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005056
Douglas Gregor2494dd02011-03-01 01:34:45 +00005057 NestedNameSpecifierLoc QualifierLoc
5058 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5059 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005060 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005061
John McCall33500952010-06-11 00:33:02 +00005062 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005063 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005064 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005065 QualifierLoc,
5066 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005067 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005068 if (Result.isNull())
5069 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005070
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005071 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5072 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005073 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5074
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005075 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005076 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005077 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005078 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005079 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005080 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005081 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005082 NewTL.setNameLoc(TL.getNameLoc());
5083 }
John McCalla2becad2009-10-21 00:40:46 +00005084 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005085}
Mike Stump1eb44332009-09-09 15:08:12 +00005086
Douglas Gregor577f75a2009-08-04 16:50:30 +00005087template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005088QualType TreeTransform<Derived>::
5089 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005090 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005091 NestedNameSpecifierLoc QualifierLoc;
5092 if (TL.getQualifierLoc()) {
5093 QualifierLoc
5094 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5095 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005096 return QualType();
5097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005098
John McCall43fed0d2010-11-12 08:19:04 +00005099 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005100 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005101}
5102
5103template<typename Derived>
5104QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005105TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5106 DependentTemplateSpecializationTypeLoc TL,
5107 NestedNameSpecifierLoc QualifierLoc) {
5108 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005109
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005110 TemplateArgumentListInfo NewTemplateArgs;
5111 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5112 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005113
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005114 typedef TemplateArgumentLocContainerIterator<
5115 DependentTemplateSpecializationTypeLoc> ArgIterator;
5116 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5117 ArgIterator(TL, TL.getNumArgs()),
5118 NewTemplateArgs))
5119 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005120
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005121 QualType Result
5122 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5123 QualifierLoc,
5124 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005125 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005126 NewTemplateArgs);
5127 if (Result.isNull())
5128 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005129
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005130 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5131 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005132
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005133 // Copy information relevant to the template specialization.
5134 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005135 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005136 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005137 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005138 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5139 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005140 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005141 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005142
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005143 // Copy information relevant to the elaborated type.
5144 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005145 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005146 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005147 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5148 DependentTemplateSpecializationTypeLoc SpecTL
5149 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005150 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005151 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005152 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005153 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005154 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5155 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005156 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005157 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005158 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005159 TemplateSpecializationTypeLoc SpecTL
5160 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005161 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005162 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005163 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5164 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005165 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005166 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005167 }
5168 return Result;
5169}
5170
5171template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005172QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5173 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005174 QualType Pattern
5175 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005176 if (Pattern.isNull())
5177 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005178
5179 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005180 if (getDerived().AlwaysRebuild() ||
5181 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005182 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005183 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005184 TL.getEllipsisLoc(),
5185 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005186 if (Result.isNull())
5187 return QualType();
5188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005189
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005190 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5191 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5192 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005193}
5194
5195template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005196QualType
5197TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005198 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005199 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005200 TLB.pushFullCopy(TL);
5201 return TL.getType();
5202}
5203
5204template<typename Derived>
5205QualType
5206TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005207 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005208 // ObjCObjectType is never dependent.
5209 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005210 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005211}
Mike Stump1eb44332009-09-09 15:08:12 +00005212
5213template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005214QualType
5215TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005216 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005217 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005218 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005219 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005220}
5221
Douglas Gregor577f75a2009-08-04 16:50:30 +00005222//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005223// Statement transformation
5224//===----------------------------------------------------------------------===//
5225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005226StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005227TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005228 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005229}
5230
5231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005233TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5234 return getDerived().TransformCompoundStmt(S, false);
5235}
5236
5237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005238StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005239TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005240 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005241 Sema::CompoundScopeRAII CompoundScope(getSema());
5242
John McCall7114cba2010-08-27 19:56:05 +00005243 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005244 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005245 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5247 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005248 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005249 if (Result.isInvalid()) {
5250 // Immediately fail if this was a DeclStmt, since it's very
5251 // likely that this will cause problems for future statements.
5252 if (isa<DeclStmt>(*B))
5253 return StmtError();
5254
5255 // Otherwise, just keep processing substatements and fail later.
5256 SubStmtInvalid = true;
5257 continue;
5258 }
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5261 Statements.push_back(Result.takeAs<Stmt>());
5262 }
Mike Stump1eb44332009-09-09 15:08:12 +00005263
John McCall7114cba2010-08-27 19:56:05 +00005264 if (SubStmtInvalid)
5265 return StmtError();
5266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (!getDerived().AlwaysRebuild() &&
5268 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005269 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005270
5271 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005272 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 S->getRBracLoc(),
5274 IsStmtExpr);
5275}
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregor43959a92009-08-20 07:17:43 +00005277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005278StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005279TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005280 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005281 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005282 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5283 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Eli Friedman264c1f82009-11-19 03:14:00 +00005285 // Transform the left-hand case value.
5286 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005287 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005288 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Eli Friedman264c1f82009-11-19 03:14:00 +00005291 // Transform the right-hand case value (for the GNU case-range extension).
5292 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005293 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005294 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005296 }
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 // Build the case statement.
5299 // Case statements are always rebuilt so that they will attached to their
5300 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005301 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005302 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005304 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 S->getColonLoc());
5306 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005307 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005310 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005315 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316}
5317
5318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005319StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005320TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005322 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 // Default statements are always rebuilt
5327 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005328 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005334 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005336 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Chris Lattner57ad3782011-02-17 20:34:02 +00005338 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5339 S->getDecl());
5340 if (!LD)
5341 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005342
5343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005345 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005346 cast<LabelDecl>(LD), SourceLocation(),
5347 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005348}
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005351StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005352TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5353 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5354 if (SubStmt.isInvalid())
5355 return StmtError();
5356
5357 // TODO: transform attributes
5358 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5359 return S;
5360
5361 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5362 S->getAttrs(),
5363 SubStmt.get());
5364}
5365
5366template<typename Derived>
5367StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005368TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005370 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005371 VarDecl *ConditionVar = 0;
5372 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005373 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005374 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005375 getDerived().TransformDefinition(
5376 S->getConditionVariable()->getLocation(),
5377 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005378 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005380 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005381 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005382
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005383 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005385
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005386 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005387 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005388 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005389 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005390 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005392
John McCall9ae2f072010-08-23 23:25:46 +00005393 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005394 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005395 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005396
John McCall9ae2f072010-08-23 23:25:46 +00005397 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5398 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005400
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005402 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005407 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005412 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005413 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 Then.get() == S->getThen() &&
5415 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005416 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005418 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005419 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005420 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005421}
5422
5423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005424StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005425TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005426 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005427 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005428 VarDecl *ConditionVar = 0;
5429 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005430 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005431 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005432 getDerived().TransformDefinition(
5433 S->getConditionVariable()->getLocation(),
5434 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005435 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005437 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005438 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005439
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005440 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005442 }
Mike Stump1eb44332009-09-09 15:08:12 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005445 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005446 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005447 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005452 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005454 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005457 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5458 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005459}
Mike Stump1eb44332009-09-09 15:08:12 +00005460
Douglas Gregor43959a92009-08-20 07:17:43 +00005461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005462StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005463TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005465 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005466 VarDecl *ConditionVar = 0;
5467 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005468 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005469 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005470 getDerived().TransformDefinition(
5471 S->getConditionVariable()->getLocation(),
5472 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005473 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005474 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005475 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005476 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005477
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005478 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005480
5481 if (S->getCond()) {
5482 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005483 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005484 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005485 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005487 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005488 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005489 }
Mike Stump1eb44332009-09-09 15:08:12 +00005490
John McCall9ae2f072010-08-23 23:25:46 +00005491 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5492 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005496 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005501 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005502 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005504 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005506 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005507 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005508}
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregor43959a92009-08-20 07:17:43 +00005510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005511StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005512TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005514 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005517
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005518 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005519 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005520 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005522
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 if (!getDerived().AlwaysRebuild() &&
5524 Cond.get() == S->getCond() &&
5525 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005527
John McCall9ae2f072010-08-23 23:25:46 +00005528 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5529 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 S->getRParenLoc());
5531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005535TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005537 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005539 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005542 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005543 VarDecl *ConditionVar = 0;
5544 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005545 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005546 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005547 getDerived().TransformDefinition(
5548 S->getConditionVariable()->getLocation(),
5549 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005550 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005552 } else {
5553 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005554
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005555 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005557
5558 if (S->getCond()) {
5559 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005560 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005561 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005562 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005564
John McCall9ae2f072010-08-23 23:25:46 +00005565 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005566 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005567 }
Mike Stump1eb44332009-09-09 15:08:12 +00005568
Chad Rosier4a9d7952012-08-08 18:46:20 +00005569 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005570 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005571 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005572
Douglas Gregor43959a92009-08-20 07:17:43 +00005573 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005574 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005575 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005577
Richard Smith41956372013-01-14 22:39:08 +00005578 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005579 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005580 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005581
Douglas Gregor43959a92009-08-20 07:17:43 +00005582 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005583 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005584 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005585 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 if (!getDerived().AlwaysRebuild() &&
5588 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005589 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005590 Inc.get() == S->getInc() &&
5591 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005592 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005593
Douglas Gregor43959a92009-08-20 07:17:43 +00005594 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005595 Init.get(), FullCond, ConditionVar,
5596 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005597}
5598
5599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005600StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005601TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005602 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5603 S->getLabel());
5604 if (!LD)
5605 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Douglas Gregor43959a92009-08-20 07:17:43 +00005607 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005608 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005609 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005610}
5611
5612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005613StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005614TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005615 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005616 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005617 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005618 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005619
Douglas Gregor43959a92009-08-20 07:17:43 +00005620 if (!getDerived().AlwaysRebuild() &&
5621 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005622 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005623
5624 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005625 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005626}
5627
5628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005629StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005630TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005631 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005632}
Mike Stump1eb44332009-09-09 15:08:12 +00005633
Douglas Gregor43959a92009-08-20 07:17:43 +00005634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005635StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005638}
Mike Stump1eb44332009-09-09 15:08:12 +00005639
Douglas Gregor43959a92009-08-20 07:17:43 +00005640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005642TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005643 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005644 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005645 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005646
Mike Stump1eb44332009-09-09 15:08:12 +00005647 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005648 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005649 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005650}
Mike Stump1eb44332009-09-09 15:08:12 +00005651
Douglas Gregor43959a92009-08-20 07:17:43 +00005652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005653StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005655 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005656 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005657 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5658 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005659 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5660 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005661 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005662 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664 if (Transformed != *D)
5665 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregor43959a92009-08-20 07:17:43 +00005667 Decls.push_back(Transformed);
5668 }
Mike Stump1eb44332009-09-09 15:08:12 +00005669
Douglas Gregor43959a92009-08-20 07:17:43 +00005670 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005671 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005673 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005674}
Mike Stump1eb44332009-09-09 15:08:12 +00005675
Douglas Gregor43959a92009-08-20 07:17:43 +00005676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005677StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005678TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005679
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005680 SmallVector<Expr*, 8> Constraints;
5681 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005682 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005683
John McCall60d7b3a2010-08-24 06:29:42 +00005684 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005685 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005686
5687 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005688
Anders Carlsson703e3942010-01-24 05:50:09 +00005689 // Go through the outputs.
5690 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005691 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005692
Anders Carlsson703e3942010-01-24 05:50:09 +00005693 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005694 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005695
Anders Carlsson703e3942010-01-24 05:50:09 +00005696 // Transform the output expr.
5697 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005698 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005699 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005700 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005701
Anders Carlsson703e3942010-01-24 05:50:09 +00005702 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005703
John McCall9ae2f072010-08-23 23:25:46 +00005704 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005705 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005706
Anders Carlsson703e3942010-01-24 05:50:09 +00005707 // Go through the inputs.
5708 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005709 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005710
Anders Carlsson703e3942010-01-24 05:50:09 +00005711 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005712 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005713
Anders Carlsson703e3942010-01-24 05:50:09 +00005714 // Transform the input expr.
5715 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005716 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005717 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005718 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
Anders Carlsson703e3942010-01-24 05:50:09 +00005720 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005721
John McCall9ae2f072010-08-23 23:25:46 +00005722 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Anders Carlsson703e3942010-01-24 05:50:09 +00005725 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005726 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005727
5728 // Go through the clobbers.
5729 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005730 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005731
5732 // No need to transform the asm string literal.
5733 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005734 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5735 S->isVolatile(), S->getNumOutputs(),
5736 S->getNumInputs(), Names.data(),
5737 Constraints, Exprs, AsmString.get(),
5738 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005739}
5740
Chad Rosier8cd64b42012-06-11 20:47:18 +00005741template<typename Derived>
5742StmtResult
5743TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005744 ArrayRef<Token> AsmToks =
5745 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005746
John McCallaeeacf72013-05-03 00:10:13 +00005747 bool HadError = false, HadChange = false;
5748
5749 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5750 SmallVector<Expr*, 8> TransformedExprs;
5751 TransformedExprs.reserve(SrcExprs.size());
5752 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5753 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5754 if (!Result.isUsable()) {
5755 HadError = true;
5756 } else {
5757 HadChange |= (Result.get() != SrcExprs[i]);
5758 TransformedExprs.push_back(Result.take());
5759 }
5760 }
5761
5762 if (HadError) return StmtError();
5763 if (!HadChange && !getDerived().AlwaysRebuild())
5764 return Owned(S);
5765
Chad Rosier7bd092b2012-08-15 16:53:30 +00005766 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005767 AsmToks, S->getAsmString(),
5768 S->getNumOutputs(), S->getNumInputs(),
5769 S->getAllConstraints(), S->getClobbers(),
5770 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005771}
Douglas Gregor43959a92009-08-20 07:17:43 +00005772
5773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005774StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005775TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005776 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005777 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005778 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005779 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005780
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005781 // Transform the @catch statements (if present).
5782 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005783 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005784 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005785 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005786 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005788 if (Catch.get() != S->getCatchStmt(I))
5789 AnyCatchChanged = true;
5790 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005792
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005793 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005794 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005795 if (S->getFinallyStmt()) {
5796 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5797 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005798 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005799 }
5800
5801 // If nothing changed, just retain this statement.
5802 if (!getDerived().AlwaysRebuild() &&
5803 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005804 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005805 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005806 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005807
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005808 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005809 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005810 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005811}
Mike Stump1eb44332009-09-09 15:08:12 +00005812
Douglas Gregor43959a92009-08-20 07:17:43 +00005813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005814StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005815TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005816 // Transform the @catch parameter, if there is one.
5817 VarDecl *Var = 0;
5818 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5819 TypeSourceInfo *TSInfo = 0;
5820 if (FromVar->getTypeSourceInfo()) {
5821 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5822 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005823 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005824 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005825
Douglas Gregorbe270a02010-04-26 17:57:08 +00005826 QualType T;
5827 if (TSInfo)
5828 T = TSInfo->getType();
5829 else {
5830 T = getDerived().TransformType(FromVar->getType());
5831 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005832 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005833 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005834
Douglas Gregorbe270a02010-04-26 17:57:08 +00005835 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5836 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005837 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005839
John McCall60d7b3a2010-08-24 06:29:42 +00005840 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005841 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005842 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005843
5844 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005845 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005846 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005847}
Mike Stump1eb44332009-09-09 15:08:12 +00005848
Douglas Gregor43959a92009-08-20 07:17:43 +00005849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005850StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005851TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005852 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005853 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005854 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005855 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005856
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005857 // If nothing changed, just retain this statement.
5858 if (!getDerived().AlwaysRebuild() &&
5859 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005860 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005861
5862 // Build a new statement.
5863 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005864 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005865}
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregor43959a92009-08-20 07:17:43 +00005867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005868StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005869TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005870 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005871 if (S->getThrowExpr()) {
5872 Operand = getDerived().TransformExpr(S->getThrowExpr());
5873 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005875 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005876
Douglas Gregord1377b22010-04-22 21:44:01 +00005877 if (!getDerived().AlwaysRebuild() &&
5878 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005880
John McCall9ae2f072010-08-23 23:25:46 +00005881 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005882}
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregor43959a92009-08-20 07:17:43 +00005884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005885StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005886TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005887 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005888 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005889 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005890 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005891 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005892 Object =
5893 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5894 Object.get());
5895 if (Object.isInvalid())
5896 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005897
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005898 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005899 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005900 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005901 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005902
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005903 // If nothing change, just retain the current statement.
5904 if (!getDerived().AlwaysRebuild() &&
5905 Object.get() == S->getSynchExpr() &&
5906 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005907 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005908
5909 // Build a new statement.
5910 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005911 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005912}
5913
5914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005916TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5917 ObjCAutoreleasePoolStmt *S) {
5918 // Transform the body.
5919 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5920 if (Body.isInvalid())
5921 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005922
John McCallf85e1932011-06-15 23:02:42 +00005923 // If nothing changed, just retain this statement.
5924 if (!getDerived().AlwaysRebuild() &&
5925 Body.get() == S->getSubStmt())
5926 return SemaRef.Owned(S);
5927
5928 // Build a new statement.
5929 return getDerived().RebuildObjCAutoreleasePoolStmt(
5930 S->getAtLoc(), Body.get());
5931}
5932
5933template<typename Derived>
5934StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005935TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005936 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005937 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005938 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005939 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005940 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005941
Douglas Gregorc3203e72010-04-22 23:10:45 +00005942 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005943 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005944 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005945 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005946
Douglas Gregorc3203e72010-04-22 23:10:45 +00005947 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005948 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005949 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005950 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005951
Douglas Gregorc3203e72010-04-22 23:10:45 +00005952 // If nothing changed, just retain this statement.
5953 if (!getDerived().AlwaysRebuild() &&
5954 Element.get() == S->getElement() &&
5955 Collection.get() == S->getCollection() &&
5956 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005957 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005958
Douglas Gregorc3203e72010-04-22 23:10:45 +00005959 // Build a new statement.
5960 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005961 Element.get(),
5962 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005963 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005964 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005965}
5966
5967
5968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005969StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005970TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5971 // Transform the exception declaration, if any.
5972 VarDecl *Var = 0;
5973 if (S->getExceptionDecl()) {
5974 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005975 TypeSourceInfo *T = getDerived().TransformType(
5976 ExceptionDecl->getTypeSourceInfo());
5977 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005978 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005979
Douglas Gregor83cb9422010-09-09 17:09:21 +00005980 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005981 ExceptionDecl->getInnerLocStart(),
5982 ExceptionDecl->getLocation(),
5983 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005984 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005985 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005986 }
Mike Stump1eb44332009-09-09 15:08:12 +00005987
Douglas Gregor43959a92009-08-20 07:17:43 +00005988 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005989 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005990 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005991 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005992
Douglas Gregor43959a92009-08-20 07:17:43 +00005993 if (!getDerived().AlwaysRebuild() &&
5994 !Var &&
5995 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005996 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005997
5998 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5999 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006000 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006001}
Mike Stump1eb44332009-09-09 15:08:12 +00006002
Douglas Gregor43959a92009-08-20 07:17:43 +00006003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006004StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006005TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6006 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006007 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006008 = getDerived().TransformCompoundStmt(S->getTryBlock());
6009 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006010 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006011
Douglas Gregor43959a92009-08-20 07:17:43 +00006012 // Transform the handlers.
6013 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006014 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006015 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006016 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006017 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6018 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006019 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006020
Douglas Gregor43959a92009-08-20 07:17:43 +00006021 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6022 Handlers.push_back(Handler.takeAs<Stmt>());
6023 }
Mike Stump1eb44332009-09-09 15:08:12 +00006024
Douglas Gregor43959a92009-08-20 07:17:43 +00006025 if (!getDerived().AlwaysRebuild() &&
6026 TryBlock.get() == S->getTryBlock() &&
6027 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006028 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006029
John McCall9ae2f072010-08-23 23:25:46 +00006030 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006031 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006032}
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Richard Smithad762fc2011-04-14 22:09:26 +00006034template<typename Derived>
6035StmtResult
6036TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6037 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6038 if (Range.isInvalid())
6039 return StmtError();
6040
6041 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6042 if (BeginEnd.isInvalid())
6043 return StmtError();
6044
6045 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6046 if (Cond.isInvalid())
6047 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006048 if (Cond.get())
6049 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6050 if (Cond.isInvalid())
6051 return StmtError();
6052 if (Cond.get())
6053 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006054
6055 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6056 if (Inc.isInvalid())
6057 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006058 if (Inc.get())
6059 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006060
6061 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6062 if (LoopVar.isInvalid())
6063 return StmtError();
6064
6065 StmtResult NewStmt = S;
6066 if (getDerived().AlwaysRebuild() ||
6067 Range.get() != S->getRangeStmt() ||
6068 BeginEnd.get() != S->getBeginEndStmt() ||
6069 Cond.get() != S->getCond() ||
6070 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006071 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006072 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6073 S->getColonLoc(), Range.get(),
6074 BeginEnd.get(), Cond.get(),
6075 Inc.get(), LoopVar.get(),
6076 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006077 if (NewStmt.isInvalid())
6078 return StmtError();
6079 }
Richard Smithad762fc2011-04-14 22:09:26 +00006080
6081 StmtResult Body = getDerived().TransformStmt(S->getBody());
6082 if (Body.isInvalid())
6083 return StmtError();
6084
6085 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6086 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006087 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006088 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6089 S->getColonLoc(), Range.get(),
6090 BeginEnd.get(), Cond.get(),
6091 Inc.get(), LoopVar.get(),
6092 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006093 if (NewStmt.isInvalid())
6094 return StmtError();
6095 }
Richard Smithad762fc2011-04-14 22:09:26 +00006096
6097 if (NewStmt.get() == S)
6098 return SemaRef.Owned(S);
6099
6100 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6101}
6102
John Wiegley28bbe4b2011-04-28 01:08:34 +00006103template<typename Derived>
6104StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006105TreeTransform<Derived>::TransformMSDependentExistsStmt(
6106 MSDependentExistsStmt *S) {
6107 // Transform the nested-name-specifier, if any.
6108 NestedNameSpecifierLoc QualifierLoc;
6109 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006110 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006111 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6112 if (!QualifierLoc)
6113 return StmtError();
6114 }
6115
6116 // Transform the declaration name.
6117 DeclarationNameInfo NameInfo = S->getNameInfo();
6118 if (NameInfo.getName()) {
6119 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6120 if (!NameInfo.getName())
6121 return StmtError();
6122 }
6123
6124 // Check whether anything changed.
6125 if (!getDerived().AlwaysRebuild() &&
6126 QualifierLoc == S->getQualifierLoc() &&
6127 NameInfo.getName() == S->getNameInfo().getName())
6128 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006129
Douglas Gregorba0513d2011-10-25 01:33:02 +00006130 // Determine whether this name exists, if we can.
6131 CXXScopeSpec SS;
6132 SS.Adopt(QualifierLoc);
6133 bool Dependent = false;
6134 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6135 case Sema::IER_Exists:
6136 if (S->isIfExists())
6137 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006138
Douglas Gregorba0513d2011-10-25 01:33:02 +00006139 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6140
6141 case Sema::IER_DoesNotExist:
6142 if (S->isIfNotExists())
6143 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006144
Douglas Gregorba0513d2011-10-25 01:33:02 +00006145 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006146
Douglas Gregorba0513d2011-10-25 01:33:02 +00006147 case Sema::IER_Dependent:
6148 Dependent = true;
6149 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006150
Douglas Gregor65019ac2011-10-25 03:44:56 +00006151 case Sema::IER_Error:
6152 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006153 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006154
Douglas Gregorba0513d2011-10-25 01:33:02 +00006155 // We need to continue with the instantiation, so do so now.
6156 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6157 if (SubStmt.isInvalid())
6158 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 // If we have resolved the name, just transform to the substatement.
6161 if (!Dependent)
6162 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006163
Douglas Gregorba0513d2011-10-25 01:33:02 +00006164 // The name is still dependent, so build a dependent expression again.
6165 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6166 S->isIfExists(),
6167 QualifierLoc,
6168 NameInfo,
6169 SubStmt.get());
6170}
6171
6172template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006173ExprResult
6174TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6175 NestedNameSpecifierLoc QualifierLoc;
6176 if (E->getQualifierLoc()) {
6177 QualifierLoc
6178 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6179 if (!QualifierLoc)
6180 return ExprError();
6181 }
6182
6183 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6184 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6185 if (!PD)
6186 return ExprError();
6187
6188 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6189 if (Base.isInvalid())
6190 return ExprError();
6191
6192 return new (SemaRef.getASTContext())
6193 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6194 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6195 QualifierLoc, E->getMemberLoc());
6196}
6197
6198template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006199StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006200TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6201 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6202 if(TryBlock.isInvalid()) return StmtError();
6203
6204 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6205 if(!getDerived().AlwaysRebuild() &&
6206 TryBlock.get() == S->getTryBlock() &&
6207 Handler.get() == S->getHandler())
6208 return SemaRef.Owned(S);
6209
6210 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6211 S->getTryLoc(),
6212 TryBlock.take(),
6213 Handler.take());
6214}
6215
6216template<typename Derived>
6217StmtResult
6218TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6219 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6220 if(Block.isInvalid()) return StmtError();
6221
6222 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6223 Block.take());
6224}
6225
6226template<typename Derived>
6227StmtResult
6228TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6229 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6230 if(FilterExpr.isInvalid()) return StmtError();
6231
6232 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6233 if(Block.isInvalid()) return StmtError();
6234
6235 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6236 FilterExpr.take(),
6237 Block.take());
6238}
6239
6240template<typename Derived>
6241StmtResult
6242TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6243 if(isa<SEHFinallyStmt>(Handler))
6244 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6245 else
6246 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6247}
6248
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006249template<typename Derived>
6250StmtResult
6251TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6252 // Transform the clauses
Rafael Espindola43678292013-09-03 14:33:09 +00006253 SmallVector<OMPClause *, 5> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006254 ArrayRef<OMPClause *> Clauses = D->clauses();
6255 TClauses.reserve(Clauses.size());
6256 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6257 I != E; ++I) {
6258 if (*I) {
6259 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Rafael Espindola43678292013-09-03 14:33:09 +00006260 if (!Clause)
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006261 return StmtError();
6262 TClauses.push_back(Clause);
6263 }
6264 else {
6265 TClauses.push_back(0);
6266 }
6267 }
Rafael Espindola43678292013-09-03 14:33:09 +00006268 if (!D->getAssociatedStmt())
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006269 return StmtError();
6270 StmtResult AssociatedStmt =
6271 getDerived().TransformStmt(D->getAssociatedStmt());
Rafael Espindola43678292013-09-03 14:33:09 +00006272 if (AssociatedStmt.isInvalid())
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006273 return StmtError();
6274
Rafael Espindola43678292013-09-03 14:33:09 +00006275 return getDerived().RebuildOMPParallelDirective(TClauses,
6276 AssociatedStmt.take(),
6277 D->getLocStart(),
6278 D->getLocEnd());
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006279}
6280
6281template<typename Derived>
6282OMPClause *
6283TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6284 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6285 C->getDefaultKindKwLoc(),
6286 C->getLocStart(),
6287 C->getLParenLoc(),
6288 C->getLocEnd());
6289}
6290
6291template<typename Derived>
6292OMPClause *
6293TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Rafael Espindola43678292013-09-03 14:33:09 +00006294 SmallVector<Expr *, 5> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006295 Vars.reserve(C->varlist_size());
6296 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6297 E = C->varlist_end();
6298 I != E; ++I) {
6299 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6300 if (EVar.isInvalid())
6301 return 0;
6302 Vars.push_back(EVar.take());
6303 }
6304 return getDerived().RebuildOMPPrivateClause(Vars,
6305 C->getLocStart(),
6306 C->getLParenLoc(),
6307 C->getLocEnd());
6308}
6309
Douglas Gregor43959a92009-08-20 07:17:43 +00006310//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311// Expression transformation
6312//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006314ExprResult
John McCall454feb92009-12-08 09:21:05 +00006315TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317}
Mike Stump1eb44332009-09-09 15:08:12 +00006318
6319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006320ExprResult
John McCall454feb92009-12-08 09:21:05 +00006321TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006322 NestedNameSpecifierLoc QualifierLoc;
6323 if (E->getQualifierLoc()) {
6324 QualifierLoc
6325 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6326 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006327 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006328 }
John McCalldbd872f2009-12-08 09:08:17 +00006329
6330 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006331 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6332 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006335
John McCallec8045d2010-08-17 21:27:17 +00006336 DeclarationNameInfo NameInfo = E->getNameInfo();
6337 if (NameInfo.getName()) {
6338 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6339 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006341 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006342
6343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006344 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006345 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006346 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006347 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006348
6349 // Mark it referenced in the new context regardless.
6350 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006351 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006352
John McCall3fa5cae2010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006354 }
John McCalldbd872f2009-12-08 09:08:17 +00006355
6356 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006357 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006358 TemplateArgs = &TransArgs;
6359 TransArgs.setLAngleLoc(E->getLAngleLoc());
6360 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006361 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6362 E->getNumTemplateArgs(),
6363 TransArgs))
6364 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006365 }
6366
Chad Rosier4a9d7952012-08-08 18:46:20 +00006367 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006368 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369}
Mike Stump1eb44332009-09-09 15:08:12 +00006370
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006372ExprResult
John McCall454feb92009-12-08 09:21:05 +00006373TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006374 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006380 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381}
Mike Stump1eb44332009-09-09 15:08:12 +00006382
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006384ExprResult
John McCall454feb92009-12-08 09:21:05 +00006385TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006386 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006390ExprResult
John McCall454feb92009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006396ExprResult
John McCall454feb92009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006398 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006399}
6400
6401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006403TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006404 if (FunctionDecl *FD = E->getDirectCallee())
6405 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006406 return SemaRef.MaybeBindToTemporary(E);
6407}
6408
6409template<typename Derived>
6410ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006411TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6412 ExprResult ControllingExpr =
6413 getDerived().TransformExpr(E->getControllingExpr());
6414 if (ControllingExpr.isInvalid())
6415 return ExprError();
6416
Chris Lattner686775d2011-07-20 06:58:45 +00006417 SmallVector<Expr *, 4> AssocExprs;
6418 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006419 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6420 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6421 if (TS) {
6422 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6423 if (!AssocType)
6424 return ExprError();
6425 AssocTypes.push_back(AssocType);
6426 } else {
6427 AssocTypes.push_back(0);
6428 }
6429
6430 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6431 if (AssocExpr.isInvalid())
6432 return ExprError();
6433 AssocExprs.push_back(AssocExpr.release());
6434 }
6435
6436 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6437 E->getDefaultLoc(),
6438 E->getRParenLoc(),
6439 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006440 AssocTypes,
6441 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006442}
6443
6444template<typename Derived>
6445ExprResult
John McCall454feb92009-12-08 09:21:05 +00006446TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006447 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006450
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006453
John McCall9ae2f072010-08-23 23:25:46 +00006454 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 E->getRParen());
6456}
6457
Richard Smithefeeccf2012-10-21 03:28:35 +00006458/// \brief The operand of a unary address-of operator has special rules: it's
6459/// allowed to refer to a non-static member of a class even if there's no 'this'
6460/// object available.
6461template<typename Derived>
6462ExprResult
6463TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6464 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6465 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6466 else
6467 return getDerived().TransformExpr(E);
6468}
6469
Mike Stump1eb44332009-09-09 15:08:12 +00006470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006473 ExprResult SubExpr;
6474 if (E->getOpcode() == UO_AddrOf)
6475 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6476 else
6477 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006480
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006482 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6485 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006486 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487}
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006490ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006491TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6492 // Transform the type.
6493 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6494 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006495 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006496
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006497 // Transform all of the components into components similar to what the
6498 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006499 // FIXME: It would be slightly more efficient in the non-dependent case to
6500 // just map FieldDecls, rather than requiring the rebuilder to look for
6501 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006502 // template code that we don't care.
6503 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006504 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006505 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006506 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006507 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6508 const Node &ON = E->getComponent(I);
6509 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006510 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006511 Comp.LocStart = ON.getSourceRange().getBegin();
6512 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006513 switch (ON.getKind()) {
6514 case Node::Array: {
6515 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006516 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006517 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006518 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006519
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006520 ExprChanged = ExprChanged || Index.get() != FromIndex;
6521 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006522 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006523 break;
6524 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006525
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006526 case Node::Field:
6527 case Node::Identifier:
6528 Comp.isBrackets = false;
6529 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006530 if (!Comp.U.IdentInfo)
6531 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006532
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006533 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006534
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006535 case Node::Base:
6536 // Will be recomputed during the rebuild.
6537 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006538 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006539
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006540 Components.push_back(Comp);
6541 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006542
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006543 // If nothing changed, retain the existing expression.
6544 if (!getDerived().AlwaysRebuild() &&
6545 Type == E->getTypeSourceInfo() &&
6546 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006547 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006548
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006549 // Build a new offsetof expression.
6550 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6551 Components.data(), Components.size(),
6552 E->getRParenLoc());
6553}
6554
6555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006556ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006557TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6558 assert(getDerived().AlreadyTransformed(E->getType()) &&
6559 "opaque value expression requires transformation");
6560 return SemaRef.Owned(E);
6561}
6562
6563template<typename Derived>
6564ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006565TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006566 // Rebuild the syntactic form. The original syntactic form has
6567 // opaque-value expressions in it, so strip those away and rebuild
6568 // the result. This is a really awful way of doing this, but the
6569 // better solution (rebuilding the semantic expressions and
6570 // rebinding OVEs as necessary) doesn't work; we'd need
6571 // TreeTransform to not strip away implicit conversions.
6572 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6573 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006574 if (result.isInvalid()) return ExprError();
6575
6576 // If that gives us a pseudo-object result back, the pseudo-object
6577 // expression must have been an lvalue-to-rvalue conversion which we
6578 // should reapply.
6579 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6580 result = SemaRef.checkPseudoObjectRValue(result.take());
6581
6582 return result;
6583}
6584
6585template<typename Derived>
6586ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006587TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6588 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006590 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006591
John McCalla93c9342009-12-07 02:54:59 +00006592 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006593 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006595
John McCall5ab75172009-11-04 07:28:41 +00006596 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006599 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6600 E->getKind(),
6601 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 }
Mike Stump1eb44332009-09-09 15:08:12 +00006603
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006604 // C++0x [expr.sizeof]p1:
6605 // The operand is either an expression, which is an unevaluated operand
6606 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006607 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6608 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006610 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6611 if (SubExpr.isInvalid())
6612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006614 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6615 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006617 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6618 E->getOperatorLoc(),
6619 E->getKind(),
6620 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621}
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006624ExprResult
John McCall454feb92009-12-08 09:21:05 +00006625TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006626 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006628 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006629
John McCall60d7b3a2010-08-24 06:29:42 +00006630 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
6634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (!getDerived().AlwaysRebuild() &&
6636 LHS.get() == E->getLHS() &&
6637 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006638 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006639
John McCall9ae2f072010-08-23 23:25:46 +00006640 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006642 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 E->getRBracketLoc());
6644}
Mike Stump1eb44332009-09-09 15:08:12 +00006645
6646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006647ExprResult
John McCall454feb92009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006650 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006652 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653
6654 // Transform arguments.
6655 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006656 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006657 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006658 &ArgChanged))
6659 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 if (!getDerived().AlwaysRebuild() &&
6662 Callee.get() == E->getCallee() &&
6663 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006664 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006667 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006669 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006670 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 E->getRParenLoc());
6672}
Mike Stump1eb44332009-09-09 15:08:12 +00006673
6674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006675ExprResult
John McCall454feb92009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregor40d96a62011-02-28 21:54:11 +00006681 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006682 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006683 QualifierLoc
6684 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006685
Douglas Gregor40d96a62011-02-28 21:54:11 +00006686 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006687 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006688 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006689 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006690
Eli Friedmanf595cc42009-12-04 06:40:45 +00006691 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006692 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6693 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
John McCall6bb80172010-03-30 21:47:33 +00006697 NamedDecl *FoundDecl = E->getFoundDecl();
6698 if (FoundDecl == E->getMemberDecl()) {
6699 FoundDecl = Member;
6700 } else {
6701 FoundDecl = cast_or_null<NamedDecl>(
6702 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6703 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006705 }
6706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
6708 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006709 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006710 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006711 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006712 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006713
Anders Carlsson1f240322009-12-22 05:24:09 +00006714 // Mark it referenced in the new context regardless.
6715 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006716 SemaRef.MarkMemberReferenced(E);
6717
John McCall3fa5cae2010-10-26 07:05:15 +00006718 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006719 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720
John McCalld5532b62009-11-23 01:53:49 +00006721 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006722 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006723 TransArgs.setLAngleLoc(E->getLAngleLoc());
6724 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006725 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6726 E->getNumTemplateArgs(),
6727 TransArgs))
6728 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006729 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 // FIXME: Bogus source location for the operator
6732 SourceLocation FakeOperatorLoc
6733 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6734
John McCallc2233c52010-01-15 08:34:02 +00006735 // FIXME: to do this check properly, we will need to preserve the
6736 // first-qualifier-in-scope here, just in case we had a dependent
6737 // base (and therefore couldn't do the check) and a
6738 // nested-name-qualifier (and therefore could do the lookup).
6739 NamedDecl *FirstQualifierInScope = 0;
6740
John McCall9ae2f072010-08-23 23:25:46 +00006741 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006743 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006744 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006745 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006746 Member,
John McCall6bb80172010-03-30 21:47:33 +00006747 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006748 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006749 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006750 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751}
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006754ExprResult
John McCall454feb92009-12-08 09:21:05 +00006755TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006756 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006758 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006759
John McCall60d7b3a2010-08-24 06:29:42 +00006760 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006763
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (!getDerived().AlwaysRebuild() &&
6765 LHS.get() == E->getLHS() &&
6766 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006767 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Lang Hamesbe9af122012-10-02 04:45:10 +00006769 Sema::FPContractStateRAII FPContractState(getSema());
6770 getSema().FPFeatures.fp_contract = E->isFPContractable();
6771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006773 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774}
6775
Mike Stump1eb44332009-09-09 15:08:12 +00006776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006777ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006779 CompoundAssignOperator *E) {
6780 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781}
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006784ExprResult TreeTransform<Derived>::
6785TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6786 // Just rebuild the common and RHS expressions and see whether we
6787 // get any changes.
6788
6789 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6790 if (commonExpr.isInvalid())
6791 return ExprError();
6792
6793 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6794 if (rhs.isInvalid())
6795 return ExprError();
6796
6797 if (!getDerived().AlwaysRebuild() &&
6798 commonExpr.get() == e->getCommon() &&
6799 rhs.get() == e->getFalseExpr())
6800 return SemaRef.Owned(e);
6801
6802 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6803 e->getQuestionLoc(),
6804 0,
6805 e->getColonLoc(),
6806 rhs.get());
6807}
6808
6809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006810ExprResult
John McCall454feb92009-12-08 09:21:05 +00006811TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006812 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006814 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006815
John McCall60d7b3a2010-08-24 06:29:42 +00006816 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006819
John McCall60d7b3a2010-08-24 06:29:42 +00006820 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006822 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006823
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (!getDerived().AlwaysRebuild() &&
6825 Cond.get() == E->getCond() &&
6826 LHS.get() == E->getLHS() &&
6827 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006828 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006829
John McCall9ae2f072010-08-23 23:25:46 +00006830 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006831 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006832 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006833 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006834 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835}
Mike Stump1eb44332009-09-09 15:08:12 +00006836
6837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006838ExprResult
John McCall454feb92009-12-08 09:21:05 +00006839TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006840 // Implicit casts are eliminated during transformation, since they
6841 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006842 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843}
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006846ExprResult
John McCall454feb92009-12-08 09:21:05 +00006847TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006848 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6849 if (!Type)
6850 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006851
John McCall60d7b3a2010-08-24 06:29:42 +00006852 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006853 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006858 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006860 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006861
John McCall9d125032010-01-15 18:39:57 +00006862 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006863 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006865 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866}
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006871 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6872 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6873 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006874 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006875
John McCall60d7b3a2010-08-24 06:29:42 +00006876 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006878 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006879
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006881 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006883 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884
John McCall1d7d8d62010-01-19 22:33:45 +00006885 // Note: the expression type doesn't necessarily match the
6886 // type-as-written, but that's okay, because it should always be
6887 // derivable from the initializer.
6888
John McCall42f56b52010-01-18 19:35:47 +00006889 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006891 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892}
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006895ExprResult
John McCall454feb92009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006897 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006900
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 if (!getDerived().AlwaysRebuild() &&
6902 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006903 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006904
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006906 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006908 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 E->getAccessorLoc(),
6910 E->getAccessor());
6911}
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006918 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006919 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006920 Inits, &InitChanged))
6921 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006924 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006925
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006926 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006927 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928}
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006931ExprResult
John McCall454feb92009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregor43959a92009-08-20 07:17:43 +00006935 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006936 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregor43959a92009-08-20 07:17:43 +00006940 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006941 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 bool ExprChanged = false;
6943 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6944 DEnd = E->designators_end();
6945 D != DEnd; ++D) {
6946 if (D->isFieldDesignator()) {
6947 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6948 D->getDotLoc(),
6949 D->getFieldLoc()));
6950 continue;
6951 }
Mike Stump1eb44332009-09-09 15:08:12 +00006952
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006954 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006957
6958 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6962 ArrayExprs.push_back(Index.release());
6963 continue;
6964 }
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006967 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6969 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006971
John McCall60d7b3a2010-08-24 06:29:42 +00006972 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006974 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006975
6976 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 End.get(),
6978 D->getLBracketLoc(),
6979 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6982 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 ArrayExprs.push_back(Start.release());
6985 ArrayExprs.push_back(End.release());
6986 }
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 if (!getDerived().AlwaysRebuild() &&
6989 Init.get() == E->getInit() &&
6990 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006993 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006995 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996}
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006999ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007001 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007002 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007003
Douglas Gregor5557b252009-10-28 00:29:27 +00007004 // FIXME: Will we ever have proper type location here? Will we actually
7005 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 QualType T = getDerived().TransformType(E->getType());
7007 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007008 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007009
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 if (!getDerived().AlwaysRebuild() &&
7011 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007012 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 return getDerived().RebuildImplicitValueInitExpr(T);
7015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007020 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7021 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007023
John McCall60d7b3a2010-08-24 06:29:42 +00007024 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007026 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007029 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007031 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007032
John McCall9ae2f072010-08-23 23:25:46 +00007033 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007034 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035}
7036
7037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007038ExprResult
John McCall454feb92009-12-08 09:21:05 +00007039TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007041 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007042 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7043 &ArgumentChanged))
7044 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007045
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007047 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 E->getRParenLoc());
7049}
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051/// \brief Transform an address-of-label expression.
7052///
7053/// By default, the transformation of an address-of-label expression always
7054/// rebuilds the expression, so that the label identifier can be resolved to
7055/// the corresponding label statement by semantic analysis.
7056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007057ExprResult
John McCall454feb92009-12-08 09:21:05 +00007058TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007059 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7060 E->getLabel());
7061 if (!LD)
7062 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007065 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066}
Mike Stump1eb44332009-09-09 15:08:12 +00007067
7068template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007069ExprResult
John McCall454feb92009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007071 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007072 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007074 if (SubStmt.isInvalid()) {
7075 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007076 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007077 }
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007080 SubStmt.get() == E->getSubStmt()) {
7081 // Calling this an 'error' is unintuitive, but it does the right thing.
7082 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007083 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007084 }
Mike Stump1eb44332009-09-09 15:08:12 +00007085
7086 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007087 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 E->getRParenLoc());
7089}
Mike Stump1eb44332009-09-09 15:08:12 +00007090
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
John McCall454feb92009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007094 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007096 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007097
John McCall60d7b3a2010-08-24 06:29:42 +00007098 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007101
John McCall60d7b3a2010-08-24 06:29:42 +00007102 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007104 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (!getDerived().AlwaysRebuild() &&
7107 Cond.get() == E->getCond() &&
7108 LHS.get() == E->getLHS() &&
7109 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007110 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007113 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 E->getRParenLoc());
7115}
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007118ExprResult
John McCall454feb92009-12-08 09:21:05 +00007119TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007120 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121}
7122
7123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007124ExprResult
John McCall454feb92009-12-08 09:21:05 +00007125TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007126 switch (E->getOperator()) {
7127 case OO_New:
7128 case OO_Delete:
7129 case OO_Array_New:
7130 case OO_Array_Delete:
7131 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007132
Douglas Gregor668d6d92009-12-13 20:44:55 +00007133 case OO_Call: {
7134 // This is a call to an object's operator().
7135 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7136
7137 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007138 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007139 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007140 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007141
7142 // FIXME: Poor location information
7143 SourceLocation FakeLParenLoc
7144 = SemaRef.PP.getLocForEndOfToken(
7145 static_cast<Expr *>(Object.get())->getLocEnd());
7146
7147 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007148 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007149 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007150 Args))
7151 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007152
John McCall9ae2f072010-08-23 23:25:46 +00007153 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007154 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007155 E->getLocEnd());
7156 }
7157
7158#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7159 case OO_##Name:
7160#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7161#include "clang/Basic/OperatorKinds.def"
7162 case OO_Subscript:
7163 // Handled below.
7164 break;
7165
7166 case OO_Conditional:
7167 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007168
7169 case OO_None:
7170 case NUM_OVERLOADED_OPERATORS:
7171 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007172 }
7173
John McCall60d7b3a2010-08-24 06:29:42 +00007174 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007176 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Richard Smithefeeccf2012-10-21 03:28:35 +00007178 ExprResult First;
7179 if (E->getOperator() == OO_Amp)
7180 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7181 else
7182 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185
John McCall60d7b3a2010-08-24 06:29:42 +00007186 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187 if (E->getNumArgs() == 2) {
7188 Second = getDerived().TransformExpr(E->getArg(1));
7189 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007190 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191 }
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 if (!getDerived().AlwaysRebuild() &&
7194 Callee.get() == E->getCallee() &&
7195 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007196 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007197 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007198
Lang Hamesbe9af122012-10-02 04:45:10 +00007199 Sema::FPContractStateRAII FPContractState(getSema());
7200 getSema().FPFeatures.fp_contract = E->isFPContractable();
7201
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7203 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007204 Callee.get(),
7205 First.get(),
7206 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207}
Mike Stump1eb44332009-09-09 15:08:12 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007210ExprResult
John McCall454feb92009-12-08 09:21:05 +00007211TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7212 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213}
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007216ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007217TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7218 // Transform the callee.
7219 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7220 if (Callee.isInvalid())
7221 return ExprError();
7222
7223 // Transform exec config.
7224 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7225 if (EC.isInvalid())
7226 return ExprError();
7227
7228 // Transform arguments.
7229 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007230 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007231 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007232 &ArgChanged))
7233 return ExprError();
7234
7235 if (!getDerived().AlwaysRebuild() &&
7236 Callee.get() == E->getCallee() &&
7237 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007238 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007239
7240 // FIXME: Wrong source location information for the '('.
7241 SourceLocation FakeLParenLoc
7242 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7243 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007244 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007245 E->getRParenLoc(), EC.get());
7246}
7247
7248template<typename Derived>
7249ExprResult
John McCall454feb92009-12-08 09:21:05 +00007250TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007251 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7252 if (!Type)
7253 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007254
John McCall60d7b3a2010-08-24 06:29:42 +00007255 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007256 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007261 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007263 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007265 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007266 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007267 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007268 E->getAngleBrackets().getEnd(),
7269 // FIXME. this should be '(' location
7270 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007271 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007272 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007273}
Mike Stump1eb44332009-09-09 15:08:12 +00007274
Douglas Gregorb98b1992009-08-11 05:31:07 +00007275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007276ExprResult
John McCall454feb92009-12-08 09:21:05 +00007277TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7278 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279}
Mike Stump1eb44332009-09-09 15:08:12 +00007280
7281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007282ExprResult
John McCall454feb92009-12-08 09:21:05 +00007283TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7284 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007285}
7286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007288ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007290 CXXReinterpretCastExpr *E) {
7291 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292}
Mike Stump1eb44332009-09-09 15:08:12 +00007293
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007295ExprResult
John McCall454feb92009-12-08 09:21:05 +00007296TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7297 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298}
Mike Stump1eb44332009-09-09 15:08:12 +00007299
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007301ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007302TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007303 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007304 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7305 if (!Type)
7306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007307
John McCall60d7b3a2010-08-24 06:29:42 +00007308 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007309 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007314 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007316 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007318 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007319 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007320 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321 E->getRParenLoc());
7322}
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007325ExprResult
John McCall454feb92009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007328 TypeSourceInfo *TInfo
7329 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7330 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007334 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007336
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007337 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7338 E->getLocStart(),
7339 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 E->getLocEnd());
7341 }
Mike Stump1eb44332009-09-09 15:08:12 +00007342
Eli Friedmanef331b72012-01-20 01:26:23 +00007343 // We don't know whether the subexpression is potentially evaluated until
7344 // after we perform semantic analysis. We speculatively assume it is
7345 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007347 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7348 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007349
John McCall60d7b3a2010-08-24 06:29:42 +00007350 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007353
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354 if (!getDerived().AlwaysRebuild() &&
7355 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007356 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007357
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007358 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7359 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007360 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 E->getLocEnd());
7362}
7363
7364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007365ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007366TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7367 if (E->isTypeOperand()) {
7368 TypeSourceInfo *TInfo
7369 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7370 if (!TInfo)
7371 return ExprError();
7372
7373 if (!getDerived().AlwaysRebuild() &&
7374 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007375 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007376
Douglas Gregor3c52a212011-03-06 17:40:41 +00007377 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007378 E->getLocStart(),
7379 TInfo,
7380 E->getLocEnd());
7381 }
7382
Francois Pichet01b7c302010-09-08 12:20:18 +00007383 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7384
7385 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7386 if (SubExpr.isInvalid())
7387 return ExprError();
7388
7389 if (!getDerived().AlwaysRebuild() &&
7390 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007391 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007392
7393 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7394 E->getLocStart(),
7395 SubExpr.get(),
7396 E->getLocEnd());
7397}
7398
7399template<typename Derived>
7400ExprResult
John McCall454feb92009-12-08 09:21:05 +00007401TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007402 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007403}
Mike Stump1eb44332009-09-09 15:08:12 +00007404
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007406ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007407TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007408 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007409 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007410}
Mike Stump1eb44332009-09-09 15:08:12 +00007411
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007413ExprResult
John McCall454feb92009-12-08 09:21:05 +00007414TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007415 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007416
Douglas Gregorec79d872012-02-24 17:41:38 +00007417 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7418 // Make sure that we capture 'this'.
7419 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007420 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007421 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007422
Douglas Gregor828a1972010-01-07 23:12:05 +00007423 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007424}
Mike Stump1eb44332009-09-09 15:08:12 +00007425
Douglas Gregorb98b1992009-08-11 05:31:07 +00007426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007427ExprResult
John McCall454feb92009-12-08 09:21:05 +00007428TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007429 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007432
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 if (!getDerived().AlwaysRebuild() &&
7434 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007435 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436
Douglas Gregorbca01b42011-07-06 22:04:06 +00007437 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7438 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439}
Mike Stump1eb44332009-09-09 15:08:12 +00007440
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007442ExprResult
John McCall454feb92009-12-08 09:21:05 +00007443TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007444 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007445 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7446 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007447 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007448 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007449
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007450 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007451 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007452 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007453
Douglas Gregor036aed12009-12-23 23:03:06 +00007454 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007455}
Mike Stump1eb44332009-09-09 15:08:12 +00007456
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007458ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007459TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7460 FieldDecl *Field
7461 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7462 E->getField()));
7463 if (!Field)
7464 return ExprError();
7465
7466 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7467 return SemaRef.Owned(E);
7468
7469 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7470}
7471
7472template<typename Derived>
7473ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007474TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7475 CXXScalarValueInitExpr *E) {
7476 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7477 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007478 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007479
Douglas Gregorb98b1992009-08-11 05:31:07 +00007480 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007481 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007482 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Chad Rosier4a9d7952012-08-08 18:46:20 +00007484 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007485 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007486 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487}
Mike Stump1eb44332009-09-09 15:08:12 +00007488
Douglas Gregorb98b1992009-08-11 05:31:07 +00007489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007490ExprResult
John McCall454feb92009-12-08 09:21:05 +00007491TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007493 TypeSourceInfo *AllocTypeInfo
7494 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7495 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007497
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007499 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503 // Transform the placement arguments (if any).
7504 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007505 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007506 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007507 E->getNumPlacementArgs(), true,
7508 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007510
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007511 // Transform the initializer (if any).
7512 Expr *OldInit = E->getInitializer();
7513 ExprResult NewInit;
7514 if (OldInit)
7515 NewInit = getDerived().TransformExpr(OldInit);
7516 if (NewInit.isInvalid())
7517 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007518
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007519 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007520 FunctionDecl *OperatorNew = 0;
7521 if (E->getOperatorNew()) {
7522 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007523 getDerived().TransformDecl(E->getLocStart(),
7524 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007525 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007526 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007527 }
7528
7529 FunctionDecl *OperatorDelete = 0;
7530 if (E->getOperatorDelete()) {
7531 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007532 getDerived().TransformDecl(E->getLocStart(),
7533 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007534 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007535 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007536 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007539 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007541 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007542 OperatorNew == E->getOperatorNew() &&
7543 OperatorDelete == E->getOperatorDelete() &&
7544 !ArgumentChanged) {
7545 // Mark any declarations we need as referenced.
7546 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007547 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007548 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007549 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007550 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007551
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007552 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007553 QualType ElementType
7554 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7555 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7556 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7557 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007558 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007559 }
7560 }
7561 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007562
John McCall3fa5cae2010-10-26 07:05:15 +00007563 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007564 }
Mike Stump1eb44332009-09-09 15:08:12 +00007565
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007566 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007567 if (!ArraySize.get()) {
7568 // If no array size was specified, but the new expression was
7569 // instantiated with an array type (e.g., "new T" where T is
7570 // instantiated with "int[4]"), extract the outer bound from the
7571 // array type as our array size. We do this with constant and
7572 // dependently-sized array types.
7573 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7574 if (!ArrayT) {
7575 // Do nothing
7576 } else if (const ConstantArrayType *ConsArrayT
7577 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007578 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007579 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007580 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007581 SemaRef.Context.getSizeType(),
7582 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007583 AllocType = ConsArrayT->getElementType();
7584 } else if (const DependentSizedArrayType *DepArrayT
7585 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7586 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007587 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007588 AllocType = DepArrayT->getElementType();
7589 }
7590 }
7591 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007592
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7594 E->isGlobalNew(),
7595 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007596 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007597 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007598 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007599 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007600 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007601 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007602 E->getDirectInitRange(),
7603 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007604}
Mike Stump1eb44332009-09-09 15:08:12 +00007605
Douglas Gregorb98b1992009-08-11 05:31:07 +00007606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007607ExprResult
John McCall454feb92009-12-08 09:21:05 +00007608TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007609 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007610 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007612
Douglas Gregor1af74512010-02-26 00:38:10 +00007613 // Transform the delete operator, if known.
7614 FunctionDecl *OperatorDelete = 0;
7615 if (E->getOperatorDelete()) {
7616 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007617 getDerived().TransformDecl(E->getLocStart(),
7618 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007619 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007620 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622
Douglas Gregorb98b1992009-08-11 05:31:07 +00007623 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007624 Operand.get() == E->getArgument() &&
7625 OperatorDelete == E->getOperatorDelete()) {
7626 // Mark any declarations we need as referenced.
7627 // FIXME: instantiation-specific.
7628 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007629 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007630
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007631 if (!E->getArgument()->isTypeDependent()) {
7632 QualType Destroyed = SemaRef.Context.getBaseElementType(
7633 E->getDestroyedType());
7634 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7635 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007636 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007637 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007638 }
7639 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
John McCall3fa5cae2010-10-26 07:05:15 +00007641 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007642 }
Mike Stump1eb44332009-09-09 15:08:12 +00007643
Douglas Gregorb98b1992009-08-11 05:31:07 +00007644 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7645 E->isGlobalDelete(),
7646 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007647 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007648}
Mike Stump1eb44332009-09-09 15:08:12 +00007649
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007651ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007652TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007653 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007654 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007655 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007657
John McCallb3d87482010-08-24 05:47:05 +00007658 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007659 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007660 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007661 E->getOperatorLoc(),
7662 E->isArrow()? tok::arrow : tok::period,
7663 ObjectTypePtr,
7664 MayBePseudoDestructor);
7665 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007666 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007667
John McCallb3d87482010-08-24 05:47:05 +00007668 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007669 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7670 if (QualifierLoc) {
7671 QualifierLoc
7672 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7673 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007674 return ExprError();
7675 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007676 CXXScopeSpec SS;
7677 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007678
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007679 PseudoDestructorTypeStorage Destroyed;
7680 if (E->getDestroyedTypeInfo()) {
7681 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007682 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007683 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007684 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007685 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007686 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007687 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007688 // We aren't likely to be able to resolve the identifier down to a type
7689 // now anyway, so just retain the identifier.
7690 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7691 E->getDestroyedTypeLoc());
7692 } else {
7693 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007694 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007695 *E->getDestroyedTypeIdentifier(),
7696 E->getDestroyedTypeLoc(),
7697 /*Scope=*/0,
7698 SS, ObjectTypePtr,
7699 false);
7700 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007701 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007702
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007703 Destroyed
7704 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7705 E->getDestroyedTypeLoc());
7706 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007707
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007708 TypeSourceInfo *ScopeTypeInfo = 0;
7709 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007710 CXXScopeSpec EmptySS;
7711 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7712 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007713 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007714 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007716
John McCall9ae2f072010-08-23 23:25:46 +00007717 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007718 E->getOperatorLoc(),
7719 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007720 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007721 ScopeTypeInfo,
7722 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007723 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007724 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007725}
Mike Stump1eb44332009-09-09 15:08:12 +00007726
Douglas Gregora71d8192009-09-04 17:36:40 +00007727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007728ExprResult
John McCallba135432009-11-21 08:51:07 +00007729TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007730 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007731 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7732 Sema::LookupOrdinaryName);
7733
7734 // Transform all the decls.
7735 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7736 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007737 NamedDecl *InstD = static_cast<NamedDecl*>(
7738 getDerived().TransformDecl(Old->getNameLoc(),
7739 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007740 if (!InstD) {
7741 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7742 // This can happen because of dependent hiding.
7743 if (isa<UsingShadowDecl>(*I))
7744 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007745 else {
7746 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007747 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007748 }
John McCall9f54ad42009-12-10 09:41:52 +00007749 }
John McCallf7a1a742009-11-24 19:00:30 +00007750
7751 // Expand using declarations.
7752 if (isa<UsingDecl>(InstD)) {
7753 UsingDecl *UD = cast<UsingDecl>(InstD);
7754 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7755 E = UD->shadow_end(); I != E; ++I)
7756 R.addDecl(*I);
7757 continue;
7758 }
7759
7760 R.addDecl(InstD);
7761 }
7762
7763 // Resolve a kind, but don't do any further analysis. If it's
7764 // ambiguous, the callee needs to deal with it.
7765 R.resolveKind();
7766
7767 // Rebuild the nested-name qualifier, if present.
7768 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007769 if (Old->getQualifierLoc()) {
7770 NestedNameSpecifierLoc QualifierLoc
7771 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7772 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007773 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007774
Douglas Gregor4c9be892011-02-28 20:01:57 +00007775 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007776 }
7777
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007778 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007779 CXXRecordDecl *NamingClass
7780 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7781 Old->getNameLoc(),
7782 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007783 if (!NamingClass) {
7784 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007785 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007787
Douglas Gregor66c45152010-04-27 16:10:10 +00007788 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007789 }
7790
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007791 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7792
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007793 // If we have neither explicit template arguments, nor the template keyword,
7794 // it's a normal declaration name.
7795 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007796 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7797
7798 // If we have template arguments, rebuild them, then rebuild the
7799 // templateid expression.
7800 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007801 if (Old->hasExplicitTemplateArgs() &&
7802 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007803 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007804 TransArgs)) {
7805 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007806 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007807 }
John McCallf7a1a742009-11-24 19:00:30 +00007808
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007809 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007810 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811}
Mike Stump1eb44332009-09-09 15:08:12 +00007812
Douglas Gregorb98b1992009-08-11 05:31:07 +00007813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007814ExprResult
John McCall454feb92009-12-08 09:21:05 +00007815TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007816 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7817 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007819
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007821 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007822 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007823
Mike Stump1eb44332009-09-09 15:08:12 +00007824 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007826 T,
7827 E->getLocEnd());
7828}
Mike Stump1eb44332009-09-09 15:08:12 +00007829
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007831ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007832TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7833 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7834 if (!LhsT)
7835 return ExprError();
7836
7837 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7838 if (!RhsT)
7839 return ExprError();
7840
7841 if (!getDerived().AlwaysRebuild() &&
7842 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7843 return SemaRef.Owned(E);
7844
7845 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7846 E->getLocStart(),
7847 LhsT, RhsT,
7848 E->getLocEnd());
7849}
7850
7851template<typename Derived>
7852ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007853TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7854 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007855 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007856 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7857 TypeSourceInfo *From = E->getArg(I);
7858 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007859 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007860 TypeLocBuilder TLB;
7861 TLB.reserve(FromTL.getFullDataSize());
7862 QualType To = getDerived().TransformType(TLB, FromTL);
7863 if (To.isNull())
7864 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007865
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007866 if (To == From->getType())
7867 Args.push_back(From);
7868 else {
7869 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7870 ArgChanged = true;
7871 }
7872 continue;
7873 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007874
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007875 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007876
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007877 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007878 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007879 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7880 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7881 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007882
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007883 // Determine whether the set of unexpanded parameter packs can and should
7884 // be expanded.
7885 bool Expand = true;
7886 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007887 Optional<unsigned> OrigNumExpansions =
7888 ExpansionTL.getTypePtr()->getNumExpansions();
7889 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007890 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7891 PatternTL.getSourceRange(),
7892 Unexpanded,
7893 Expand, RetainExpansion,
7894 NumExpansions))
7895 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007896
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007897 if (!Expand) {
7898 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007899 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007900 // expansion.
7901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007902
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007903 TypeLocBuilder TLB;
7904 TLB.reserve(From->getTypeLoc().getFullDataSize());
7905
7906 QualType To = getDerived().TransformType(TLB, PatternTL);
7907 if (To.isNull())
7908 return ExprError();
7909
Chad Rosier4a9d7952012-08-08 18:46:20 +00007910 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007911 PatternTL.getSourceRange(),
7912 ExpansionTL.getEllipsisLoc(),
7913 NumExpansions);
7914 if (To.isNull())
7915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007916
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007917 PackExpansionTypeLoc ToExpansionTL
7918 = TLB.push<PackExpansionTypeLoc>(To);
7919 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7920 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7921 continue;
7922 }
7923
7924 // Expand the pack expansion by substituting for each argument in the
7925 // pack(s).
7926 for (unsigned I = 0; I != *NumExpansions; ++I) {
7927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7928 TypeLocBuilder TLB;
7929 TLB.reserve(PatternTL.getFullDataSize());
7930 QualType To = getDerived().TransformType(TLB, PatternTL);
7931 if (To.isNull())
7932 return ExprError();
7933
Eli Friedman20cfeca2013-07-19 21:49:32 +00007934 if (To->containsUnexpandedParameterPack()) {
7935 To = getDerived().RebuildPackExpansionType(To,
7936 PatternTL.getSourceRange(),
7937 ExpansionTL.getEllipsisLoc(),
7938 NumExpansions);
7939 if (To.isNull())
7940 return ExprError();
7941
7942 PackExpansionTypeLoc ToExpansionTL
7943 = TLB.push<PackExpansionTypeLoc>(To);
7944 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7945 }
7946
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007947 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007949
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007950 if (!RetainExpansion)
7951 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007953 // If we're supposed to retain a pack expansion, do so by temporarily
7954 // forgetting the partially-substituted parameter pack.
7955 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7956
7957 TypeLocBuilder TLB;
7958 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007960 QualType To = getDerived().TransformType(TLB, PatternTL);
7961 if (To.isNull())
7962 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963
7964 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007965 PatternTL.getSourceRange(),
7966 ExpansionTL.getEllipsisLoc(),
7967 NumExpansions);
7968 if (To.isNull())
7969 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007970
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007971 PackExpansionTypeLoc ToExpansionTL
7972 = TLB.push<PackExpansionTypeLoc>(To);
7973 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7974 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7975 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007977 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7978 return SemaRef.Owned(E);
7979
7980 return getDerived().RebuildTypeTrait(E->getTrait(),
7981 E->getLocStart(),
7982 Args,
7983 E->getLocEnd());
7984}
7985
7986template<typename Derived>
7987ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007988TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7989 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7990 if (!T)
7991 return ExprError();
7992
7993 if (!getDerived().AlwaysRebuild() &&
7994 T == E->getQueriedTypeSourceInfo())
7995 return SemaRef.Owned(E);
7996
7997 ExprResult SubExpr;
7998 {
7999 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8000 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8001 if (SubExpr.isInvalid())
8002 return ExprError();
8003
8004 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8005 return SemaRef.Owned(E);
8006 }
8007
8008 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8009 E->getLocStart(),
8010 T,
8011 SubExpr.get(),
8012 E->getLocEnd());
8013}
8014
8015template<typename Derived>
8016ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008017TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8018 ExprResult SubExpr;
8019 {
8020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8021 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8022 if (SubExpr.isInvalid())
8023 return ExprError();
8024
8025 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8026 return SemaRef.Owned(E);
8027 }
8028
8029 return getDerived().RebuildExpressionTrait(
8030 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8031}
8032
8033template<typename Derived>
8034ExprResult
John McCall865d4472009-11-19 22:55:06 +00008035TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008036 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008037 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8038}
8039
8040template<typename Derived>
8041ExprResult
8042TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8043 DependentScopeDeclRefExpr *E,
8044 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008045 NestedNameSpecifierLoc QualifierLoc
8046 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8047 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008048 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008049 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008050
John McCall43fed0d2010-11-12 08:19:04 +00008051 // TODO: If this is a conversion-function-id, verify that the
8052 // destination type name (if present) resolves the same way after
8053 // instantiation as it did in the local scope.
8054
Abramo Bagnara25777432010-08-11 22:01:17 +00008055 DeclarationNameInfo NameInfo
8056 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8057 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008058 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008059
John McCallf7a1a742009-11-24 19:00:30 +00008060 if (!E->hasExplicitTemplateArgs()) {
8061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008062 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008063 // Note: it is sufficient to compare the Name component of NameInfo:
8064 // if name has not changed, DNLoc has not changed either.
8065 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008066 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008067
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008068 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008069 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008070 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008071 /*TemplateArgs*/ 0,
8072 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008073 }
John McCalld5532b62009-11-23 01:53:49 +00008074
8075 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008076 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8077 E->getNumTemplateArgs(),
8078 TransArgs))
8079 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008080
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008081 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008082 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008083 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008084 &TransArgs,
8085 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008086}
8087
8088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008089ExprResult
John McCall454feb92009-12-08 09:21:05 +00008090TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008091 // CXXConstructExprs other than for list-initialization and
8092 // CXXTemporaryObjectExpr are always implicit, so when we have
8093 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008094 if ((E->getNumArgs() == 1 ||
8095 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008096 (!getDerived().DropCallArgument(E->getArg(0))) &&
8097 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008098 return getDerived().TransformExpr(E->getArg(0));
8099
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8101
8102 QualType T = getDerived().TransformType(E->getType());
8103 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008104 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105
8106 CXXConstructorDecl *Constructor
8107 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008108 getDerived().TransformDecl(E->getLocStart(),
8109 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008110 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008112
Douglas Gregorb98b1992009-08-11 05:31:07 +00008113 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008114 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008115 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008116 &ArgumentChanged))
8117 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008118
Douglas Gregorb98b1992009-08-11 05:31:07 +00008119 if (!getDerived().AlwaysRebuild() &&
8120 T == E->getType() &&
8121 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008122 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008123 // Mark the constructor as referenced.
8124 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008125 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008126 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008127 }
Mike Stump1eb44332009-09-09 15:08:12 +00008128
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008129 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8130 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008131 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008132 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008133 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008134 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008135 E->getConstructionKind(),
8136 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008137}
Mike Stump1eb44332009-09-09 15:08:12 +00008138
Douglas Gregorb98b1992009-08-11 05:31:07 +00008139/// \brief Transform a C++ temporary-binding expression.
8140///
Douglas Gregor51326552009-12-24 18:51:59 +00008141/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8142/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008144ExprResult
John McCall454feb92009-12-08 09:21:05 +00008145TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008146 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008147}
Mike Stump1eb44332009-09-09 15:08:12 +00008148
John McCall4765fa02010-12-06 08:20:24 +00008149/// \brief Transform a C++ expression that contains cleanups that should
8150/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151///
John McCall4765fa02010-12-06 08:20:24 +00008152/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008153/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008155ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008156TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008157 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158}
Mike Stump1eb44332009-09-09 15:08:12 +00008159
Douglas Gregorb98b1992009-08-11 05:31:07 +00008160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008161ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008162TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008163 CXXTemporaryObjectExpr *E) {
8164 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8165 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008167
Douglas Gregorb98b1992009-08-11 05:31:07 +00008168 CXXConstructorDecl *Constructor
8169 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008170 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008171 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008174
Douglas Gregorb98b1992009-08-11 05:31:07 +00008175 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008176 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008177 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008178 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008179 &ArgumentChanged))
8180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008181
Douglas Gregorb98b1992009-08-11 05:31:07 +00008182 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008183 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008184 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008185 !ArgumentChanged) {
8186 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008187 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008188 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008189 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008190
Richard Smithc83c2302012-12-19 01:39:02 +00008191 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008192 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8193 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008194 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008195 E->getLocEnd());
8196}
Mike Stump1eb44332009-09-09 15:08:12 +00008197
Douglas Gregorb98b1992009-08-11 05:31:07 +00008198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008199ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008200TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008201 // Transform the type of the lambda parameters and start the definition of
8202 // the lambda itself.
8203 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008204 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008205 if (!MethodTy)
8206 return ExprError();
8207
Eli Friedman8da8a662012-09-19 01:18:11 +00008208 // Create the local class that will describe the lambda.
8209 CXXRecordDecl *Class
8210 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8211 MethodTy,
8212 /*KnownDependent=*/false);
8213 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8214
Douglas Gregorc6889e72012-02-14 22:28:59 +00008215 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008216 SmallVector<QualType, 4> ParamTypes;
8217 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008218 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8219 E->getCallOperator()->param_begin(),
8220 E->getCallOperator()->param_size(),
8221 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008222 return ExprError();
Manuel Klimek152b4e42013-08-22 12:12:24 +00008223
Douglas Gregordfca6f52012-02-13 22:00:16 +00008224 // Build the call operator.
8225 CXXMethodDecl *CallOperator
8226 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008227 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008228 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008229 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008230 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008231
Richard Smith612409e2012-07-25 03:56:55 +00008232 return getDerived().TransformLambdaScope(E, CallOperator);
8233}
8234
8235template<typename Derived>
8236ExprResult
8237TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8238 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008239 bool Invalid = false;
8240
8241 // Transform any init-capture expressions before entering the scope of the
8242 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008243 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008244 InitCaptureExprs.resize(E->explicit_capture_end() -
8245 E->explicit_capture_begin());
8246 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8247 CEnd = E->capture_end();
8248 C != CEnd; ++C) {
8249 if (!C->isInitCapture())
8250 continue;
8251 InitCaptureExprs[C - E->capture_begin()] =
8252 getDerived().TransformExpr(E->getInitCaptureInit(C));
8253 }
8254
Douglas Gregord5387e82012-02-14 00:00:48 +00008255 // Introduce the context of the call operator.
8256 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8257
Douglas Gregordfca6f52012-02-13 22:00:16 +00008258 // Enter the scope of the lambda.
Manuel Klimek152b4e42013-08-22 12:12:24 +00008259 sema::LambdaScopeInfo *LSI
8260 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008261 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008262 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008263 E->hasExplicitParameters(),
8264 E->hasExplicitResultType(),
8265 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008266
Douglas Gregordfca6f52012-02-13 22:00:16 +00008267 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008268 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008269 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008270 CEnd = E->capture_end();
8271 C != CEnd; ++C) {
8272 // When we hit the first implicit capture, tell Sema that we've finished
8273 // the list of explicit captures.
8274 if (!FinishedExplicitCaptures && C->isImplicit()) {
8275 getSema().finishLambdaExplicitCaptures(LSI);
8276 FinishedExplicitCaptures = true;
8277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008278
Douglas Gregordfca6f52012-02-13 22:00:16 +00008279 // Capturing 'this' is trivial.
8280 if (C->capturesThis()) {
8281 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8282 continue;
8283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008284
Richard Smith0d8e9642013-05-16 06:20:58 +00008285 // Rebuild init-captures, including the implied field declaration.
8286 if (C->isInitCapture()) {
8287 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8288 if (Init.isInvalid()) {
8289 Invalid = true;
8290 continue;
8291 }
8292 FieldDecl *OldFD = C->getInitCaptureField();
8293 FieldDecl *NewFD = getSema().checkInitCapture(
8294 C->getLocation(), OldFD->getType()->isReferenceType(),
8295 OldFD->getIdentifier(), Init.take());
8296 if (!NewFD)
8297 Invalid = true;
8298 else
8299 getDerived().transformedLocalDecl(OldFD, NewFD);
8300 continue;
8301 }
8302
8303 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8304
Douglas Gregora7365242012-02-14 19:27:52 +00008305 // Determine the capture kind for Sema.
8306 Sema::TryCaptureKind Kind
8307 = C->isImplicit()? Sema::TryCapture_Implicit
8308 : C->getCaptureKind() == LCK_ByCopy
8309 ? Sema::TryCapture_ExplicitByVal
8310 : Sema::TryCapture_ExplicitByRef;
8311 SourceLocation EllipsisLoc;
8312 if (C->isPackExpansion()) {
8313 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8314 bool ShouldExpand = false;
8315 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008316 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008317 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8318 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008319 Unexpanded,
8320 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008321 NumExpansions)) {
8322 Invalid = true;
8323 continue;
8324 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008325
Douglas Gregora7365242012-02-14 19:27:52 +00008326 if (ShouldExpand) {
8327 // The transform has determined that we should perform an expansion;
8328 // transform and capture each of the arguments.
8329 // expansion of the pattern. Do so.
8330 VarDecl *Pack = C->getCapturedVar();
8331 for (unsigned I = 0; I != *NumExpansions; ++I) {
8332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8333 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008334 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008335 Pack));
8336 if (!CapturedVar) {
8337 Invalid = true;
8338 continue;
8339 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008340
Douglas Gregora7365242012-02-14 19:27:52 +00008341 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008342 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8343 }
Douglas Gregora7365242012-02-14 19:27:52 +00008344 continue;
8345 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008346
Douglas Gregora7365242012-02-14 19:27:52 +00008347 EllipsisLoc = C->getEllipsisLoc();
8348 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008349
Douglas Gregordfca6f52012-02-13 22:00:16 +00008350 // Transform the captured variable.
8351 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008352 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008353 C->getCapturedVar()));
8354 if (!CapturedVar) {
8355 Invalid = true;
8356 continue;
8357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008358
Douglas Gregordfca6f52012-02-13 22:00:16 +00008359 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008360 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008361 }
8362 if (!FinishedExplicitCaptures)
8363 getSema().finishLambdaExplicitCaptures(LSI);
8364
Douglas Gregordfca6f52012-02-13 22:00:16 +00008365
8366 // Enter a new evaluation context to insulate the lambda from any
8367 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008369
8370 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008371 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008372 /*IsInstantiation=*/true);
8373 return ExprError();
8374 }
8375
8376 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008377 StmtResult Body = getDerived().TransformStmt(E->getBody());
8378 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008379 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008380 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008381 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008382 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008383
Chad Rosier4a9d7952012-08-08 18:46:20 +00008384 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008385 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008386}
8387
8388template<typename Derived>
8389ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008390TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008391 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008392 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8393 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008394 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008395
Douglas Gregorb98b1992009-08-11 05:31:07 +00008396 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008397 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008398 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008400 &ArgumentChanged))
8401 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008402
Douglas Gregorb98b1992009-08-11 05:31:07 +00008403 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008404 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008405 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008406 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008407
Douglas Gregorb98b1992009-08-11 05:31:07 +00008408 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008409 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008410 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008411 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008412 E->getRParenLoc());
8413}
Mike Stump1eb44332009-09-09 15:08:12 +00008414
Douglas Gregorb98b1992009-08-11 05:31:07 +00008415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008416ExprResult
John McCall865d4472009-11-19 22:55:06 +00008417TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008418 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008419 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008420 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008421 Expr *OldBase;
8422 QualType BaseType;
8423 QualType ObjectType;
8424 if (!E->isImplicitAccess()) {
8425 OldBase = E->getBase();
8426 Base = getDerived().TransformExpr(OldBase);
8427 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008429
John McCallaa81e162009-12-01 22:10:20 +00008430 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008431 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008432 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008433 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008434 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008435 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008436 ObjectTy,
8437 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008438 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008439 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008440
John McCallb3d87482010-08-24 05:47:05 +00008441 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008442 BaseType = ((Expr*) Base.get())->getType();
8443 } else {
8444 OldBase = 0;
8445 BaseType = getDerived().TransformType(E->getBaseType());
8446 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8447 }
Mike Stump1eb44332009-09-09 15:08:12 +00008448
Douglas Gregor6cd21982009-10-20 05:58:46 +00008449 // Transform the first part of the nested-name-specifier that qualifies
8450 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008451 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008452 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008453 E->getFirstQualifierFoundInScope(),
8454 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008455
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008456 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008457 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008458 QualifierLoc
8459 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8460 ObjectType,
8461 FirstQualifierInScope);
8462 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008463 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008464 }
Mike Stump1eb44332009-09-09 15:08:12 +00008465
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008466 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8467
John McCall43fed0d2010-11-12 08:19:04 +00008468 // TODO: If this is a conversion-function-id, verify that the
8469 // destination type name (if present) resolves the same way after
8470 // instantiation as it did in the local scope.
8471
Abramo Bagnara25777432010-08-11 22:01:17 +00008472 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008473 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008474 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008475 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008476
John McCallaa81e162009-12-01 22:10:20 +00008477 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008478 // This is a reference to a member without an explicitly-specified
8479 // template argument list. Optimize for this common case.
8480 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008481 Base.get() == OldBase &&
8482 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008483 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008484 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008485 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008487
John McCall9ae2f072010-08-23 23:25:46 +00008488 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008489 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008490 E->isArrow(),
8491 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008492 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008493 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008494 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008495 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008496 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008497 }
8498
John McCalld5532b62009-11-23 01:53:49 +00008499 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008500 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8501 E->getNumTemplateArgs(),
8502 TransArgs))
8503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008504
John McCall9ae2f072010-08-23 23:25:46 +00008505 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008506 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008507 E->isArrow(),
8508 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008509 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008510 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008511 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008512 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008513 &TransArgs);
8514}
8515
8516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008517ExprResult
John McCall454feb92009-12-08 09:21:05 +00008518TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008519 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008520 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008521 QualType BaseType;
8522 if (!Old->isImplicitAccess()) {
8523 Base = getDerived().TransformExpr(Old->getBase());
8524 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008525 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008526 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8527 Old->isArrow());
8528 if (Base.isInvalid())
8529 return ExprError();
8530 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008531 } else {
8532 BaseType = getDerived().TransformType(Old->getBaseType());
8533 }
John McCall129e2df2009-11-30 22:42:35 +00008534
Douglas Gregor4c9be892011-02-28 20:01:57 +00008535 NestedNameSpecifierLoc QualifierLoc;
8536 if (Old->getQualifierLoc()) {
8537 QualifierLoc
8538 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8539 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008540 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008541 }
8542
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008543 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8544
Abramo Bagnara25777432010-08-11 22:01:17 +00008545 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008546 Sema::LookupOrdinaryName);
8547
8548 // Transform all the decls.
8549 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8550 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008551 NamedDecl *InstD = static_cast<NamedDecl*>(
8552 getDerived().TransformDecl(Old->getMemberLoc(),
8553 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008554 if (!InstD) {
8555 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8556 // This can happen because of dependent hiding.
8557 if (isa<UsingShadowDecl>(*I))
8558 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008559 else {
8560 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008561 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008562 }
John McCall9f54ad42009-12-10 09:41:52 +00008563 }
John McCall129e2df2009-11-30 22:42:35 +00008564
8565 // Expand using declarations.
8566 if (isa<UsingDecl>(InstD)) {
8567 UsingDecl *UD = cast<UsingDecl>(InstD);
8568 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8569 E = UD->shadow_end(); I != E; ++I)
8570 R.addDecl(*I);
8571 continue;
8572 }
8573
8574 R.addDecl(InstD);
8575 }
8576
8577 R.resolveKind();
8578
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008579 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008580 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008581 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008582 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008583 Old->getMemberLoc(),
8584 Old->getNamingClass()));
8585 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008586 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008587
Douglas Gregor66c45152010-04-27 16:10:10 +00008588 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008589 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008590
John McCall129e2df2009-11-30 22:42:35 +00008591 TemplateArgumentListInfo TransArgs;
8592 if (Old->hasExplicitTemplateArgs()) {
8593 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8594 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008595 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8596 Old->getNumTemplateArgs(),
8597 TransArgs))
8598 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008599 }
John McCallc2233c52010-01-15 08:34:02 +00008600
8601 // FIXME: to do this check properly, we will need to preserve the
8602 // first-qualifier-in-scope here, just in case we had a dependent
8603 // base (and therefore couldn't do the check) and a
8604 // nested-name-qualifier (and therefore could do the lookup).
8605 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008606
John McCall9ae2f072010-08-23 23:25:46 +00008607 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008608 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008609 Old->getOperatorLoc(),
8610 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008611 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008612 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008613 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008614 R,
8615 (Old->hasExplicitTemplateArgs()
8616 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008617}
8618
8619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008620ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008621TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008622 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008623 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8624 if (SubExpr.isInvalid())
8625 return ExprError();
8626
8627 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008628 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008629
8630 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8631}
8632
8633template<typename Derived>
8634ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008635TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008636 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8637 if (Pattern.isInvalid())
8638 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008640 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8641 return SemaRef.Owned(E);
8642
Douglas Gregor67fd1252011-01-14 21:20:45 +00008643 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8644 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008645}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008646
8647template<typename Derived>
8648ExprResult
8649TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8650 // If E is not value-dependent, then nothing will change when we transform it.
8651 // Note: This is an instantiation-centric view.
8652 if (!E->isValueDependent())
8653 return SemaRef.Owned(E);
8654
8655 // Note: None of the implementations of TryExpandParameterPacks can ever
8656 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008657 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008658 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8659 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008660 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008661 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008662 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008663 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008664 ShouldExpand, RetainExpansion,
8665 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008666 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008667
Douglas Gregor089e8932011-10-10 18:59:29 +00008668 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008669 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008670
Douglas Gregor089e8932011-10-10 18:59:29 +00008671 NamedDecl *Pack = E->getPack();
8672 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008674 Pack));
8675 if (!Pack)
8676 return ExprError();
8677 }
8678
Chad Rosier4a9d7952012-08-08 18:46:20 +00008679
Douglas Gregoree8aff02011-01-04 17:33:58 +00008680 // We now know the length of the parameter pack, so build a new expression
8681 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008682 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8683 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008684 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008685}
8686
Douglas Gregorbe230c32011-01-03 17:17:50 +00008687template<typename Derived>
8688ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008689TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8690 SubstNonTypeTemplateParmPackExpr *E) {
8691 // Default behavior is to do nothing with this transformation.
8692 return SemaRef.Owned(E);
8693}
8694
8695template<typename Derived>
8696ExprResult
John McCall91a57552011-07-15 05:09:51 +00008697TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8698 SubstNonTypeTemplateParmExpr *E) {
8699 // Default behavior is to do nothing with this transformation.
8700 return SemaRef.Owned(E);
8701}
8702
8703template<typename Derived>
8704ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008705TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8706 // Default behavior is to do nothing with this transformation.
8707 return SemaRef.Owned(E);
8708}
8709
8710template<typename Derived>
8711ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008712TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8713 MaterializeTemporaryExpr *E) {
8714 return getDerived().TransformExpr(E->GetTemporaryExpr());
8715}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716
Douglas Gregor03e80032011-06-21 17:03:29 +00008717template<typename Derived>
8718ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008719TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8720 CXXStdInitializerListExpr *E) {
8721 return getDerived().TransformExpr(E->getSubExpr());
8722}
8723
8724template<typename Derived>
8725ExprResult
John McCall454feb92009-12-08 09:21:05 +00008726TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008727 return SemaRef.MaybeBindToTemporary(E);
8728}
8729
8730template<typename Derived>
8731ExprResult
8732TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008733 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008734}
8735
8736template<typename Derived>
8737ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008738TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8739 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8740 if (SubExpr.isInvalid())
8741 return ExprError();
8742
8743 if (!getDerived().AlwaysRebuild() &&
8744 SubExpr.get() == E->getSubExpr())
8745 return SemaRef.Owned(E);
8746
8747 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008748}
8749
8750template<typename Derived>
8751ExprResult
8752TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8753 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008754 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008755 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008757 /*IsCall=*/false, Elements, &ArgChanged))
8758 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008759
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008760 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8761 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008762
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008763 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8764 Elements.data(),
8765 Elements.size());
8766}
8767
8768template<typename Derived>
8769ExprResult
8770TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008772 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008773 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008774 bool ArgChanged = false;
8775 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8776 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008777
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008778 if (OrigElement.isPackExpansion()) {
8779 // This key/value element is a pack expansion.
8780 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8781 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8782 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8783 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8784
8785 // Determine whether the set of unexpanded parameter packs can
8786 // and should be expanded.
8787 bool Expand = true;
8788 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008789 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8790 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008791 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8792 OrigElement.Value->getLocEnd());
8793 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8794 PatternRange,
8795 Unexpanded,
8796 Expand, RetainExpansion,
8797 NumExpansions))
8798 return ExprError();
8799
8800 if (!Expand) {
8801 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008803 // expansion.
8804 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8805 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8806 if (Key.isInvalid())
8807 return ExprError();
8808
8809 if (Key.get() != OrigElement.Key)
8810 ArgChanged = true;
8811
8812 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8813 if (Value.isInvalid())
8814 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008815
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008816 if (Value.get() != OrigElement.Value)
8817 ArgChanged = true;
8818
Chad Rosier4a9d7952012-08-08 18:46:20 +00008819 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008820 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8821 };
8822 Elements.push_back(Expansion);
8823 continue;
8824 }
8825
8826 // Record right away that the argument was changed. This needs
8827 // to happen even if the array expands to nothing.
8828 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008829
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008830 // The transform has determined that we should perform an elementwise
8831 // expansion of the pattern. Do so.
8832 for (unsigned I = 0; I != *NumExpansions; ++I) {
8833 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8834 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8835 if (Key.isInvalid())
8836 return ExprError();
8837
8838 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8839 if (Value.isInvalid())
8840 return ExprError();
8841
Chad Rosier4a9d7952012-08-08 18:46:20 +00008842 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008843 Key.get(), Value.get(), SourceLocation(), NumExpansions
8844 };
8845
8846 // If any unexpanded parameter packs remain, we still have a
8847 // pack expansion.
8848 if (Key.get()->containsUnexpandedParameterPack() ||
8849 Value.get()->containsUnexpandedParameterPack())
8850 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008851
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008852 Elements.push_back(Element);
8853 }
8854
8855 // We've finished with this pack expansion.
8856 continue;
8857 }
8858
8859 // Transform and check key.
8860 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8861 if (Key.isInvalid())
8862 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008863
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008864 if (Key.get() != OrigElement.Key)
8865 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008867 // Transform and check value.
8868 ExprResult Value
8869 = getDerived().TransformExpr(OrigElement.Value);
8870 if (Value.isInvalid())
8871 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008872
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008873 if (Value.get() != OrigElement.Value)
8874 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008875
8876 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008877 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878 };
8879 Elements.push_back(Element);
8880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008881
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008882 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8883 return SemaRef.MaybeBindToTemporary(E);
8884
8885 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8886 Elements.data(),
8887 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008888}
8889
Mike Stump1eb44332009-09-09 15:08:12 +00008890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008891ExprResult
John McCall454feb92009-12-08 09:21:05 +00008892TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008893 TypeSourceInfo *EncodedTypeInfo
8894 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8895 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008897
Douglas Gregorb98b1992009-08-11 05:31:07 +00008898 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008899 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008900 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008901
8902 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008903 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008904 E->getRParenLoc());
8905}
Mike Stump1eb44332009-09-09 15:08:12 +00008906
Douglas Gregorb98b1992009-08-11 05:31:07 +00008907template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008908ExprResult TreeTransform<Derived>::
8909TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008910 // This is a kind of implicit conversion, and it needs to get dropped
8911 // and recomputed for the same general reasons that ImplicitCastExprs
8912 // do, as well a more specific one: this expression is only valid when
8913 // it appears *immediately* as an argument expression.
8914 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008915}
8916
8917template<typename Derived>
8918ExprResult TreeTransform<Derived>::
8919TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008920 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008921 = getDerived().TransformType(E->getTypeInfoAsWritten());
8922 if (!TSInfo)
8923 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008924
John McCallf85e1932011-06-15 23:02:42 +00008925 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008926 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008927 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008928
John McCallf85e1932011-06-15 23:02:42 +00008929 if (!getDerived().AlwaysRebuild() &&
8930 TSInfo == E->getTypeInfoAsWritten() &&
8931 Result.get() == E->getSubExpr())
8932 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008933
John McCallf85e1932011-06-15 23:02:42 +00008934 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008935 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008936 Result.get());
8937}
8938
8939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008940ExprResult
John McCall454feb92009-12-08 09:21:05 +00008941TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008942 // Transform arguments.
8943 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008944 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008945 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008946 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008947 &ArgChanged))
8948 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008949
Douglas Gregor92e986e2010-04-22 16:44:27 +00008950 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8951 // Class message: transform the receiver type.
8952 TypeSourceInfo *ReceiverTypeInfo
8953 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8954 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008955 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008956
Douglas Gregor92e986e2010-04-22 16:44:27 +00008957 // If nothing changed, just retain the existing message send.
8958 if (!getDerived().AlwaysRebuild() &&
8959 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008960 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008961
8962 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008963 SmallVector<SourceLocation, 16> SelLocs;
8964 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008965 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8966 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008967 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008968 E->getMethodDecl(),
8969 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008970 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008971 E->getRightLoc());
8972 }
8973
8974 // Instance message: transform the receiver
8975 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8976 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008977 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008978 = getDerived().TransformExpr(E->getInstanceReceiver());
8979 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008980 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008981
8982 // If nothing changed, just retain the existing message send.
8983 if (!getDerived().AlwaysRebuild() &&
8984 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008985 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008986
Douglas Gregor92e986e2010-04-22 16:44:27 +00008987 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008988 SmallVector<SourceLocation, 16> SelLocs;
8989 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008990 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008991 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008992 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008993 E->getMethodDecl(),
8994 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008995 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008996 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008997}
8998
Mike Stump1eb44332009-09-09 15:08:12 +00008999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009000ExprResult
John McCall454feb92009-12-08 09:21:05 +00009001TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009002 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009003}
9004
Mike Stump1eb44332009-09-09 15:08:12 +00009005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009006ExprResult
John McCall454feb92009-12-08 09:21:05 +00009007TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009008 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009009}
9010
Mike Stump1eb44332009-09-09 15:08:12 +00009011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009012ExprResult
John McCall454feb92009-12-08 09:21:05 +00009013TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009014 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009015 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009016 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009017 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009018
9019 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009020
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009021 // If nothing changed, just retain the existing expression.
9022 if (!getDerived().AlwaysRebuild() &&
9023 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009024 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009025
John McCall9ae2f072010-08-23 23:25:46 +00009026 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009027 E->getLocation(),
9028 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009029}
9030
Mike Stump1eb44332009-09-09 15:08:12 +00009031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009032ExprResult
John McCall454feb92009-12-08 09:21:05 +00009033TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009034 // 'super' and types never change. Property never changes. Just
9035 // retain the existing expression.
9036 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009037 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009038
Douglas Gregore3303542010-04-26 20:47:02 +00009039 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009040 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009041 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009042 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009043
Douglas Gregore3303542010-04-26 20:47:02 +00009044 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009045
Douglas Gregore3303542010-04-26 20:47:02 +00009046 // If nothing changed, just retain the existing expression.
9047 if (!getDerived().AlwaysRebuild() &&
9048 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009049 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009050
John McCall12f78a62010-12-02 01:19:52 +00009051 if (E->isExplicitProperty())
9052 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9053 E->getExplicitProperty(),
9054 E->getLocation());
9055
9056 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009057 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009058 E->getImplicitPropertyGetter(),
9059 E->getImplicitPropertySetter(),
9060 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009061}
9062
Mike Stump1eb44332009-09-09 15:08:12 +00009063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009064ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009065TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9066 // Transform the base expression.
9067 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9068 if (Base.isInvalid())
9069 return ExprError();
9070
9071 // Transform the key expression.
9072 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9073 if (Key.isInvalid())
9074 return ExprError();
9075
9076 // If nothing changed, just retain the existing expression.
9077 if (!getDerived().AlwaysRebuild() &&
9078 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9079 return SemaRef.Owned(E);
9080
Chad Rosier4a9d7952012-08-08 18:46:20 +00009081 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009082 Base.get(), Key.get(),
9083 E->getAtIndexMethodDecl(),
9084 E->setAtIndexMethodDecl());
9085}
9086
9087template<typename Derived>
9088ExprResult
John McCall454feb92009-12-08 09:21:05 +00009089TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009090 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009091 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009092 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009093 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009094
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009095 // If nothing changed, just retain the existing expression.
9096 if (!getDerived().AlwaysRebuild() &&
9097 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009098 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009099
John McCall9ae2f072010-08-23 23:25:46 +00009100 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009101 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009102 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009103}
9104
Mike Stump1eb44332009-09-09 15:08:12 +00009105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009106ExprResult
John McCall454feb92009-12-08 09:21:05 +00009107TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009108 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009109 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009110 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009111 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009112 SubExprs, &ArgumentChanged))
9113 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009114
Douglas Gregorb98b1992009-08-11 05:31:07 +00009115 if (!getDerived().AlwaysRebuild() &&
9116 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009117 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009118
Douglas Gregorb98b1992009-08-11 05:31:07 +00009119 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009120 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009121 E->getRParenLoc());
9122}
9123
Mike Stump1eb44332009-09-09 15:08:12 +00009124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009125ExprResult
John McCall454feb92009-12-08 09:21:05 +00009126TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009127 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009128
John McCallc6ac9c32011-02-04 18:33:18 +00009129 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9130 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9131
9132 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009133 blockScope->TheDecl->setBlockMissingReturnType(
9134 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009135
Chris Lattner686775d2011-07-20 06:58:45 +00009136 SmallVector<ParmVarDecl*, 4> params;
9137 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009138
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009139 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009140 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9141 oldBlock->param_begin(),
9142 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009143 0, paramTypes, &params)) {
9144 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009145 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009146 }
John McCallc6ac9c32011-02-04 18:33:18 +00009147
Jordan Rose09189892013-03-08 22:25:36 +00009148 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009149 QualType exprResultType =
9150 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009151
Jordan Rosebea522f2013-03-08 21:51:21 +00009152 QualType functionType =
9153 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009154 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009155 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009156
9157 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009158 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009159 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009160
9161 if (!oldBlock->blockMissingReturnType()) {
9162 blockScope->HasImplicitReturnType = false;
9163 blockScope->ReturnType = exprResultType;
9164 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009165
John McCall711c52b2011-01-05 12:14:39 +00009166 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009167 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009168 if (body.isInvalid()) {
9169 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009170 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009171 }
John McCall711c52b2011-01-05 12:14:39 +00009172
John McCallc6ac9c32011-02-04 18:33:18 +00009173#ifndef NDEBUG
9174 // In builds with assertions, make sure that we captured everything we
9175 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009176 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9177 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9178 e = oldBlock->capture_end(); i != e; ++i) {
9179 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009180
Douglas Gregorfc921372011-05-20 15:32:55 +00009181 // Ignore parameter packs.
9182 if (isa<ParmVarDecl>(oldCapture) &&
9183 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9184 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009185
Douglas Gregorfc921372011-05-20 15:32:55 +00009186 VarDecl *newCapture =
9187 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9188 oldCapture));
9189 assert(blockScope->CaptureMap.count(newCapture));
9190 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009191 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009192 }
9193#endif
9194
9195 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9196 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009197}
9198
Mike Stump1eb44332009-09-09 15:08:12 +00009199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009200ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009201TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009202 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009203}
Eli Friedman276b0612011-10-11 02:20:01 +00009204
9205template<typename Derived>
9206ExprResult
9207TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009208 QualType RetTy = getDerived().TransformType(E->getType());
9209 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009210 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009211 SubExprs.reserve(E->getNumSubExprs());
9212 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9213 SubExprs, &ArgumentChanged))
9214 return ExprError();
9215
9216 if (!getDerived().AlwaysRebuild() &&
9217 !ArgumentChanged)
9218 return SemaRef.Owned(E);
9219
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009220 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009221 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009222}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009223
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009225// Type reconstruction
9226//===----------------------------------------------------------------------===//
9227
Mike Stump1eb44332009-09-09 15:08:12 +00009228template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009229QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9230 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009231 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009232 getDerived().getBaseEntity());
9233}
9234
Mike Stump1eb44332009-09-09 15:08:12 +00009235template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009236QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9237 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009238 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009239 getDerived().getBaseEntity());
9240}
9241
Mike Stump1eb44332009-09-09 15:08:12 +00009242template<typename Derived>
9243QualType
John McCall85737a72009-10-30 00:06:24 +00009244TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9245 bool WrittenAsLValue,
9246 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009247 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009248 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009249}
9250
9251template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009252QualType
John McCall85737a72009-10-30 00:06:24 +00009253TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9254 QualType ClassType,
9255 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009256 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009257 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009258}
9259
9260template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009261QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009262TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9263 ArrayType::ArraySizeModifier SizeMod,
9264 const llvm::APInt *Size,
9265 Expr *SizeExpr,
9266 unsigned IndexTypeQuals,
9267 SourceRange BracketsRange) {
9268 if (SizeExpr || !Size)
9269 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9270 IndexTypeQuals, BracketsRange,
9271 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009272
9273 QualType Types[] = {
9274 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9275 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9276 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009277 };
Craig Topperb9602322013-07-15 03:38:40 +00009278 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009279 QualType SizeType;
9280 for (unsigned I = 0; I != NumTypes; ++I)
9281 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9282 SizeType = Types[I];
9283 break;
9284 }
Mike Stump1eb44332009-09-09 15:08:12 +00009285
Eli Friedman01f276d2012-01-25 23:20:27 +00009286 // Note that we can return a VariableArrayType here in the case where
9287 // the element type was a dependent VariableArrayType.
9288 IntegerLiteral *ArraySize
9289 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9290 /*FIXME*/BracketsRange.getBegin());
9291 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009292 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009293 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009294}
Mike Stump1eb44332009-09-09 15:08:12 +00009295
Douglas Gregor577f75a2009-08-04 16:50:30 +00009296template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009297QualType
9298TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009299 ArrayType::ArraySizeModifier SizeMod,
9300 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009301 unsigned IndexTypeQuals,
9302 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009303 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009304 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009305}
9306
9307template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009308QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009309TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009310 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009311 unsigned IndexTypeQuals,
9312 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009313 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009314 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009315}
Mike Stump1eb44332009-09-09 15:08:12 +00009316
Douglas Gregor577f75a2009-08-04 16:50:30 +00009317template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009318QualType
9319TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009320 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009321 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009322 unsigned IndexTypeQuals,
9323 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009324 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009325 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009326 IndexTypeQuals, BracketsRange);
9327}
9328
9329template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009330QualType
9331TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009332 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009333 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009334 unsigned IndexTypeQuals,
9335 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009336 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009337 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009338 IndexTypeQuals, BracketsRange);
9339}
9340
9341template<typename Derived>
9342QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009343 unsigned NumElements,
9344 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009345 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009346 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009347}
Mike Stump1eb44332009-09-09 15:08:12 +00009348
Douglas Gregor577f75a2009-08-04 16:50:30 +00009349template<typename Derived>
9350QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9351 unsigned NumElements,
9352 SourceLocation AttributeLoc) {
9353 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9354 NumElements, true);
9355 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009356 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9357 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009358 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009359}
Mike Stump1eb44332009-09-09 15:08:12 +00009360
Douglas Gregor577f75a2009-08-04 16:50:30 +00009361template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009362QualType
9363TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009364 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009365 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009366 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009367}
Mike Stump1eb44332009-09-09 15:08:12 +00009368
Douglas Gregor577f75a2009-08-04 16:50:30 +00009369template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009370QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9371 QualType T,
9372 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009373 const FunctionProtoType::ExtProtoInfo &EPI) {
9374 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009375 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009376 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009377 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009378}
Mike Stump1eb44332009-09-09 15:08:12 +00009379
Douglas Gregor577f75a2009-08-04 16:50:30 +00009380template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009381QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9382 return SemaRef.Context.getFunctionNoProtoType(T);
9383}
9384
9385template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009386QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9387 assert(D && "no decl found");
9388 if (D->isInvalidDecl()) return QualType();
9389
Douglas Gregor92e986e2010-04-22 16:44:27 +00009390 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009391 TypeDecl *Ty;
9392 if (isa<UsingDecl>(D)) {
9393 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009394 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009395 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9396
9397 // A valid resolved using typename decl points to exactly one type decl.
9398 assert(++Using->shadow_begin() == Using->shadow_end());
9399 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009400
John McCalled976492009-12-04 22:46:56 +00009401 } else {
9402 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9403 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9404 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9405 }
9406
9407 return SemaRef.Context.getTypeDeclType(Ty);
9408}
9409
9410template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009411QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9412 SourceLocation Loc) {
9413 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009414}
9415
9416template<typename Derived>
9417QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9418 return SemaRef.Context.getTypeOfType(Underlying);
9419}
9420
9421template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009422QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9423 SourceLocation Loc) {
9424 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009425}
9426
9427template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009428QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9429 UnaryTransformType::UTTKind UKind,
9430 SourceLocation Loc) {
9431 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9432}
9433
9434template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009435QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009436 TemplateName Template,
9437 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009438 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009439 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009440}
Mike Stump1eb44332009-09-09 15:08:12 +00009441
Douglas Gregordcee1a12009-08-06 05:28:30 +00009442template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009443QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9444 SourceLocation KWLoc) {
9445 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9446}
9447
9448template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009449TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009450TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009451 bool TemplateKW,
9452 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009453 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009454 Template);
9455}
9456
9457template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009458TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009459TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9460 const IdentifierInfo &Name,
9461 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009462 QualType ObjectType,
9463 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009464 UnqualifiedId TemplateName;
9465 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009466 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009467 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009468 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009469 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009470 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009471 /*EnteringContext=*/false,
9472 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009473 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009474}
Mike Stump1eb44332009-09-09 15:08:12 +00009475
Douglas Gregorb98b1992009-08-11 05:31:07 +00009476template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009477TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009478TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009479 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009480 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009481 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009482 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009483 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009484 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009485 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009486 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009487 Sema::TemplateTy Template;
9488 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009489 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009490 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009491 /*EnteringContext=*/false,
9492 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009493 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009494}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009495
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009497ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009498TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9499 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009500 Expr *OrigCallee,
9501 Expr *First,
9502 Expr *Second) {
9503 Expr *Callee = OrigCallee->IgnoreParenCasts();
9504 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009505
Douglas Gregorb98b1992009-08-11 05:31:07 +00009506 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009507 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009508 if (!First->getType()->isOverloadableType() &&
9509 !Second->getType()->isOverloadableType())
9510 return getSema().CreateBuiltinArraySubscriptExpr(First,
9511 Callee->getLocStart(),
9512 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009513 } else if (Op == OO_Arrow) {
9514 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009515 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9516 } else if (Second == 0 || isPostIncDec) {
9517 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009518 // The argument is not of overloadable type, so try to create a
9519 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009520 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009521 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009522
John McCall9ae2f072010-08-23 23:25:46 +00009523 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009524 }
9525 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009526 if (!First->getType()->isOverloadableType() &&
9527 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009528 // Neither of the arguments is an overloadable type, so try to
9529 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009530 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009531 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009532 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009533 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009534 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009535
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009536 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009537 }
9538 }
Mike Stump1eb44332009-09-09 15:08:12 +00009539
9540 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009541 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009542 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009543
John McCall9ae2f072010-08-23 23:25:46 +00009544 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009545 assert(ULE->requiresADL());
9546
9547 // FIXME: Do we have to check
9548 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009549 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009550 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009551 // If we've resolved this to a particular non-member function, just call
9552 // that function. If we resolved it to a member function,
9553 // CreateOverloaded* will find that function for us.
9554 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9555 if (!isa<CXXMethodDecl>(ND))
9556 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009557 }
Mike Stump1eb44332009-09-09 15:08:12 +00009558
Douglas Gregorb98b1992009-08-11 05:31:07 +00009559 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009560 Expr *Args[2] = { First, Second };
9561 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009562
Douglas Gregorb98b1992009-08-11 05:31:07 +00009563 // Create the overloaded operator invocation for unary operators.
9564 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009565 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009566 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009567 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009568 }
Mike Stump1eb44332009-09-09 15:08:12 +00009569
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009570 if (Op == OO_Subscript) {
9571 SourceLocation LBrace;
9572 SourceLocation RBrace;
9573
9574 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9575 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9576 LBrace = SourceLocation::getFromRawEncoding(
9577 NameLoc.CXXOperatorName.BeginOpNameLoc);
9578 RBrace = SourceLocation::getFromRawEncoding(
9579 NameLoc.CXXOperatorName.EndOpNameLoc);
9580 } else {
9581 LBrace = Callee->getLocStart();
9582 RBrace = OpLoc;
9583 }
9584
9585 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9586 First, Second);
9587 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009588
Douglas Gregorb98b1992009-08-11 05:31:07 +00009589 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009590 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009591 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009592 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9593 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009595
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009596 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009597}
Mike Stump1eb44332009-09-09 15:08:12 +00009598
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009599template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009600ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009601TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009602 SourceLocation OperatorLoc,
9603 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009604 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009605 TypeSourceInfo *ScopeType,
9606 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009607 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009608 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009609 QualType BaseType = Base->getType();
9610 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009611 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009612 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009613 !BaseType->getAs<PointerType>()->getPointeeType()
9614 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009615 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009616 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009617 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009618 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009619 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009620 /*FIXME?*/true);
9621 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009622
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009623 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009624 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9625 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9626 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9627 NameInfo.setNamedTypeInfo(DestroyedType);
9628
Richard Smith6314db92012-05-15 06:15:11 +00009629 // The scope type is now known to be a valid nested name specifier
9630 // component. Tack it on to the end of the nested name specifier.
9631 if (ScopeType)
9632 SS.Extend(SemaRef.Context, SourceLocation(),
9633 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009634
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009635 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009636 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009637 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009638 SS, TemplateKWLoc,
9639 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009640 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009641 /*TemplateArgs*/ 0);
9642}
9643
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009644template<typename Derived>
9645StmtResult
9646TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009647 SourceLocation Loc = S->getLocStart();
9648 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9649 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9650 S->getCapturedRegionKind(), NumParams);
9651 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9652
9653 if (Body.isInvalid()) {
9654 getSema().ActOnCapturedRegionError();
9655 return StmtError();
9656 }
9657
9658 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009659}
9660
Douglas Gregor577f75a2009-08-04 16:50:30 +00009661} // end namespace clang
9662
9663#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H