blob: 34fdbad87b3401a5648a83202b1aeb3193207aa3 [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.
Richard Smitha2c36462013-04-26 16:15:35 +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.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001388 Stmt *TryBlock,
1389 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001390 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Richard Smithad762fc2011-04-14 22:09:26 +00001393 /// \brief Build a new C++0x range-based for statement.
1394 ///
1395 /// By default, performs semantic analysis to build the new statement.
1396 /// Subclasses may override this routine to provide different behavior.
1397 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1398 SourceLocation ColonLoc,
1399 Stmt *Range, Stmt *BeginEnd,
1400 Expr *Cond, Expr *Inc,
1401 Stmt *LoopVar,
1402 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001403 // If we've just learned that the range is actually an Objective-C
1404 // collection, treat this as an Objective-C fast enumeration loop.
1405 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1406 if (RangeStmt->isSingleDecl()) {
1407 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001408 if (RangeVar->isInvalidDecl())
1409 return StmtError();
1410
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001411 Expr *RangeExpr = RangeVar->getInit();
1412 if (!RangeExpr->isTypeDependent() &&
1413 RangeExpr->getType()->isObjCObjectPointerType())
1414 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1415 RParenLoc);
1416 }
1417 }
1418 }
1419
Richard Smithad762fc2011-04-14 22:09:26 +00001420 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001421 Cond, Inc, LoopVar, RParenLoc,
1422 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001423 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001424
1425 /// \brief Build a new C++0x range-based for statement.
1426 ///
1427 /// By default, performs semantic analysis to build the new statement.
1428 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001429 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001430 bool IsIfExists,
1431 NestedNameSpecifierLoc QualifierLoc,
1432 DeclarationNameInfo NameInfo,
1433 Stmt *Nested) {
1434 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1435 QualifierLoc, NameInfo, Nested);
1436 }
1437
Richard Smithad762fc2011-04-14 22:09:26 +00001438 /// \brief Attach body to a C++0x range-based for statement.
1439 ///
1440 /// By default, performs semantic analysis to finish the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
1442 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1443 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1444 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001445
John Wiegley28bbe4b2011-04-28 01:08:34 +00001446 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1447 SourceLocation TryLoc,
1448 Stmt *TryBlock,
1449 Stmt *Handler) {
1450 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1451 }
1452
1453 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1454 Expr *FilterExpr,
1455 Stmt *Block) {
1456 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1457 }
1458
1459 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1460 Stmt *Block) {
1461 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1462 }
1463
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// \brief Build a new expression that references a declaration.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001468 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001469 LookupResult &R,
1470 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001471 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1472 }
1473
1474
1475 /// \brief Build a new expression that references a declaration.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001479 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001480 ValueDecl *VD,
1481 const DeclarationNameInfo &NameInfo,
1482 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001483 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001484 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001485
1486 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001487
1488 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
Mike Stump1eb44332009-09-09 15:08:12 +00001490
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001492 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001495 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 }
1499
Douglas Gregora71d8192009-09-04 17:36:40 +00001500 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001501 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001505 SourceLocation OperatorLoc,
1506 bool isArrow,
1507 CXXScopeSpec &SS,
1508 TypeSourceInfo *ScopeType,
1509 SourceLocation CCLoc,
1510 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001511 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001518 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001519 Expr *SubExpr) {
1520 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001523 /// \brief Build a new builtin offsetof expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001528 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001529 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001530 unsigned NumComponents,
1531 SourceLocation RParenLoc) {
1532 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1533 NumComponents, RParenLoc);
1534 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001535
1536 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001537 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001538 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001541 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1542 SourceLocation OpLoc,
1543 UnaryExprOrTypeTrait ExprKind,
1544 SourceRange R) {
1545 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
1547
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001548 /// \brief Build a new sizeof, alignof or vec step expression with an
1549 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001553 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1554 UnaryExprOrTypeTrait ExprKind,
1555 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001556 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001557 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001561 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 }
Mike Stump1eb44332009-09-09 15:08:12 +00001563
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001565 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001570 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001572 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1573 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 RBracketLoc);
1575 }
1576
1577 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001583 SourceLocation RParenLoc,
1584 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001585 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001586 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 }
1588
1589 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001590 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001593 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001594 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001595 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001596 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001597 const DeclarationNameInfo &MemberNameInfo,
1598 ValueDecl *Member,
1599 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001600 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001601 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001602 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1603 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001604 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001605 // We have a reference to an unnamed field. This is always the
1606 // base of an anonymous struct/union member access, i.e. the
1607 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001608 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001609 assert(Member->getType()->isRecordType() &&
1610 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Richard Smith9138b4e2011-10-26 19:06:56 +00001612 BaseResult =
1613 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001614 QualifierLoc.getNestedNameSpecifier(),
1615 FoundDecl, Member);
1616 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001617 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001618 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001619 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001620 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001621 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001622 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001623 cast<FieldDecl>(Member)->getType(),
1624 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001625 return getSema().Owned(ME);
1626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001628 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001629 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001630
John Wiegley429bb272011-04-08 18:41:53 +00001631 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001632 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001633
John McCall6bb80172010-03-30 21:47:33 +00001634 // FIXME: this involves duplicating earlier analysis in a lot of
1635 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001636 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001637 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001638 R.resolveKind();
1639
John McCall9ae2f072010-08-23 23:25:46 +00001640 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001641 SS, TemplateKWLoc,
1642 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001643 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 }
Mike Stump1eb44332009-09-09 15:08:12 +00001645
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001647 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001650 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001651 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001652 Expr *LHS, Expr *RHS) {
1653 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 }
1655
1656 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001657 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001661 SourceLocation QuestionLoc,
1662 Expr *LHS,
1663 SourceLocation ColonLoc,
1664 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001665 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1666 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 }
1668
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001670 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001673 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001674 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001676 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001677 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001686 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001689 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 SourceLocation OpLoc,
1699 SourceLocation AccessorLoc,
1700 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001701
John McCall129e2df2009-11-30 22:42:35 +00001702 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001703 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001704 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001705 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001706 SS, SourceLocation(),
1707 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001708 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001709 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001717 MultiExprArg Inits,
1718 SourceLocation RBraceLoc,
1719 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001720 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001721 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001722 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001723 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001724
Douglas Gregore48319a2009-11-09 17:16:50 +00001725 // Patch in the result type we were given, which may have been computed
1726 // when the initial InitListExpr was built.
1727 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1728 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001729 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001733 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001736 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 MultiExprArg ArrayExprs,
1738 SourceLocation EqualOrColonLoc,
1739 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001740 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001741 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001743 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001746
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001747 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001751 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// By default, builds the implicit value initialization without performing
1753 /// any semantic analysis. Subclasses may override this routine to provide
1754 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001755 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1757 }
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001760 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001763 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001765 SourceLocation RParenLoc) {
1766 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001767 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001768 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 }
1770
1771 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001772 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001776 MultiExprArg SubExprs,
1777 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001778 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 }
Mike Stump1eb44332009-09-09 15:08:12 +00001780
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001782 ///
1783 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 /// rather than attempting to map the label statement itself.
1785 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001786 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001787 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001788 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 }
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001792 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001795 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001798 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new __builtin_choose_expr expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001806 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 SourceLocation RParenLoc) {
1808 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001809 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 RParenLoc);
1811 }
Mike Stump1eb44332009-09-09 15:08:12 +00001812
Peter Collingbournef111d932011-04-15 00:35:48 +00001813 /// \brief Build a new generic selection expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
1817 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1818 SourceLocation DefaultLoc,
1819 SourceLocation RParenLoc,
1820 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001821 ArrayRef<TypeSourceInfo *> Types,
1822 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001823 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001824 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001825 }
1826
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 /// \brief Build a new overloaded operator call expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// The semantic analysis provides the behavior of template instantiation,
1831 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001832 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 /// argument-dependent lookup, etc. Subclasses may override this routine to
1834 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001837 Expr *Callee,
1838 Expr *First,
1839 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001840
1841 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 /// reinterpret_cast.
1843 ///
1844 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001845 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 Stmt::StmtClass Class,
1849 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001850 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 SourceLocation RAngleLoc,
1852 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001853 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 SourceLocation RParenLoc) {
1855 switch (Class) {
1856 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001857 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001858 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001859 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860
1861 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001862 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001863 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001864 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001865
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001867 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001868 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001869 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001871
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001873 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001874 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001875 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001878 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 }
Mike Stump1eb44332009-09-09 15:08:12 +00001881
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 /// \brief Build a new C++ static_cast expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001888 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RAngleLoc,
1890 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001891 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001893 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001894 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001895 SourceRange(LAngleLoc, RAngleLoc),
1896 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
1898
1899 /// \brief Build a new C++ dynamic_cast expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001903 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001905 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 SourceLocation RAngleLoc,
1907 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001908 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001910 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001911 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001912 SourceRange(LAngleLoc, RAngleLoc),
1913 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 }
1915
1916 /// \brief Build a new C++ reinterpret_cast expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001920 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001922 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 SourceLocation RAngleLoc,
1924 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001925 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001927 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001928 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001929 SourceRange(LAngleLoc, RAngleLoc),
1930 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 }
1932
1933 /// \brief Build a new C++ const_cast expression.
1934 ///
1935 /// By default, performs semantic analysis to build the new expression.
1936 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001937 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001939 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 SourceLocation RAngleLoc,
1941 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001942 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001944 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001945 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001946 SourceRange(LAngleLoc, RAngleLoc),
1947 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 }
Mike Stump1eb44332009-09-09 15:08:12 +00001949
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 /// \brief Build a new C++ functional-style cast expression.
1951 ///
1952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001954 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1955 SourceLocation LParenLoc,
1956 Expr *Sub,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001959 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 RParenLoc);
1961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ typeid(type) expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001967 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001968 SourceLocation TypeidLoc,
1969 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001971 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001972 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Francois Pichet01b7c302010-09-08 12:20:18 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 /// \brief Build a new C++ typeid(expr) expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001980 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001981 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001982 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001984 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001985 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001986 }
1987
Francois Pichet01b7c302010-09-08 12:20:18 +00001988 /// \brief Build a new C++ __uuidof(type) expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1993 SourceLocation TypeidLoc,
1994 TypeSourceInfo *Operand,
1995 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001996 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001997 RParenLoc);
1998 }
1999
2000 /// \brief Build a new C++ __uuidof(expr) expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2005 SourceLocation TypeidLoc,
2006 Expr *Operand,
2007 SourceLocation RParenLoc) {
2008 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2009 RParenLoc);
2010 }
2011
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 /// \brief Build a new C++ "this" expression.
2013 ///
2014 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002015 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002017 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002018 QualType ThisType,
2019 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002020 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002022 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2023 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 }
2025
2026 /// \brief Build a new C++ throw expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002030 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2031 bool IsThrownVariableInScope) {
2032 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new C++ default-argument expression.
2036 ///
2037 /// By default, builds a new default-argument expression, which does not
2038 /// require any semantic analysis. Subclasses may override this routine to
2039 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002040 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002041 ParmVarDecl *Param) {
2042 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2043 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 }
2045
Richard Smithc3bf52c2013-04-20 22:23:05 +00002046 /// \brief Build a new C++11 default-initialization expression.
2047 ///
2048 /// By default, builds a new default field initialization expression, which
2049 /// does not require any semantic analysis. Subclasses may override this
2050 /// routine to provide different behavior.
2051 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2052 FieldDecl *Field) {
2053 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2054 Field));
2055 }
2056
Douglas Gregorb98b1992009-08-11 05:31:07 +00002057 /// \brief Build a new C++ zero-initialization expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002061 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2062 SourceLocation LParenLoc,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002065 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002066 }
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregorb98b1992009-08-11 05:31:07 +00002068 /// \brief Build a new C++ "new" expression.
2069 ///
2070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002072 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002073 bool UseGlobal,
2074 SourceLocation PlacementLParen,
2075 MultiExprArg PlacementArgs,
2076 SourceLocation PlacementRParen,
2077 SourceRange TypeIdParens,
2078 QualType AllocatedType,
2079 TypeSourceInfo *AllocatedTypeInfo,
2080 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002081 SourceRange DirectInitRange,
2082 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002083 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002085 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002087 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002088 AllocatedType,
2089 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002090 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002091 DirectInitRange,
2092 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 }
Mike Stump1eb44332009-09-09 15:08:12 +00002094
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 /// \brief Build a new C++ "delete" expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002099 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 bool IsGlobalDelete,
2101 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002102 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002103 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002104 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
Mike Stump1eb44332009-09-09 15:08:12 +00002106
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 /// \brief Build a new unary type trait expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002112 SourceLocation StartLoc,
2113 TypeSourceInfo *T,
2114 SourceLocation RParenLoc) {
2115 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002116 }
2117
Francois Pichet6ad6f282010-12-07 00:08:36 +00002118 /// \brief Build a new binary type trait expression.
2119 ///
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
2122 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2123 SourceLocation StartLoc,
2124 TypeSourceInfo *LhsT,
2125 TypeSourceInfo *RhsT,
2126 SourceLocation RParenLoc) {
2127 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2128 }
2129
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002130 /// \brief Build a new type trait expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
2134 ExprResult RebuildTypeTrait(TypeTrait Trait,
2135 SourceLocation StartLoc,
2136 ArrayRef<TypeSourceInfo *> Args,
2137 SourceLocation RParenLoc) {
2138 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2139 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002140
John Wiegley21ff2e52011-04-28 00:16:57 +00002141 /// \brief Build a new array type trait expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
2145 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2146 SourceLocation StartLoc,
2147 TypeSourceInfo *TSInfo,
2148 Expr *DimExpr,
2149 SourceLocation RParenLoc) {
2150 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2151 }
2152
John Wiegley55262202011-04-25 06:54:41 +00002153 /// \brief Build a new expression trait expression.
2154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
2157 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2158 SourceLocation StartLoc,
2159 Expr *Queried,
2160 SourceLocation RParenLoc) {
2161 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2162 }
2163
Mike Stump1eb44332009-09-09 15:08:12 +00002164 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 /// expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002169 ExprResult RebuildDependentScopeDeclRefExpr(
2170 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002171 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002172 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002173 const TemplateArgumentListInfo *TemplateArgs,
2174 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002176 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002177
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002178 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002179 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002180 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002181
Richard Smithefeeccf2012-10-21 03:28:35 +00002182 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2183 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 }
2185
2186 /// \brief Build a new template-id expression.
2187 ///
2188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002190 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
2192 LookupResult &R,
2193 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002194 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002195 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2196 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002197 }
2198
2199 /// \brief Build a new object-construction expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002203 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002204 SourceLocation Loc,
2205 CXXConstructorDecl *Constructor,
2206 bool IsElidable,
2207 MultiExprArg Args,
2208 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002209 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002210 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002211 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002212 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002213 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002214 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002215 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002216 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002217
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002218 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002219 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002220 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002221 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002222 RequiresZeroInit, ConstructKind,
2223 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002224 }
2225
2226 /// \brief Build a new object-construction expression.
2227 ///
2228 /// By default, performs semantic analysis to build the new expression.
2229 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002230 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2231 SourceLocation LParenLoc,
2232 MultiExprArg Args,
2233 SourceLocation RParenLoc) {
2234 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002235 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002236 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002237 RParenLoc);
2238 }
2239
2240 /// \brief Build a new object-construction expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002244 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2245 SourceLocation LParenLoc,
2246 MultiExprArg Args,
2247 SourceLocation RParenLoc) {
2248 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002249 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002250 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002251 RParenLoc);
2252 }
Mike Stump1eb44332009-09-09 15:08:12 +00002253
Douglas Gregorb98b1992009-08-11 05:31:07 +00002254 /// \brief Build a new member reference expression.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002258 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002259 QualType BaseType,
2260 bool IsArrow,
2261 SourceLocation OperatorLoc,
2262 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002263 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002264 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002265 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002266 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002268 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002269
John McCall9ae2f072010-08-23 23:25:46 +00002270 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002271 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002272 SS, TemplateKWLoc,
2273 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002274 MemberNameInfo,
2275 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276 }
2277
John McCall129e2df2009-11-30 22:42:35 +00002278 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002282 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2283 SourceLocation OperatorLoc,
2284 bool IsArrow,
2285 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002286 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002287 NamedDecl *FirstQualifierInScope,
2288 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002289 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002290 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002291 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002292
John McCall9ae2f072010-08-23 23:25:46 +00002293 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002294 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002295 SS, TemplateKWLoc,
2296 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002297 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002298 }
Mike Stump1eb44332009-09-09 15:08:12 +00002299
Sebastian Redl2e156222010-09-10 20:55:43 +00002300 /// \brief Build a new noexcept expression.
2301 ///
2302 /// By default, performs semantic analysis to build the new expression.
2303 /// Subclasses may override this routine to provide different behavior.
2304 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2305 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2306 }
2307
Douglas Gregoree8aff02011-01-04 17:33:58 +00002308 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002309 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2310 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002311 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002312 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002313 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002314 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2315 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002316 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002317
2318 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2319 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002320 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002321 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002322
Patrick Beardeb382ec2012-04-19 00:25:12 +00002323 /// \brief Build a new Objective-C boxed expression.
2324 ///
2325 /// By default, performs semantic analysis to build the new expression.
2326 /// Subclasses may override this routine to provide different behavior.
2327 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2328 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2329 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002331 /// \brief Build a new Objective-C array literal.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2336 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002337 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002338 MultiExprArg(Elements, NumElements));
2339 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002340
2341 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002342 Expr *Base, Expr *Key,
2343 ObjCMethodDecl *getterMethod,
2344 ObjCMethodDecl *setterMethod) {
2345 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2346 getterMethod, setterMethod);
2347 }
2348
2349 /// \brief Build a new Objective-C dictionary literal.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2354 ObjCDictionaryElement *Elements,
2355 unsigned NumElements) {
2356 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002358
James Dennett699c9042012-06-15 07:13:21 +00002359 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002360 ///
2361 /// By default, performs semantic analysis to build the new expression.
2362 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002363 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002364 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002365 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002366 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002367 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002368 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002369
Douglas Gregor92e986e2010-04-22 16:44:27 +00002370 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002371 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002372 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002373 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002374 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002375 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002376 MultiExprArg Args,
2377 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002378 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2379 ReceiverTypeInfo->getType(),
2380 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002381 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002382 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002383 }
2384
2385 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002386 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002387 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002388 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002389 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002390 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002391 MultiExprArg Args,
2392 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002393 return SemaRef.BuildInstanceMessage(Receiver,
2394 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002395 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002396 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002397 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002398 }
2399
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002400 /// \brief Build a new Objective-C ivar reference expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002404 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002405 SourceLocation IvarLoc,
2406 bool IsArrow, bool IsFreeIvar) {
2407 // FIXME: We lose track of the IsFreeIvar bit.
2408 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002409 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002410 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2411 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002412 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002413 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002414 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002415 false);
John Wiegley429bb272011-04-08 18:41:53 +00002416 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002417 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002418
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002419 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002420 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002421
John Wiegley429bb272011-04-08 18:41:53 +00002422 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002423 /*FIXME:*/IvarLoc, IsArrow,
2424 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002426 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002427 /*TemplateArgs=*/0);
2428 }
Douglas Gregore3303542010-04-26 20:47:02 +00002429
2430 /// \brief Build a new Objective-C property reference expression.
2431 ///
2432 /// By default, performs semantic analysis to build the new expression.
2433 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002434 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002435 ObjCPropertyDecl *Property,
2436 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002437 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002438 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002439 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2440 Sema::LookupMemberName);
2441 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002442 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002443 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002444 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002445 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002446 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002447
Douglas Gregore3303542010-04-26 20:47:02 +00002448 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002449 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
John Wiegley429bb272011-04-08 18:41:53 +00002451 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002453 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002454 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002456 /*TemplateArgs=*/0);
2457 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002458
John McCall12f78a62010-12-02 01:19:52 +00002459 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002460 ///
2461 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002462 /// Subclasses may override this routine to provide different behavior.
2463 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2464 ObjCMethodDecl *Getter,
2465 ObjCMethodDecl *Setter,
2466 SourceLocation PropertyLoc) {
2467 // Since these expressions can only be value-dependent, we do not
2468 // need to perform semantic analysis again.
2469 return Owned(
2470 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2471 VK_LValue, OK_ObjCProperty,
2472 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002473 }
2474
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002475 /// \brief Build a new Objective-C "isa" expression.
2476 ///
2477 /// By default, performs semantic analysis to build the new expression.
2478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002479 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002480 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002481 bool IsArrow) {
2482 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002483 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002484 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2485 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002486 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002487 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002488 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002489 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002490 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002491
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002492 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002493 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002494
John Wiegley429bb272011-04-08 18:41:53 +00002495 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002496 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002497 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002498 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002500 /*TemplateArgs=*/0);
2501 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002502
Douglas Gregorb98b1992009-08-11 05:31:07 +00002503 /// \brief Build a new shuffle vector expression.
2504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002507 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002508 MultiExprArg SubExprs,
2509 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002510 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002511 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002512 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2513 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2514 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002515 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002516
Douglas Gregorb98b1992009-08-11 05:31:07 +00002517 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002518 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002519 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2520 SemaRef.Context.BuiltinFnTy,
2521 VK_RValue, BuiltinLoc);
2522 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2523 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2524 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002525
2526 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002527 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002528 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002529 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002530 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002531 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002532
Douglas Gregorb98b1992009-08-11 05:31:07 +00002533 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002534 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002535 }
John McCall43fed0d2010-11-12 08:19:04 +00002536
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002537 /// \brief Build a new template argument pack expansion.
2538 ///
2539 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002540 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002541 /// different behavior.
2542 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002543 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002544 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002545 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002546 case TemplateArgument::Expression: {
2547 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002548 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2549 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002550 if (Result.isInvalid())
2551 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002552
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002553 return TemplateArgumentLoc(Result.get(), Result.get());
2554 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002555
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002556 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002557 return TemplateArgumentLoc(TemplateArgument(
2558 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002559 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002560 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002561 Pattern.getTemplateNameLoc(),
2562 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002563
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002564 case TemplateArgument::Null:
2565 case TemplateArgument::Integral:
2566 case TemplateArgument::Declaration:
2567 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002568 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002569 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002570 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002571
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002572 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002573 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002574 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002575 EllipsisLoc,
2576 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002577 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2578 Expansion);
2579 break;
2580 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002581
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002582 return TemplateArgumentLoc();
2583 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002584
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002585 /// \brief Build a new expression pack expansion.
2586 ///
2587 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002590 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002591 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002592 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002593 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002594
2595 /// \brief Build a new atomic operation expression.
2596 ///
2597 /// By default, performs semantic analysis to build the new expression.
2598 /// Subclasses may override this routine to provide different behavior.
2599 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2600 MultiExprArg SubExprs,
2601 QualType RetTy,
2602 AtomicExpr::AtomicOp Op,
2603 SourceLocation RParenLoc) {
2604 // Just create the expression; there is not any interesting semantic
2605 // analysis here because we can't actually build an AtomicExpr until
2606 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002607 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002608 RParenLoc);
2609 }
2610
John McCall43fed0d2010-11-12 08:19:04 +00002611private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002612 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2613 QualType ObjectType,
2614 NamedDecl *FirstQualifierInScope,
2615 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002616
2617 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2618 QualType ObjectType,
2619 NamedDecl *FirstQualifierInScope,
2620 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002621};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002622
Douglas Gregor43959a92009-08-20 07:17:43 +00002623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002624StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002625 if (!S)
2626 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002627
Douglas Gregor43959a92009-08-20 07:17:43 +00002628 switch (S->getStmtClass()) {
2629 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002630
Douglas Gregor43959a92009-08-20 07:17:43 +00002631 // Transform individual statement nodes
2632#define STMT(Node, Parent) \
2633 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002634#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002635#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002636#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002637
Douglas Gregor43959a92009-08-20 07:17:43 +00002638 // Transform expressions by calling TransformExpr.
2639#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002640#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002641#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002642#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002643 {
John McCall60d7b3a2010-08-24 06:29:42 +00002644 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002645 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002646 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002647
Richard Smith41956372013-01-14 22:39:08 +00002648 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002649 }
Mike Stump1eb44332009-09-09 15:08:12 +00002650 }
2651
John McCall3fa5cae2010-10-26 07:05:15 +00002652 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002653}
Mike Stump1eb44332009-09-09 15:08:12 +00002654
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002655template<typename Derived>
2656OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2657 if (!S)
2658 return S;
2659
2660 switch (S->getClauseKind()) {
2661 default: break;
2662 // Transform individual clause nodes
2663#define OPENMP_CLAUSE(Name, Class) \
2664 case OMPC_ ## Name : \
2665 return getDerived().Transform ## Class(cast<Class>(S));
2666#include "clang/Basic/OpenMPKinds.def"
2667 }
2668
2669 return S;
2670}
2671
Mike Stump1eb44332009-09-09 15:08:12 +00002672
Douglas Gregor670444e2009-08-04 22:27:00 +00002673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002674ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002675 if (!E)
2676 return SemaRef.Owned(E);
2677
2678 switch (E->getStmtClass()) {
2679 case Stmt::NoStmtClass: break;
2680#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002681#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002682#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002683 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002684#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002685 }
2686
John McCall3fa5cae2010-10-26 07:05:15 +00002687 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002688}
2689
2690template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002691ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2692 bool CXXDirectInit) {
2693 // Initializers are instantiated like expressions, except that various outer
2694 // layers are stripped.
2695 if (!Init)
2696 return SemaRef.Owned(Init);
2697
2698 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2699 Init = ExprTemp->getSubExpr();
2700
Richard Smith858c2c32013-05-30 22:40:16 +00002701 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2702 Init = MTE->GetTemporaryExpr();
2703
Richard Smithc83c2302012-12-19 01:39:02 +00002704 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2705 Init = Binder->getSubExpr();
2706
2707 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2708 Init = ICE->getSubExprAsWritten();
2709
Richard Smith7c3e6152013-06-12 22:31:48 +00002710 if (CXXStdInitializerListExpr *ILE =
2711 dyn_cast<CXXStdInitializerListExpr>(Init))
2712 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2713
Richard Smith5cf15892012-12-21 08:13:35 +00002714 // If this is not a direct-initializer, we only need to reconstruct
2715 // InitListExprs. Other forms of copy-initialization will be a no-op if
2716 // the initializer is already the right type.
2717 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2718 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2719 return getDerived().TransformExpr(Init);
2720
2721 // Revert value-initialization back to empty parens.
2722 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2723 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002724 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002725 Parens.getEnd());
2726 }
2727
2728 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2729 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002730 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002731 SourceLocation());
2732
2733 // Revert initialization by constructor back to a parenthesized or braced list
2734 // of expressions. Any other form of initializer can just be reused directly.
2735 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002736 return getDerived().TransformExpr(Init);
2737
2738 SmallVector<Expr*, 8> NewArgs;
2739 bool ArgChanged = false;
2740 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2741 /*IsCall*/true, NewArgs, &ArgChanged))
2742 return ExprError();
2743
2744 // If this was list initialization, revert to list form.
2745 if (Construct->isListInitialization())
2746 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2747 Construct->getLocEnd(),
2748 Construct->getType());
2749
Richard Smithc83c2302012-12-19 01:39:02 +00002750 // Build a ParenListExpr to represent anything else.
2751 SourceRange Parens = Construct->getParenRange();
2752 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2753 Parens.getEnd());
2754}
2755
2756template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2758 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002759 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002760 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002761 bool *ArgChanged) {
2762 for (unsigned I = 0; I != NumInputs; ++I) {
2763 // If requested, drop call arguments that need to be dropped.
2764 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2765 if (ArgChanged)
2766 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregoraa165f82011-01-03 19:04:46 +00002768 break;
2769 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002771 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2772 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
Chris Lattner686775d2011-07-20 06:58:45 +00002774 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002775 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2776 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002778 // Determine whether the set of unexpanded parameter packs can and should
2779 // be expanded.
2780 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002781 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002782 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2783 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002784 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2785 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002786 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002787 Expand, RetainExpansion,
2788 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002789 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002791 if (!Expand) {
2792 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002794 // expansion.
2795 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2796 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2797 if (OutPattern.isInvalid())
2798 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002799
2800 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002801 Expansion->getEllipsisLoc(),
2802 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002803 if (Out.isInvalid())
2804 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002806 if (ArgChanged)
2807 *ArgChanged = true;
2808 Outputs.push_back(Out.get());
2809 continue;
2810 }
John McCallc8fc90a2011-07-06 07:30:07 +00002811
2812 // Record right away that the argument was changed. This needs
2813 // to happen even if the array expands to nothing.
2814 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002815
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002816 // The transform has determined that we should perform an elementwise
2817 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002818 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002819 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2820 ExprResult Out = getDerived().TransformExpr(Pattern);
2821 if (Out.isInvalid())
2822 return true;
2823
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002824 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002825 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2826 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002827 if (Out.isInvalid())
2828 return true;
2829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002831 Outputs.push_back(Out.get());
2832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002834 continue;
2835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
Richard Smithc83c2302012-12-19 01:39:02 +00002837 ExprResult Result =
2838 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2839 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002840 if (Result.isInvalid())
2841 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842
Douglas Gregoraa165f82011-01-03 19:04:46 +00002843 if (Result.get() != Inputs[I] && ArgChanged)
2844 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
2846 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002847 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
Douglas Gregoraa165f82011-01-03 19:04:46 +00002849 return false;
2850}
2851
2852template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002853NestedNameSpecifierLoc
2854TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2855 NestedNameSpecifierLoc NNS,
2856 QualType ObjectType,
2857 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002858 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002860 Qualifier = Qualifier.getPrefix())
2861 Qualifiers.push_back(Qualifier);
2862
2863 CXXScopeSpec SS;
2864 while (!Qualifiers.empty()) {
2865 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2866 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002868 switch (QNNS->getKind()) {
2869 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002871 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002873 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002875 FirstQualifierInScope, false))
2876 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002878 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002880 case NestedNameSpecifier::Namespace: {
2881 NamespaceDecl *NS
2882 = cast_or_null<NamespaceDecl>(
2883 getDerived().TransformDecl(
2884 Q.getLocalBeginLoc(),
2885 QNNS->getAsNamespace()));
2886 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2887 break;
2888 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002889
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002890 case NestedNameSpecifier::NamespaceAlias: {
2891 NamespaceAliasDecl *Alias
2892 = cast_or_null<NamespaceAliasDecl>(
2893 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2894 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002896 Q.getLocalEndLoc());
2897 break;
2898 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002900 case NestedNameSpecifier::Global:
2901 // There is no meaningful transformation that one could perform on the
2902 // global scope.
2903 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2904 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002906 case NestedNameSpecifier::TypeSpecWithTemplate:
2907 case NestedNameSpecifier::TypeSpec: {
2908 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2909 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002911 if (!TL)
2912 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002913
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002914 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002915 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002916 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002919 if (TL.getType()->isEnumeralType())
2920 SemaRef.Diag(TL.getBeginLoc(),
2921 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002922 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2923 Q.getLocalEndLoc());
2924 break;
2925 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002926 // If the nested-name-specifier is an invalid type def, don't emit an
2927 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002928 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2929 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002930 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002931 << TL.getType() << SS.getRange();
2932 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002933 return NestedNameSpecifierLoc();
2934 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002935 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002937 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002938 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002939 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 !getDerived().AlwaysRebuild())
2945 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946
2947 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002948 // nested-name-specifier, do so.
2949 if (SS.location_size() == NNS.getDataLength() &&
2950 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2951 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2952
2953 // Allocate new nested-name-specifier location information.
2954 return SS.getWithLocInContext(SemaRef.Context);
2955}
2956
2957template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002958DeclarationNameInfo
2959TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002960::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002961 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002962 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002963 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002964
2965 switch (Name.getNameKind()) {
2966 case DeclarationName::Identifier:
2967 case DeclarationName::ObjCZeroArgSelector:
2968 case DeclarationName::ObjCOneArgSelector:
2969 case DeclarationName::ObjCMultiArgSelector:
2970 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002971 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002972 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002973 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002974
Douglas Gregor81499bb2009-09-03 22:13:48 +00002975 case DeclarationName::CXXConstructorName:
2976 case DeclarationName::CXXDestructorName:
2977 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002978 TypeSourceInfo *NewTInfo;
2979 CanQualType NewCanTy;
2980 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002981 NewTInfo = getDerived().TransformType(OldTInfo);
2982 if (!NewTInfo)
2983 return DeclarationNameInfo();
2984 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002985 }
2986 else {
2987 NewTInfo = 0;
2988 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002989 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002990 if (NewT.isNull())
2991 return DeclarationNameInfo();
2992 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2993 }
Mike Stump1eb44332009-09-09 15:08:12 +00002994
Abramo Bagnara25777432010-08-11 22:01:17 +00002995 DeclarationName NewName
2996 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2997 NewCanTy);
2998 DeclarationNameInfo NewNameInfo(NameInfo);
2999 NewNameInfo.setName(NewName);
3000 NewNameInfo.setNamedTypeInfo(NewTInfo);
3001 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003002 }
Mike Stump1eb44332009-09-09 15:08:12 +00003003 }
3004
David Blaikieb219cfc2011-09-23 05:06:16 +00003005 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003006}
3007
3008template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003009TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003010TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3011 TemplateName Name,
3012 SourceLocation NameLoc,
3013 QualType ObjectType,
3014 NamedDecl *FirstQualifierInScope) {
3015 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3016 TemplateDecl *Template = QTN->getTemplateDecl();
3017 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003018
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003019 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003020 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003021 Template));
3022 if (!TransTemplate)
3023 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003024
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003025 if (!getDerived().AlwaysRebuild() &&
3026 SS.getScopeRep() == QTN->getQualifier() &&
3027 TransTemplate == Template)
3028 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003029
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003030 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3031 TransTemplate);
3032 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003033
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003034 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3035 if (SS.getScopeRep()) {
3036 // These apply to the scope specifier, not the template.
3037 ObjectType = QualType();
3038 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003039 }
3040
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003041 if (!getDerived().AlwaysRebuild() &&
3042 SS.getScopeRep() == DTN->getQualifier() &&
3043 ObjectType.isNull())
3044 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003045
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003046 if (DTN->isIdentifier()) {
3047 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003048 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003049 NameLoc,
3050 ObjectType,
3051 FirstQualifierInScope);
3052 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003054 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3055 ObjectType);
3056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3059 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003060 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003061 Template));
3062 if (!TransTemplate)
3063 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003064
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003065 if (!getDerived().AlwaysRebuild() &&
3066 TransTemplate == Template)
3067 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003068
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 return TemplateName(TransTemplate);
3070 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003071
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003072 if (SubstTemplateTemplateParmPackStorage *SubstPack
3073 = Name.getAsSubstTemplateTemplateParmPack()) {
3074 TemplateTemplateParmDecl *TransParam
3075 = cast_or_null<TemplateTemplateParmDecl>(
3076 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3077 if (!TransParam)
3078 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003079
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003080 if (!getDerived().AlwaysRebuild() &&
3081 TransParam == SubstPack->getParameterPack())
3082 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003083
3084 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003085 SubstPack->getArgumentPack());
3086 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003087
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003088 // These should be getting filtered out before they reach the AST.
3089 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003090}
3091
3092template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003093void TreeTransform<Derived>::InventTemplateArgumentLoc(
3094 const TemplateArgument &Arg,
3095 TemplateArgumentLoc &Output) {
3096 SourceLocation Loc = getDerived().getBaseLocation();
3097 switch (Arg.getKind()) {
3098 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003099 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003100 break;
3101
3102 case TemplateArgument::Type:
3103 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003104 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
John McCall833ca992009-10-29 08:12:44 +00003106 break;
3107
Douglas Gregor788cd062009-11-11 01:00:40 +00003108 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003109 case TemplateArgument::TemplateExpansion: {
3110 NestedNameSpecifierLocBuilder Builder;
3111 TemplateName Template = Arg.getAsTemplate();
3112 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3113 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3114 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3115 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003117 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003119 Builder.getWithLocInContext(SemaRef.Context),
3120 Loc);
3121 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003122 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003123 Builder.getWithLocInContext(SemaRef.Context),
3124 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Douglas Gregor788cd062009-11-11 01:00:40 +00003126 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003127 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003128
John McCall833ca992009-10-29 08:12:44 +00003129 case TemplateArgument::Expression:
3130 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3131 break;
3132
3133 case TemplateArgument::Declaration:
3134 case TemplateArgument::Integral:
3135 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003136 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003137 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003138 break;
3139 }
3140}
3141
3142template<typename Derived>
3143bool TreeTransform<Derived>::TransformTemplateArgument(
3144 const TemplateArgumentLoc &Input,
3145 TemplateArgumentLoc &Output) {
3146 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003147 switch (Arg.getKind()) {
3148 case TemplateArgument::Null:
3149 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003150 case TemplateArgument::Pack:
3151 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003152 case TemplateArgument::NullPtr:
3153 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003154
Douglas Gregor670444e2009-08-04 22:27:00 +00003155 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003156 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003157 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003158 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003159
3160 DI = getDerived().TransformType(DI);
3161 if (!DI) return true;
3162
3163 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3164 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003165 }
Mike Stump1eb44332009-09-09 15:08:12 +00003166
Douglas Gregor788cd062009-11-11 01:00:40 +00003167 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003168 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3169 if (QualifierLoc) {
3170 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3171 if (!QualifierLoc)
3172 return true;
3173 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003174
Douglas Gregor1d752d72011-03-02 18:46:51 +00003175 CXXScopeSpec SS;
3176 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003177 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003178 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3179 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003180 if (Template.isNull())
3181 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003183 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003184 Input.getTemplateNameLoc());
3185 return false;
3186 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003187
3188 case TemplateArgument::TemplateExpansion:
3189 llvm_unreachable("Caller should expand pack expansions");
3190
Douglas Gregor670444e2009-08-04 22:27:00 +00003191 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003192 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003193 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003194 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003195
John McCall833ca992009-10-29 08:12:44 +00003196 Expr *InputExpr = Input.getSourceExpression();
3197 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3198
Chris Lattner223de242011-04-25 20:37:58 +00003199 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003200 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003201 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003202 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003203 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003204 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003205 }
Mike Stump1eb44332009-09-09 15:08:12 +00003206
Douglas Gregor670444e2009-08-04 22:27:00 +00003207 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003208 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003209}
3210
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003211/// \brief Iterator adaptor that invents template argument location information
3212/// for each of the template arguments in its underlying iterator.
3213template<typename Derived, typename InputIterator>
3214class TemplateArgumentLocInventIterator {
3215 TreeTransform<Derived> &Self;
3216 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003218public:
3219 typedef TemplateArgumentLoc value_type;
3220 typedef TemplateArgumentLoc reference;
3221 typedef typename std::iterator_traits<InputIterator>::difference_type
3222 difference_type;
3223 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003225 class pointer {
3226 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003227
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003228 public:
3229 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003230
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003231 const TemplateArgumentLoc *operator->() const { return &Arg; }
3232 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003234 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003236 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3237 InputIterator Iter)
3238 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003240 TemplateArgumentLocInventIterator &operator++() {
3241 ++Iter;
3242 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003243 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003245 TemplateArgumentLocInventIterator operator++(int) {
3246 TemplateArgumentLocInventIterator Old(*this);
3247 ++(*this);
3248 return Old;
3249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003251 reference operator*() const {
3252 TemplateArgumentLoc Result;
3253 Self.InventTemplateArgumentLoc(*Iter, Result);
3254 return Result;
3255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003257 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003259 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3260 const TemplateArgumentLocInventIterator &Y) {
3261 return X.Iter == Y.Iter;
3262 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003263
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003264 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3265 const TemplateArgumentLocInventIterator &Y) {
3266 return X.Iter != Y.Iter;
3267 }
3268};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003270template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003271template<typename InputIterator>
3272bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3273 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003274 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003275 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003276 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003277 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003279 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3280 // Unpack argument packs, which we translate them into separate
3281 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003282 // FIXME: We could do much better if we could guarantee that the
3283 // TemplateArgumentLocInfo for the pack expansion would be usable for
3284 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003285 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003286 TemplateArgument::pack_iterator>
3287 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003289 In.getArgument().pack_begin()),
3290 PackLocIterator(*this,
3291 In.getArgument().pack_end()),
3292 Outputs))
3293 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003295 continue;
3296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003298 if (In.getArgument().isPackExpansion()) {
3299 // We have a pack expansion, for which we will be substituting into
3300 // the pattern.
3301 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003302 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003303 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003304 = getSema().getTemplateArgumentPackExpansionPattern(
3305 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Chris Lattner686775d2011-07-20 06:58:45 +00003307 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003308 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3309 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003310
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003311 // Determine whether the set of unexpanded parameter packs can and should
3312 // be expanded.
3313 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003314 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003315 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003316 if (getDerived().TryExpandParameterPacks(Ellipsis,
3317 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003318 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003319 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003320 RetainExpansion,
3321 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003322 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003323
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003324 if (!Expand) {
3325 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003326 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003327 // expansion.
3328 TemplateArgumentLoc OutPattern;
3329 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3330 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3331 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003332
Douglas Gregorcded4f62011-01-14 17:04:44 +00003333 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3334 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003335 if (Out.getArgument().isNull())
3336 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003337
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003338 Outputs.addArgument(Out);
3339 continue;
3340 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003341
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003342 // The transform has determined that we should perform an elementwise
3343 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003344 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003345 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3346
3347 if (getDerived().TransformTemplateArgument(Pattern, Out))
3348 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003350 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003351 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3352 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003353 if (Out.getArgument().isNull())
3354 return true;
3355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003356
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003357 Outputs.addArgument(Out);
3358 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003359
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003360 // If we're supposed to retain a pack expansion, do so by temporarily
3361 // forgetting the partially-substituted parameter pack.
3362 if (RetainExpansion) {
3363 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003364
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003365 if (getDerived().TransformTemplateArgument(Pattern, Out))
3366 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003367
Douglas Gregorcded4f62011-01-14 17:04:44 +00003368 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3369 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003370 if (Out.getArgument().isNull())
3371 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003372
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003373 Outputs.addArgument(Out);
3374 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003375
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003376 continue;
3377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378
3379 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003380 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003381 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003382
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003383 Outputs.addArgument(Out);
3384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003385
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003386 return false;
3387
3388}
3389
Douglas Gregor577f75a2009-08-04 16:50:30 +00003390//===----------------------------------------------------------------------===//
3391// Type transformation
3392//===----------------------------------------------------------------------===//
3393
3394template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003395QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003396 if (getDerived().AlreadyTransformed(T))
3397 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003398
John McCalla2becad2009-10-21 00:40:46 +00003399 // Temporary workaround. All of these transformations should
3400 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003401 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3402 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
John McCall43fed0d2010-11-12 08:19:04 +00003404 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003405
John McCalla2becad2009-10-21 00:40:46 +00003406 if (!NewDI)
3407 return QualType();
3408
3409 return NewDI->getType();
3410}
3411
3412template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003413TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003414 // Refine the base location to the type's location.
3415 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3416 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003417 if (getDerived().AlreadyTransformed(DI->getType()))
3418 return DI;
3419
3420 TypeLocBuilder TLB;
3421
3422 TypeLoc TL = DI->getTypeLoc();
3423 TLB.reserve(TL.getFullDataSize());
3424
John McCall43fed0d2010-11-12 08:19:04 +00003425 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003426 if (Result.isNull())
3427 return 0;
3428
John McCalla93c9342009-12-07 02:54:59 +00003429 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003430}
3431
3432template<typename Derived>
3433QualType
John McCall43fed0d2010-11-12 08:19:04 +00003434TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003435 switch (T.getTypeLocClass()) {
3436#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003437#define TYPELOC(CLASS, PARENT) \
3438 case TypeLoc::CLASS: \
3439 return getDerived().Transform##CLASS##Type(TLB, \
3440 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003441#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003442 }
Mike Stump1eb44332009-09-09 15:08:12 +00003443
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003444 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003445}
3446
3447/// FIXME: By default, this routine adds type qualifiers only to types
3448/// that can have qualifiers, and silently suppresses those qualifiers
3449/// that are not permitted (e.g., qualifiers on reference or function
3450/// types). This is the right thing for template instantiation, but
3451/// probably not for other clients.
3452template<typename Derived>
3453QualType
3454TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003455 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003456 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003457
John McCall43fed0d2010-11-12 08:19:04 +00003458 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003459 if (Result.isNull())
3460 return QualType();
3461
3462 // Silently suppress qualifiers if the result type can't be qualified.
3463 // FIXME: this is the right thing for template instantiation, but
3464 // probably not for other clients.
3465 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003466 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003467
John McCallf85e1932011-06-15 23:02:42 +00003468 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003469 // resulting type.
3470 if (Quals.hasObjCLifetime()) {
3471 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3472 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003473 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003475 // A lifetime qualifier applied to a substituted template parameter
3476 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003477 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003479 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3480 QualType Replacement = SubstTypeParam->getReplacementType();
3481 Qualifiers Qs = Replacement.getQualifiers();
3482 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003483 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003484 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3485 Qs);
3486 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003488 Replacement);
3489 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003490 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3491 // 'auto' types behave the same way as template parameters.
3492 QualType Deduced = AutoTy->getDeducedType();
3493 Qualifiers Qs = Deduced.getQualifiers();
3494 Qs.removeObjCLifetime();
3495 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3496 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003497 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003498 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003499 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003500 // Otherwise, complain about the addition of a qualifier to an
3501 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003502 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003503 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003504 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003505
Douglas Gregore559ca12011-06-17 22:11:49 +00003506 Quals.removeObjCLifetime();
3507 }
3508 }
3509 }
John McCall28654742010-06-05 06:41:15 +00003510 if (!Quals.empty()) {
3511 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003512 // BuildQualifiedType might not add qualifiers if they are invalid.
3513 if (Result.hasLocalQualifiers())
3514 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003515 // No location information to preserve.
3516 }
John McCalla2becad2009-10-21 00:40:46 +00003517
3518 return Result;
3519}
3520
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003521template<typename Derived>
3522TypeLoc
3523TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3524 QualType ObjectType,
3525 NamedDecl *UnqualLookup,
3526 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003527 QualType T = TL.getType();
3528 if (getDerived().AlreadyTransformed(T))
3529 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003530
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003531 TypeLocBuilder TLB;
3532 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003533
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003534 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003535 TemplateSpecializationTypeLoc SpecTL =
3536 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003538 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003539 getDerived().TransformTemplateName(SS,
3540 SpecTL.getTypePtr()->getTemplateName(),
3541 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003542 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003543 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003544 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003545
3546 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003547 Template);
3548 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003549 DependentTemplateSpecializationTypeLoc SpecTL =
3550 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003551
Douglas Gregora88f09f2011-02-28 17:23:35 +00003552 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553 = getDerived().RebuildTemplateName(SS,
3554 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003555 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003556 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003557 if (Template.isNull())
3558 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
3560 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003561 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003562 Template,
3563 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003564 } else {
3565 // Nothing special needs to be done for these.
3566 Result = getDerived().TransformType(TLB, TL);
3567 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003568
3569 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003570 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003572 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3573}
3574
Douglas Gregorb71d8212011-03-02 18:32:08 +00003575template<typename Derived>
3576TypeSourceInfo *
3577TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3578 QualType ObjectType,
3579 NamedDecl *UnqualLookup,
3580 CXXScopeSpec &SS) {
3581 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003582
Douglas Gregorb71d8212011-03-02 18:32:08 +00003583 QualType T = TSInfo->getType();
3584 if (getDerived().AlreadyTransformed(T))
3585 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003586
Douglas Gregorb71d8212011-03-02 18:32:08 +00003587 TypeLocBuilder TLB;
3588 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003589
Douglas Gregorb71d8212011-03-02 18:32:08 +00003590 TypeLoc TL = TSInfo->getTypeLoc();
3591 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003592 TemplateSpecializationTypeLoc SpecTL =
3593 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003594
Douglas Gregorb71d8212011-03-02 18:32:08 +00003595 TemplateName Template
3596 = getDerived().TransformTemplateName(SS,
3597 SpecTL.getTypePtr()->getTemplateName(),
3598 SpecTL.getTemplateNameLoc(),
3599 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003600 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003601 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003602
3603 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003604 Template);
3605 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003606 DependentTemplateSpecializationTypeLoc SpecTL =
3607 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003608
Douglas Gregorb71d8212011-03-02 18:32:08 +00003609 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003610 = getDerived().RebuildTemplateName(SS,
3611 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003612 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003613 ObjectType, UnqualLookup);
3614 if (Template.isNull())
3615 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003616
3617 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003618 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003619 Template,
3620 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003621 } else {
3622 // Nothing special needs to be done for these.
3623 Result = getDerived().TransformType(TLB, TL);
3624 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003625
3626 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003627 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003628
Douglas Gregorb71d8212011-03-02 18:32:08 +00003629 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3630}
3631
John McCalla2becad2009-10-21 00:40:46 +00003632template <class TyLoc> static inline
3633QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3634 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3635 NewT.setNameLoc(T.getNameLoc());
3636 return T.getType();
3637}
3638
John McCalla2becad2009-10-21 00:40:46 +00003639template<typename Derived>
3640QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003641 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003642 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3643 NewT.setBuiltinLoc(T.getBuiltinLoc());
3644 if (T.needsExtraLocalData())
3645 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3646 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003647}
Mike Stump1eb44332009-09-09 15:08:12 +00003648
Douglas Gregor577f75a2009-08-04 16:50:30 +00003649template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003650QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003651 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003652 // FIXME: recurse?
3653 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654}
Mike Stump1eb44332009-09-09 15:08:12 +00003655
Douglas Gregor577f75a2009-08-04 16:50:30 +00003656template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003657QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3658 DecayedTypeLoc TL) {
3659 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3660 if (OriginalType.isNull())
3661 return QualType();
3662
3663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
3665 OriginalType != TL.getOriginalLoc().getType())
3666 Result = SemaRef.Context.getDecayedType(OriginalType);
3667 TLB.push<DecayedTypeLoc>(Result);
3668 // Nothing to set for DecayedTypeLoc.
3669 return Result;
3670}
3671
3672template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003673QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003674 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003675 QualType PointeeType
3676 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003677 if (PointeeType.isNull())
3678 return QualType();
3679
3680 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003681 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003682 // A dependent pointer type 'T *' has is being transformed such
3683 // that an Objective-C class type is being replaced for 'T'. The
3684 // resulting pointer type is an ObjCObjectPointerType, not a
3685 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003686 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003687
John McCallc12c5bb2010-05-15 11:32:37 +00003688 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3689 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003690 return Result;
3691 }
John McCall43fed0d2010-11-12 08:19:04 +00003692
Douglas Gregor92e986e2010-04-22 16:44:27 +00003693 if (getDerived().AlwaysRebuild() ||
3694 PointeeType != TL.getPointeeLoc().getType()) {
3695 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3696 if (Result.isNull())
3697 return QualType();
3698 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003699
John McCallf85e1932011-06-15 23:02:42 +00003700 // Objective-C ARC can add lifetime qualifiers to the type that we're
3701 // pointing to.
3702 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003703
Douglas Gregor92e986e2010-04-22 16:44:27 +00003704 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3705 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003706 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707}
Mike Stump1eb44332009-09-09 15:08:12 +00003708
3709template<typename Derived>
3710QualType
John McCalla2becad2009-10-21 00:40:46 +00003711TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003713 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003714 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3715 if (PointeeType.isNull())
3716 return QualType();
3717
3718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 PointeeType != TL.getPointeeLoc().getType()) {
3721 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003722 TL.getSigilLoc());
3723 if (Result.isNull())
3724 return QualType();
3725 }
3726
Douglas Gregor39968ad2010-04-22 16:50:51 +00003727 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003728 NewT.setSigilLoc(TL.getSigilLoc());
3729 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730}
3731
John McCall85737a72009-10-30 00:06:24 +00003732/// Transforms a reference type. Note that somewhat paradoxically we
3733/// don't care whether the type itself is an l-value type or an r-value
3734/// type; we only care if the type was *written* as an l-value type
3735/// or an r-value type.
3736template<typename Derived>
3737QualType
3738TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003739 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003740 const ReferenceType *T = TL.getTypePtr();
3741
3742 // Note that this works with the pointee-as-written.
3743 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3744 if (PointeeType.isNull())
3745 return QualType();
3746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 PointeeType != T->getPointeeTypeAsWritten()) {
3750 Result = getDerived().RebuildReferenceType(PointeeType,
3751 T->isSpelledAsLValue(),
3752 TL.getSigilLoc());
3753 if (Result.isNull())
3754 return QualType();
3755 }
3756
John McCallf85e1932011-06-15 23:02:42 +00003757 // Objective-C ARC can add lifetime qualifiers to the type that we're
3758 // referring to.
3759 TLB.TypeWasModifiedSafely(
3760 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3761
John McCall85737a72009-10-30 00:06:24 +00003762 // r-value references can be rebuilt as l-value references.
3763 ReferenceTypeLoc NewTL;
3764 if (isa<LValueReferenceType>(Result))
3765 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3766 else
3767 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3768 NewTL.setSigilLoc(TL.getSigilLoc());
3769
3770 return Result;
3771}
3772
Mike Stump1eb44332009-09-09 15:08:12 +00003773template<typename Derived>
3774QualType
John McCalla2becad2009-10-21 00:40:46 +00003775TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003776 LValueReferenceTypeLoc TL) {
3777 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003778}
3779
Mike Stump1eb44332009-09-09 15:08:12 +00003780template<typename Derived>
3781QualType
John McCalla2becad2009-10-21 00:40:46 +00003782TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003783 RValueReferenceTypeLoc TL) {
3784 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003785}
Mike Stump1eb44332009-09-09 15:08:12 +00003786
Douglas Gregor577f75a2009-08-04 16:50:30 +00003787template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003788QualType
John McCalla2becad2009-10-21 00:40:46 +00003789TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003790 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003791 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003792 if (PointeeType.isNull())
3793 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003794
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003795 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3796 TypeSourceInfo* NewClsTInfo = 0;
3797 if (OldClsTInfo) {
3798 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3799 if (!NewClsTInfo)
3800 return QualType();
3801 }
3802
3803 const MemberPointerType *T = TL.getTypePtr();
3804 QualType OldClsType = QualType(T->getClass(), 0);
3805 QualType NewClsType;
3806 if (NewClsTInfo)
3807 NewClsType = NewClsTInfo->getType();
3808 else {
3809 NewClsType = getDerived().TransformType(OldClsType);
3810 if (NewClsType.isNull())
3811 return QualType();
3812 }
Mike Stump1eb44332009-09-09 15:08:12 +00003813
John McCalla2becad2009-10-21 00:40:46 +00003814 QualType Result = TL.getType();
3815 if (getDerived().AlwaysRebuild() ||
3816 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003817 NewClsType != OldClsType) {
3818 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003819 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003820 if (Result.isNull())
3821 return QualType();
3822 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823
John McCalla2becad2009-10-21 00:40:46 +00003824 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3825 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003826 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
3830
Mike Stump1eb44332009-09-09 15:08:12 +00003831template<typename Derived>
3832QualType
John McCalla2becad2009-10-21 00:40:46 +00003833TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003834 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003835 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003836 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003837 if (ElementType.isNull())
3838 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003839
John McCalla2becad2009-10-21 00:40:46 +00003840 QualType Result = TL.getType();
3841 if (getDerived().AlwaysRebuild() ||
3842 ElementType != T->getElementType()) {
3843 Result = getDerived().RebuildConstantArrayType(ElementType,
3844 T->getSizeModifier(),
3845 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003846 T->getIndexTypeCVRQualifiers(),
3847 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003848 if (Result.isNull())
3849 return QualType();
3850 }
Eli Friedman457a3772012-01-25 22:19:07 +00003851
3852 // We might have either a ConstantArrayType or a VariableArrayType now:
3853 // a ConstantArrayType is allowed to have an element type which is a
3854 // VariableArrayType if the type is dependent. Fortunately, all array
3855 // types have the same location layout.
3856 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003857 NewTL.setLBracketLoc(TL.getLBracketLoc());
3858 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003859
John McCalla2becad2009-10-21 00:40:46 +00003860 Expr *Size = TL.getSizeExpr();
3861 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003862 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3863 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003864 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003865 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003866 }
3867 NewTL.setSizeExpr(Size);
3868
3869 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003870}
Mike Stump1eb44332009-09-09 15:08:12 +00003871
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003873QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003874 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003875 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003876 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003877 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878 if (ElementType.isNull())
3879 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003880
John McCalla2becad2009-10-21 00:40:46 +00003881 QualType Result = TL.getType();
3882 if (getDerived().AlwaysRebuild() ||
3883 ElementType != T->getElementType()) {
3884 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003885 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003886 T->getIndexTypeCVRQualifiers(),
3887 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003888 if (Result.isNull())
3889 return QualType();
3890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003891
John McCalla2becad2009-10-21 00:40:46 +00003892 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3893 NewTL.setLBracketLoc(TL.getLBracketLoc());
3894 NewTL.setRBracketLoc(TL.getRBracketLoc());
3895 NewTL.setSizeExpr(0);
3896
3897 return Result;
3898}
3899
3900template<typename Derived>
3901QualType
3902TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003903 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003904 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003905 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3906 if (ElementType.isNull())
3907 return QualType();
3908
John McCall60d7b3a2010-08-24 06:29:42 +00003909 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003910 = getDerived().TransformExpr(T->getSizeExpr());
3911 if (SizeResult.isInvalid())
3912 return QualType();
3913
John McCall9ae2f072010-08-23 23:25:46 +00003914 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003915
3916 QualType Result = TL.getType();
3917 if (getDerived().AlwaysRebuild() ||
3918 ElementType != T->getElementType() ||
3919 Size != T->getSizeExpr()) {
3920 Result = getDerived().RebuildVariableArrayType(ElementType,
3921 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003922 Size,
John McCalla2becad2009-10-21 00:40:46 +00003923 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003924 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003925 if (Result.isNull())
3926 return QualType();
3927 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003928
John McCalla2becad2009-10-21 00:40:46 +00003929 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3930 NewTL.setLBracketLoc(TL.getLBracketLoc());
3931 NewTL.setRBracketLoc(TL.getRBracketLoc());
3932 NewTL.setSizeExpr(Size);
3933
3934 return Result;
3935}
3936
3937template<typename Derived>
3938QualType
3939TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003940 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003941 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003942 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3943 if (ElementType.isNull())
3944 return QualType();
3945
Richard Smithf6702a32011-12-20 02:08:33 +00003946 // Array bounds are constant expressions.
3947 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3948 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003949
John McCall3b657512011-01-19 10:06:00 +00003950 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3951 Expr *origSize = TL.getSizeExpr();
3952 if (!origSize) origSize = T->getSizeExpr();
3953
3954 ExprResult sizeResult
3955 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003956 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003957 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003958 return QualType();
3959
John McCall3b657512011-01-19 10:06:00 +00003960 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003961
3962 QualType Result = TL.getType();
3963 if (getDerived().AlwaysRebuild() ||
3964 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003965 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003966 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3967 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003968 size,
John McCalla2becad2009-10-21 00:40:46 +00003969 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003970 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003971 if (Result.isNull())
3972 return QualType();
3973 }
John McCalla2becad2009-10-21 00:40:46 +00003974
3975 // We might have any sort of array type now, but fortunately they
3976 // all have the same location layout.
3977 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3978 NewTL.setLBracketLoc(TL.getLBracketLoc());
3979 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003980 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003981
3982 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003983}
Mike Stump1eb44332009-09-09 15:08:12 +00003984
3985template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003986QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003987 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003988 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003989 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003990
3991 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003992 QualType ElementType = getDerived().TransformType(T->getElementType());
3993 if (ElementType.isNull())
3994 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003995
Richard Smithf6702a32011-12-20 02:08:33 +00003996 // Vector sizes are constant expressions.
3997 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3998 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003999
John McCall60d7b3a2010-08-24 06:29:42 +00004000 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004001 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004002 if (Size.isInvalid())
4003 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004004
John McCalla2becad2009-10-21 00:40:46 +00004005 QualType Result = TL.getType();
4006 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004007 ElementType != T->getElementType() ||
4008 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004009 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004010 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004011 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004012 if (Result.isNull())
4013 return QualType();
4014 }
John McCalla2becad2009-10-21 00:40:46 +00004015
4016 // Result might be dependent or not.
4017 if (isa<DependentSizedExtVectorType>(Result)) {
4018 DependentSizedExtVectorTypeLoc NewTL
4019 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4020 NewTL.setNameLoc(TL.getNameLoc());
4021 } else {
4022 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4023 NewTL.setNameLoc(TL.getNameLoc());
4024 }
4025
4026 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004027}
Mike Stump1eb44332009-09-09 15:08:12 +00004028
4029template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004030QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004031 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004032 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004033 QualType ElementType = getDerived().TransformType(T->getElementType());
4034 if (ElementType.isNull())
4035 return QualType();
4036
John McCalla2becad2009-10-21 00:40:46 +00004037 QualType Result = TL.getType();
4038 if (getDerived().AlwaysRebuild() ||
4039 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004040 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004041 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004042 if (Result.isNull())
4043 return QualType();
4044 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004045
John McCalla2becad2009-10-21 00:40:46 +00004046 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4047 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004048
John McCalla2becad2009-10-21 00:40:46 +00004049 return Result;
4050}
4051
4052template<typename Derived>
4053QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004054 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004055 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004056 QualType ElementType = getDerived().TransformType(T->getElementType());
4057 if (ElementType.isNull())
4058 return QualType();
4059
4060 QualType Result = TL.getType();
4061 if (getDerived().AlwaysRebuild() ||
4062 ElementType != T->getElementType()) {
4063 Result = getDerived().RebuildExtVectorType(ElementType,
4064 T->getNumElements(),
4065 /*FIXME*/ SourceLocation());
4066 if (Result.isNull())
4067 return QualType();
4068 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004069
John McCalla2becad2009-10-21 00:40:46 +00004070 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4071 NewTL.setNameLoc(TL.getNameLoc());
4072
4073 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004074}
Mike Stump1eb44332009-09-09 15:08:12 +00004075
David Blaikiedc84cd52013-02-20 22:23:23 +00004076template <typename Derived>
4077ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4078 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4079 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004080 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004081 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004082
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004083 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004085 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004086 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004087 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004089 TypeLocBuilder TLB;
4090 TypeLoc NewTL = OldDI->getTypeLoc();
4091 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004092
4093 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004094 OldExpansionTL.getPatternLoc());
4095 if (Result.isNull())
4096 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097
4098 Result = RebuildPackExpansionType(Result,
4099 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004100 OldExpansionTL.getEllipsisLoc(),
4101 NumExpansions);
4102 if (Result.isNull())
4103 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004105 PackExpansionTypeLoc NewExpansionTL
4106 = TLB.push<PackExpansionTypeLoc>(Result);
4107 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4108 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4109 } else
4110 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004111 if (!NewDI)
4112 return 0;
4113
John McCallfb44de92011-05-01 22:35:37 +00004114 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004115 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004116
4117 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4118 OldParm->getDeclContext(),
4119 OldParm->getInnerLocStart(),
4120 OldParm->getLocation(),
4121 OldParm->getIdentifier(),
4122 NewDI->getType(),
4123 NewDI,
4124 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004125 /* DefArg */ NULL);
4126 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4127 OldParm->getFunctionScopeIndex() + indexAdjustment);
4128 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004129}
4130
4131template<typename Derived>
4132bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004133 TransformFunctionTypeParams(SourceLocation Loc,
4134 ParmVarDecl **Params, unsigned NumParams,
4135 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004136 SmallVectorImpl<QualType> &OutParamTypes,
4137 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004138 int indexAdjustment = 0;
4139
Douglas Gregora009b592011-01-07 00:20:55 +00004140 for (unsigned i = 0; i != NumParams; ++i) {
4141 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004142 assert(OldParm->getFunctionScopeIndex() == i);
4143
David Blaikiedc84cd52013-02-20 22:23:23 +00004144 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004145 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 if (OldParm->isParameterPack()) {
4147 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004148 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004149
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004151 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004152 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004153 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4154 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004155 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4156
Douglas Gregor603cfb42011-01-05 23:12:31 +00004157 // Determine whether we should expand the parameter packs.
4158 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004159 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004160 Optional<unsigned> OrigNumExpansions =
4161 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004162 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004163 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4164 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004165 Unexpanded,
4166 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004167 RetainExpansion,
4168 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004169 return true;
4170 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004171
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 if (ShouldExpand) {
4173 // Expand the function parameter pack into multiple, separate
4174 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004175 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004176 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004178 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004179 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004180 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004181 OrigNumExpansions,
4182 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004183 if (!NewParm)
4184 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004185
Douglas Gregora009b592011-01-07 00:20:55 +00004186 OutParamTypes.push_back(NewParm->getType());
4187 if (PVars)
4188 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 }
Douglas Gregord3731192011-01-10 07:32:04 +00004190
4191 // If we're supposed to retain a pack expansion, do so by temporarily
4192 // forgetting the partially-substituted parameter pack.
4193 if (RetainExpansion) {
4194 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004195 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004196 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004197 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004198 OrigNumExpansions,
4199 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004200 if (!NewParm)
4201 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004202
Douglas Gregord3731192011-01-10 07:32:04 +00004203 OutParamTypes.push_back(NewParm->getType());
4204 if (PVars)
4205 PVars->push_back(NewParm);
4206 }
4207
John McCallfb44de92011-05-01 22:35:37 +00004208 // The next parameter should have the same adjustment as the
4209 // last thing we pushed, but we post-incremented indexAdjustment
4210 // on every push. Also, if we push nothing, the adjustment should
4211 // go down by one.
4212 indexAdjustment--;
4213
Douglas Gregor603cfb42011-01-05 23:12:31 +00004214 // We're done with the pack expansion.
4215 continue;
4216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217
4218 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004219 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004220 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4221 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004222 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004223 NumExpansions,
4224 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004225 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004226 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004227 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004228 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004229
John McCall21ef0fa2010-03-11 09:03:00 +00004230 if (!NewParm)
4231 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004232
Douglas Gregora009b592011-01-07 00:20:55 +00004233 OutParamTypes.push_back(NewParm->getType());
4234 if (PVars)
4235 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004236 continue;
4237 }
John McCall21ef0fa2010-03-11 09:03:00 +00004238
4239 // Deal with the possibility that we don't have a parameter
4240 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004241 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004242 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004243 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004244 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004245 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004246 = dyn_cast<PackExpansionType>(OldType)) {
4247 // We have a function parameter pack that may need to be expanded.
4248 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004249 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004250 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004251
Douglas Gregor603cfb42011-01-05 23:12:31 +00004252 // Determine whether we should expand the parameter packs.
4253 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004254 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004255 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004256 Unexpanded,
4257 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004258 RetainExpansion,
4259 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004260 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004262
Douglas Gregor603cfb42011-01-05 23:12:31 +00004263 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004264 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004265 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004266 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004267 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4268 QualType NewType = getDerived().TransformType(Pattern);
4269 if (NewType.isNull())
4270 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004271
Douglas Gregora009b592011-01-07 00:20:55 +00004272 OutParamTypes.push_back(NewType);
4273 if (PVars)
4274 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004275 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004276
Douglas Gregor603cfb42011-01-05 23:12:31 +00004277 // We're done with the pack expansion.
4278 continue;
4279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004281 // If we're supposed to retain a pack expansion, do so by temporarily
4282 // forgetting the partially-substituted parameter pack.
4283 if (RetainExpansion) {
4284 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4285 QualType NewType = getDerived().TransformType(Pattern);
4286 if (NewType.isNull())
4287 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004288
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004289 OutParamTypes.push_back(NewType);
4290 if (PVars)
4291 PVars->push_back(0);
4292 }
Douglas Gregord3731192011-01-10 07:32:04 +00004293
Chad Rosier4a9d7952012-08-08 18:46:20 +00004294 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004295 // expansion.
4296 OldType = Expansion->getPattern();
4297 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004298 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4299 NewType = getDerived().TransformType(OldType);
4300 } else {
4301 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004302 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004303
Douglas Gregor603cfb42011-01-05 23:12:31 +00004304 if (NewType.isNull())
4305 return true;
4306
4307 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004308 NewType = getSema().Context.getPackExpansionType(NewType,
4309 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004310
Douglas Gregora009b592011-01-07 00:20:55 +00004311 OutParamTypes.push_back(NewType);
4312 if (PVars)
4313 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004314 }
4315
John McCallfb44de92011-05-01 22:35:37 +00004316#ifndef NDEBUG
4317 if (PVars) {
4318 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4319 if (ParmVarDecl *parm = (*PVars)[i])
4320 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004321 }
John McCallfb44de92011-05-01 22:35:37 +00004322#endif
4323
4324 return false;
4325}
John McCall21ef0fa2010-03-11 09:03:00 +00004326
4327template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004328QualType
John McCalla2becad2009-10-21 00:40:46 +00004329TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004330 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004331 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4332}
4333
4334template<typename Derived>
4335QualType
4336TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4337 FunctionProtoTypeLoc TL,
4338 CXXRecordDecl *ThisContext,
4339 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004340 // Transform the parameters and return type.
4341 //
Richard Smithe6975e92012-04-17 00:58:00 +00004342 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004343 // When the function has a trailing return type, we instantiate the
4344 // parameters before the return type, since the return type can then refer
4345 // to the parameters themselves (via decltype, sizeof, etc.).
4346 //
Chris Lattner686775d2011-07-20 06:58:45 +00004347 SmallVector<QualType, 4> ParamTypes;
4348 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004349 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004350
Douglas Gregordab60ad2010-10-01 18:44:50 +00004351 QualType ResultType;
4352
Richard Smith9fbf3272012-08-14 22:51:13 +00004353 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004354 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004355 TL.getParmArray(),
4356 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004357 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004358 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004359 return QualType();
4360
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004361 {
4362 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004363 // If a declaration declares a member function or member function
4364 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004365 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004366 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004367 // declarator.
4368 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004369
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004370 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4371 if (ResultType.isNull())
4372 return QualType();
4373 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004374 }
4375 else {
4376 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4377 if (ResultType.isNull())
4378 return QualType();
4379
Chad Rosier4a9d7952012-08-08 18:46:20 +00004380 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004381 TL.getParmArray(),
4382 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004383 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004384 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004385 return QualType();
4386 }
4387
Richard Smithe6975e92012-04-17 00:58:00 +00004388 // FIXME: Need to transform the exception-specification too.
4389
John McCalla2becad2009-10-21 00:40:46 +00004390 QualType Result = TL.getType();
4391 if (getDerived().AlwaysRebuild() ||
4392 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004393 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004394 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004395 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004396 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004397 if (Result.isNull())
4398 return QualType();
4399 }
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCalla2becad2009-10-21 00:40:46 +00004401 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004402 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004403 NewTL.setLParenLoc(TL.getLParenLoc());
4404 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004405 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004406 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4407 NewTL.setArg(i, ParamDecls[i]);
4408
4409 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004410}
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregor577f75a2009-08-04 16:50:30 +00004412template<typename Derived>
4413QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004414 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004415 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004416 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004417 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4418 if (ResultType.isNull())
4419 return QualType();
4420
4421 QualType Result = TL.getType();
4422 if (getDerived().AlwaysRebuild() ||
4423 ResultType != T->getResultType())
4424 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4425
4426 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004427 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004428 NewTL.setLParenLoc(TL.getLParenLoc());
4429 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004430 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004431
4432 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004433}
Mike Stump1eb44332009-09-09 15:08:12 +00004434
John McCalled976492009-12-04 22:46:56 +00004435template<typename Derived> QualType
4436TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004437 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004438 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004439 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004440 if (!D)
4441 return QualType();
4442
4443 QualType Result = TL.getType();
4444 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4445 Result = getDerived().RebuildUnresolvedUsingType(D);
4446 if (Result.isNull())
4447 return QualType();
4448 }
4449
4450 // We might get an arbitrary type spec type back. We should at
4451 // least always get a type spec type, though.
4452 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4453 NewTL.setNameLoc(TL.getNameLoc());
4454
4455 return Result;
4456}
4457
Douglas Gregor577f75a2009-08-04 16:50:30 +00004458template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004459QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004460 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004461 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004462 TypedefNameDecl *Typedef
4463 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4464 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004465 if (!Typedef)
4466 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004467
John McCalla2becad2009-10-21 00:40:46 +00004468 QualType Result = TL.getType();
4469 if (getDerived().AlwaysRebuild() ||
4470 Typedef != T->getDecl()) {
4471 Result = getDerived().RebuildTypedefType(Typedef);
4472 if (Result.isNull())
4473 return QualType();
4474 }
Mike Stump1eb44332009-09-09 15:08:12 +00004475
John McCalla2becad2009-10-21 00:40:46 +00004476 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4477 NewTL.setNameLoc(TL.getNameLoc());
4478
4479 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480}
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Douglas Gregor577f75a2009-08-04 16:50:30 +00004482template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004483QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004484 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004485 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004486 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4487 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCall60d7b3a2010-08-24 06:29:42 +00004489 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004490 if (E.isInvalid())
4491 return QualType();
4492
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004493 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4494 if (E.isInvalid())
4495 return QualType();
4496
John McCalla2becad2009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004499 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004500 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004501 if (Result.isNull())
4502 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503 }
John McCalla2becad2009-10-21 00:40:46 +00004504 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004507 NewTL.setTypeofLoc(TL.getTypeofLoc());
4508 NewTL.setLParenLoc(TL.getLParenLoc());
4509 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004510
4511 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004512}
Mike Stump1eb44332009-09-09 15:08:12 +00004513
4514template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004515QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004516 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004517 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4518 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4519 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004520 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004521
John McCalla2becad2009-10-21 00:40:46 +00004522 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004523 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4524 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004525 if (Result.isNull())
4526 return QualType();
4527 }
Mike Stump1eb44332009-09-09 15:08:12 +00004528
John McCalla2becad2009-10-21 00:40:46 +00004529 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004530 NewTL.setTypeofLoc(TL.getTypeofLoc());
4531 NewTL.setLParenLoc(TL.getLParenLoc());
4532 NewTL.setRParenLoc(TL.getRParenLoc());
4533 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004534
4535 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004536}
Mike Stump1eb44332009-09-09 15:08:12 +00004537
4538template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004539QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004540 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004541 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004542
Douglas Gregor670444e2009-08-04 22:27:00 +00004543 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004544 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4545 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004546
John McCall60d7b3a2010-08-24 06:29:42 +00004547 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004548 if (E.isInvalid())
4549 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
Richard Smith76f3f692012-02-22 02:04:18 +00004551 E = getSema().ActOnDecltypeExpression(E.take());
4552 if (E.isInvalid())
4553 return QualType();
4554
John McCalla2becad2009-10-21 00:40:46 +00004555 QualType Result = TL.getType();
4556 if (getDerived().AlwaysRebuild() ||
4557 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004558 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004559 if (Result.isNull())
4560 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004561 }
John McCalla2becad2009-10-21 00:40:46 +00004562 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004563
John McCalla2becad2009-10-21 00:40:46 +00004564 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4565 NewTL.setNameLoc(TL.getNameLoc());
4566
4567 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004568}
4569
4570template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004571QualType TreeTransform<Derived>::TransformUnaryTransformType(
4572 TypeLocBuilder &TLB,
4573 UnaryTransformTypeLoc TL) {
4574 QualType Result = TL.getType();
4575 if (Result->isDependentType()) {
4576 const UnaryTransformType *T = TL.getTypePtr();
4577 QualType NewBase =
4578 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4579 Result = getDerived().RebuildUnaryTransformType(NewBase,
4580 T->getUTTKind(),
4581 TL.getKWLoc());
4582 if (Result.isNull())
4583 return QualType();
4584 }
4585
4586 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4587 NewTL.setKWLoc(TL.getKWLoc());
4588 NewTL.setParensRange(TL.getParensRange());
4589 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4590 return Result;
4591}
4592
4593template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004594QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4595 AutoTypeLoc TL) {
4596 const AutoType *T = TL.getTypePtr();
4597 QualType OldDeduced = T->getDeducedType();
4598 QualType NewDeduced;
4599 if (!OldDeduced.isNull()) {
4600 NewDeduced = getDerived().TransformType(OldDeduced);
4601 if (NewDeduced.isNull())
4602 return QualType();
4603 }
4604
4605 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004606 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4607 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004608 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004609 if (Result.isNull())
4610 return QualType();
4611 }
4612
4613 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4614 NewTL.setNameLoc(TL.getNameLoc());
4615
4616 return Result;
4617}
4618
4619template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004620QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004621 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004622 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004623 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004624 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4625 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004626 if (!Record)
4627 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004628
John McCalla2becad2009-10-21 00:40:46 +00004629 QualType Result = TL.getType();
4630 if (getDerived().AlwaysRebuild() ||
4631 Record != T->getDecl()) {
4632 Result = getDerived().RebuildRecordType(Record);
4633 if (Result.isNull())
4634 return QualType();
4635 }
Mike Stump1eb44332009-09-09 15:08:12 +00004636
John McCalla2becad2009-10-21 00:40:46 +00004637 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4638 NewTL.setNameLoc(TL.getNameLoc());
4639
4640 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004641}
Mike Stump1eb44332009-09-09 15:08:12 +00004642
4643template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004644QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004645 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004646 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004647 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004648 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4649 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004650 if (!Enum)
4651 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004652
John McCalla2becad2009-10-21 00:40:46 +00004653 QualType Result = TL.getType();
4654 if (getDerived().AlwaysRebuild() ||
4655 Enum != T->getDecl()) {
4656 Result = getDerived().RebuildEnumType(Enum);
4657 if (Result.isNull())
4658 return QualType();
4659 }
Mike Stump1eb44332009-09-09 15:08:12 +00004660
John McCalla2becad2009-10-21 00:40:46 +00004661 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4662 NewTL.setNameLoc(TL.getNameLoc());
4663
4664 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004665}
John McCall7da24312009-09-05 00:15:47 +00004666
John McCall3cb0ebd2010-03-10 03:28:59 +00004667template<typename Derived>
4668QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4669 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004670 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004671 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4672 TL.getTypePtr()->getDecl());
4673 if (!D) return QualType();
4674
4675 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4676 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4677 return T;
4678}
4679
Douglas Gregor577f75a2009-08-04 16:50:30 +00004680template<typename Derived>
4681QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004682 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004683 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004684 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004685}
4686
Mike Stump1eb44332009-09-09 15:08:12 +00004687template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004688QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004689 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004690 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004691 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004693 // Substitute into the replacement type, which itself might involve something
4694 // that needs to be transformed. This only tends to occur with default
4695 // template arguments of template template parameters.
4696 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4697 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4698 if (Replacement.isNull())
4699 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004700
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004701 // Always canonicalize the replacement type.
4702 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4703 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004705 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004706
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004707 // Propagate type-source information.
4708 SubstTemplateTypeParmTypeLoc NewTL
4709 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4710 NewTL.setNameLoc(TL.getNameLoc());
4711 return Result;
4712
John McCall49a832b2009-10-18 09:09:24 +00004713}
4714
4715template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004716QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4717 TypeLocBuilder &TLB,
4718 SubstTemplateTypeParmPackTypeLoc TL) {
4719 return TransformTypeSpecType(TLB, TL);
4720}
4721
4722template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004723QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004724 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004725 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004726 const TemplateSpecializationType *T = TL.getTypePtr();
4727
Douglas Gregor1d752d72011-03-02 18:46:51 +00004728 // The nested-name-specifier never matters in a TemplateSpecializationType,
4729 // because we can't have a dependent nested-name-specifier anyway.
4730 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004731 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004732 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4733 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004734 if (Template.isNull())
4735 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004736
John McCall43fed0d2010-11-12 08:19:04 +00004737 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4738}
4739
Eli Friedmanb001de72011-10-06 23:00:33 +00004740template<typename Derived>
4741QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4742 AtomicTypeLoc TL) {
4743 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4744 if (ValueType.isNull())
4745 return QualType();
4746
4747 QualType Result = TL.getType();
4748 if (getDerived().AlwaysRebuild() ||
4749 ValueType != TL.getValueLoc().getType()) {
4750 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4751 if (Result.isNull())
4752 return QualType();
4753 }
4754
4755 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4756 NewTL.setKWLoc(TL.getKWLoc());
4757 NewTL.setLParenLoc(TL.getLParenLoc());
4758 NewTL.setRParenLoc(TL.getRParenLoc());
4759
4760 return Result;
4761}
4762
Chad Rosier4a9d7952012-08-08 18:46:20 +00004763 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004764 /// container that provides a \c getArgLoc() member function.
4765 ///
4766 /// This iterator is intended to be used with the iterator form of
4767 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4768 template<typename ArgLocContainer>
4769 class TemplateArgumentLocContainerIterator {
4770 ArgLocContainer *Container;
4771 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004772
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004773 public:
4774 typedef TemplateArgumentLoc value_type;
4775 typedef TemplateArgumentLoc reference;
4776 typedef int difference_type;
4777 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004778
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004779 class pointer {
4780 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004781
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004782 public:
4783 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004785 const TemplateArgumentLoc *operator->() const {
4786 return &Arg;
4787 }
4788 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004789
4790
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004791 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004793 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4794 unsigned Index)
4795 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004797 TemplateArgumentLocContainerIterator &operator++() {
4798 ++Index;
4799 return *this;
4800 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 TemplateArgumentLocContainerIterator operator++(int) {
4803 TemplateArgumentLocContainerIterator Old(*this);
4804 ++(*this);
4805 return Old;
4806 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004807
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004808 TemplateArgumentLoc operator*() const {
4809 return Container->getArgLoc(Index);
4810 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004811
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004812 pointer operator->() const {
4813 return pointer(Container->getArgLoc(Index));
4814 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004816 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004817 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004818 return X.Container == Y.Container && X.Index == Y.Index;
4819 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004820
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004821 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004822 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004823 return !(X == Y);
4824 }
4825 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004826
4827
John McCall43fed0d2010-11-12 08:19:04 +00004828template <typename Derived>
4829QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4830 TypeLocBuilder &TLB,
4831 TemplateSpecializationTypeLoc TL,
4832 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004833 TemplateArgumentListInfo NewTemplateArgs;
4834 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4835 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004836 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4837 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004838 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004839 ArgIterator(TL, TL.getNumArgs()),
4840 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004841 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004842
John McCall833ca992009-10-29 08:12:44 +00004843 // FIXME: maybe don't rebuild if all the template arguments are the same.
4844
4845 QualType Result =
4846 getDerived().RebuildTemplateSpecializationType(Template,
4847 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004848 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004849
4850 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004851 // Specializations of template template parameters are represented as
4852 // TemplateSpecializationTypes, and substitution of type alias templates
4853 // within a dependent context can transform them into
4854 // DependentTemplateSpecializationTypes.
4855 if (isa<DependentTemplateSpecializationType>(Result)) {
4856 DependentTemplateSpecializationTypeLoc NewTL
4857 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004858 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004859 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004860 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004861 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004862 NewTL.setLAngleLoc(TL.getLAngleLoc());
4863 NewTL.setRAngleLoc(TL.getRAngleLoc());
4864 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4865 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4866 return Result;
4867 }
4868
John McCall833ca992009-10-29 08:12:44 +00004869 TemplateSpecializationTypeLoc NewTL
4870 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004871 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004872 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4873 NewTL.setLAngleLoc(TL.getLAngleLoc());
4874 NewTL.setRAngleLoc(TL.getRAngleLoc());
4875 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4876 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004877 }
Mike Stump1eb44332009-09-09 15:08:12 +00004878
John McCall833ca992009-10-29 08:12:44 +00004879 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004880}
Mike Stump1eb44332009-09-09 15:08:12 +00004881
Douglas Gregora88f09f2011-02-28 17:23:35 +00004882template <typename Derived>
4883QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4884 TypeLocBuilder &TLB,
4885 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004886 TemplateName Template,
4887 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004888 TemplateArgumentListInfo NewTemplateArgs;
4889 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4890 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4891 typedef TemplateArgumentLocContainerIterator<
4892 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004893 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004894 ArgIterator(TL, TL.getNumArgs()),
4895 NewTemplateArgs))
4896 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004897
Douglas Gregora88f09f2011-02-28 17:23:35 +00004898 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004899
Douglas Gregora88f09f2011-02-28 17:23:35 +00004900 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4901 QualType Result
4902 = getSema().Context.getDependentTemplateSpecializationType(
4903 TL.getTypePtr()->getKeyword(),
4904 DTN->getQualifier(),
4905 DTN->getIdentifier(),
4906 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004907
Douglas Gregora88f09f2011-02-28 17:23:35 +00004908 DependentTemplateSpecializationTypeLoc NewTL
4909 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004910 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004911 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004912 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004913 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004914 NewTL.setLAngleLoc(TL.getLAngleLoc());
4915 NewTL.setRAngleLoc(TL.getRAngleLoc());
4916 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4917 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4918 return Result;
4919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004920
4921 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004922 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004923 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004924 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004925
Douglas Gregora88f09f2011-02-28 17:23:35 +00004926 if (!Result.isNull()) {
4927 /// FIXME: Wrap this in an elaborated-type-specifier?
4928 TemplateSpecializationTypeLoc NewTL
4929 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004930 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004931 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004932 NewTL.setLAngleLoc(TL.getLAngleLoc());
4933 NewTL.setRAngleLoc(TL.getRAngleLoc());
4934 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4935 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4936 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004937
Douglas Gregora88f09f2011-02-28 17:23:35 +00004938 return Result;
4939}
4940
Mike Stump1eb44332009-09-09 15:08:12 +00004941template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004942QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004943TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004944 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004945 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004946
Douglas Gregor9e876872011-03-01 18:12:44 +00004947 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004948 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004949 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004950 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004951 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4952 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004953 return QualType();
4954 }
Mike Stump1eb44332009-09-09 15:08:12 +00004955
John McCall43fed0d2010-11-12 08:19:04 +00004956 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4957 if (NamedT.isNull())
4958 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004959
Richard Smith3e4c6c42011-05-05 21:57:07 +00004960 // C++0x [dcl.type.elab]p2:
4961 // If the identifier resolves to a typedef-name or the simple-template-id
4962 // resolves to an alias template specialization, the
4963 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004964 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4965 if (const TemplateSpecializationType *TST =
4966 NamedT->getAs<TemplateSpecializationType>()) {
4967 TemplateName Template = TST->getTemplateName();
4968 if (TypeAliasTemplateDecl *TAT =
4969 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4970 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4971 diag::err_tag_reference_non_tag) << 4;
4972 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4973 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004974 }
4975 }
4976
John McCalla2becad2009-10-21 00:40:46 +00004977 QualType Result = TL.getType();
4978 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004979 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004980 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004981 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004982 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004983 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004984 if (Result.isNull())
4985 return QualType();
4986 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004987
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004988 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004989 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004990 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004991 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004992}
Mike Stump1eb44332009-09-09 15:08:12 +00004993
4994template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004995QualType TreeTransform<Derived>::TransformAttributedType(
4996 TypeLocBuilder &TLB,
4997 AttributedTypeLoc TL) {
4998 const AttributedType *oldType = TL.getTypePtr();
4999 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5000 if (modifiedType.isNull())
5001 return QualType();
5002
5003 QualType result = TL.getType();
5004
5005 // FIXME: dependent operand expressions?
5006 if (getDerived().AlwaysRebuild() ||
5007 modifiedType != oldType->getModifiedType()) {
5008 // TODO: this is really lame; we should really be rebuilding the
5009 // equivalent type from first principles.
5010 QualType equivalentType
5011 = getDerived().TransformType(oldType->getEquivalentType());
5012 if (equivalentType.isNull())
5013 return QualType();
5014 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5015 modifiedType,
5016 equivalentType);
5017 }
5018
5019 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5020 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5021 if (TL.hasAttrOperand())
5022 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5023 if (TL.hasAttrExprOperand())
5024 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5025 else if (TL.hasAttrEnumOperand())
5026 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5027
5028 return result;
5029}
5030
5031template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005032QualType
5033TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5034 ParenTypeLoc TL) {
5035 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5036 if (Inner.isNull())
5037 return QualType();
5038
5039 QualType Result = TL.getType();
5040 if (getDerived().AlwaysRebuild() ||
5041 Inner != TL.getInnerLoc().getType()) {
5042 Result = getDerived().RebuildParenType(Inner);
5043 if (Result.isNull())
5044 return QualType();
5045 }
5046
5047 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5048 NewTL.setLParenLoc(TL.getLParenLoc());
5049 NewTL.setRParenLoc(TL.getRParenLoc());
5050 return Result;
5051}
5052
5053template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005054QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005055 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005056 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005057
Douglas Gregor2494dd02011-03-01 01:34:45 +00005058 NestedNameSpecifierLoc QualifierLoc
5059 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5060 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005061 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005062
John McCall33500952010-06-11 00:33:02 +00005063 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005064 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005065 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005066 QualifierLoc,
5067 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005068 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005069 if (Result.isNull())
5070 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005071
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005072 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5073 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005074 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5075
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005076 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005077 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005078 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005079 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005080 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005081 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005082 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005083 NewTL.setNameLoc(TL.getNameLoc());
5084 }
John McCalla2becad2009-10-21 00:40:46 +00005085 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005086}
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Douglas Gregor577f75a2009-08-04 16:50:30 +00005088template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005089QualType TreeTransform<Derived>::
5090 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005091 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005092 NestedNameSpecifierLoc QualifierLoc;
5093 if (TL.getQualifierLoc()) {
5094 QualifierLoc
5095 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5096 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005097 return QualType();
5098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005099
John McCall43fed0d2010-11-12 08:19:04 +00005100 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005101 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005102}
5103
5104template<typename Derived>
5105QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005106TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5107 DependentTemplateSpecializationTypeLoc TL,
5108 NestedNameSpecifierLoc QualifierLoc) {
5109 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005110
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005111 TemplateArgumentListInfo NewTemplateArgs;
5112 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5113 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005114
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005115 typedef TemplateArgumentLocContainerIterator<
5116 DependentTemplateSpecializationTypeLoc> ArgIterator;
5117 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5118 ArgIterator(TL, TL.getNumArgs()),
5119 NewTemplateArgs))
5120 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005121
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005122 QualType Result
5123 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5124 QualifierLoc,
5125 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005126 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005127 NewTemplateArgs);
5128 if (Result.isNull())
5129 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005130
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005131 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5132 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005133
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005134 // Copy information relevant to the template specialization.
5135 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005136 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005137 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005138 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005139 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5140 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005141 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005142 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005143
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 // Copy information relevant to the elaborated type.
5145 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005146 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005147 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005148 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5149 DependentTemplateSpecializationTypeLoc SpecTL
5150 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005151 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005152 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005153 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005154 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005155 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5156 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005157 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005158 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005159 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005160 TemplateSpecializationTypeLoc SpecTL
5161 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005162 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005163 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005164 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5165 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005166 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005167 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005168 }
5169 return Result;
5170}
5171
5172template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005173QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5174 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005175 QualType Pattern
5176 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005177 if (Pattern.isNull())
5178 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005179
5180 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005181 if (getDerived().AlwaysRebuild() ||
5182 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005183 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005184 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005185 TL.getEllipsisLoc(),
5186 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005187 if (Result.isNull())
5188 return QualType();
5189 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005190
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005191 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5192 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5193 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005194}
5195
5196template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005197QualType
5198TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005199 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005200 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005201 TLB.pushFullCopy(TL);
5202 return TL.getType();
5203}
5204
5205template<typename Derived>
5206QualType
5207TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005208 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005209 // ObjCObjectType is never dependent.
5210 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005211 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005212}
Mike Stump1eb44332009-09-09 15:08:12 +00005213
5214template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005215QualType
5216TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005217 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005218 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005219 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005220 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005221}
5222
Douglas Gregor577f75a2009-08-04 16:50:30 +00005223//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005224// Statement transformation
5225//===----------------------------------------------------------------------===//
5226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005227StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005228TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005229 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005230}
5231
5232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005233StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005234TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5235 return getDerived().TransformCompoundStmt(S, false);
5236}
5237
5238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005239StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005240TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005242 Sema::CompoundScopeRAII CompoundScope(getSema());
5243
John McCall7114cba2010-08-27 19:56:05 +00005244 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005246 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5248 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005249 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005250 if (Result.isInvalid()) {
5251 // Immediately fail if this was a DeclStmt, since it's very
5252 // likely that this will cause problems for future statements.
5253 if (isa<DeclStmt>(*B))
5254 return StmtError();
5255
5256 // Otherwise, just keep processing substatements and fail later.
5257 SubStmtInvalid = true;
5258 continue;
5259 }
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5262 Statements.push_back(Result.takeAs<Stmt>());
5263 }
Mike Stump1eb44332009-09-09 15:08:12 +00005264
John McCall7114cba2010-08-27 19:56:05 +00005265 if (SubStmtInvalid)
5266 return StmtError();
5267
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (!getDerived().AlwaysRebuild() &&
5269 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005270 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005271
5272 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005273 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 S->getRBracLoc(),
5275 IsStmtExpr);
5276}
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregor43959a92009-08-20 07:17:43 +00005278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005282 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005283 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5284 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005285
Eli Friedman264c1f82009-11-19 03:14:00 +00005286 // Transform the left-hand case value.
5287 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005288 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005289 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005290 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Eli Friedman264c1f82009-11-19 03:14:00 +00005292 // Transform the right-hand case value (for the GNU case-range extension).
5293 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005294 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005295 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Build the case statement.
5300 // Case statements are always rebuilt so that they will attached to their
5301 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005302 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005303 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005305 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 S->getColonLoc());
5307 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005311 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005316 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005317}
5318
5319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005320StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005321TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005322 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005323 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005326
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 // Default statements are always rebuilt
5328 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005329 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005330}
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005333StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005334TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Chris Lattner57ad3782011-02-17 20:34:02 +00005339 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5340 S->getDecl());
5341 if (!LD)
5342 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005343
5344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005346 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005347 cast<LabelDecl>(LD), SourceLocation(),
5348 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005349}
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005352StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005353TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5354 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5355 if (SubStmt.isInvalid())
5356 return StmtError();
5357
5358 // TODO: transform attributes
5359 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5360 return S;
5361
5362 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5363 S->getAttrs(),
5364 SubStmt.get());
5365}
5366
5367template<typename Derived>
5368StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005369TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005371 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005372 VarDecl *ConditionVar = 0;
5373 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005374 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005375 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005376 getDerived().TransformDefinition(
5377 S->getConditionVariable()->getLocation(),
5378 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005379 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005381 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005382 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005383
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005384 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005385 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005386
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005387 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005388 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005389 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005390 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005391 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005392 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005393
John McCall9ae2f072010-08-23 23:25:46 +00005394 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005395 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005397
John McCall9ae2f072010-08-23 23:25:46 +00005398 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5399 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005400 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401
Douglas Gregor43959a92009-08-20 07:17:43 +00005402 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005403 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005404 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005406
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005408 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005411
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005413 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005414 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005415 Then.get() == S->getThen() &&
5416 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005417 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005419 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005420 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005421 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005422}
5423
5424template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005425StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005426TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005428 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005429 VarDecl *ConditionVar = 0;
5430 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005431 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005432 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005433 getDerived().TransformDefinition(
5434 S->getConditionVariable()->getLocation(),
5435 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005436 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005438 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005439 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005440
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005441 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 }
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005446 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005447 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005448 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005451
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005453 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005458 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5459 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005460}
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005466 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005467 VarDecl *ConditionVar = 0;
5468 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005469 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005470 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005471 getDerived().TransformDefinition(
5472 S->getConditionVariable()->getLocation(),
5473 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005474 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005476 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005477 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005478
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005479 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005481
5482 if (S->getCond()) {
5483 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005484 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005485 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005486 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005487 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005488 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005489 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005490 }
Mike Stump1eb44332009-09-09 15:08:12 +00005491
John McCall9ae2f072010-08-23 23:25:46 +00005492 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5493 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005497 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005500
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005502 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005503 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005505 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005507 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005508 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor43959a92009-08-20 07:17:43 +00005511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005513TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005515 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005519 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005520 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005521 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 if (!getDerived().AlwaysRebuild() &&
5525 Cond.get() == S->getCond() &&
5526 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005528
John McCall9ae2f072010-08-23 23:25:46 +00005529 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5530 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005531 S->getRParenLoc());
5532}
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregor43959a92009-08-20 07:17:43 +00005534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005535StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005536TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005537 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005538 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005539 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregor43959a92009-08-20 07:17:43 +00005542 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005543 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005544 VarDecl *ConditionVar = 0;
5545 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005546 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005547 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005548 getDerived().TransformDefinition(
5549 S->getConditionVariable()->getLocation(),
5550 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005551 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005552 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005553 } else {
5554 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005555
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005556 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005558
5559 if (S->getCond()) {
5560 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005562 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005563 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005564 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005565
John McCall9ae2f072010-08-23 23:25:46 +00005566 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005567 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005568 }
Mike Stump1eb44332009-09-09 15:08:12 +00005569
Chad Rosier4a9d7952012-08-08 18:46:20 +00005570 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005571 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005572 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005573
Douglas Gregor43959a92009-08-20 07:17:43 +00005574 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005575 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005576 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005577 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005578
Richard Smith41956372013-01-14 22:39:08 +00005579 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005580 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005582
Douglas Gregor43959a92009-08-20 07:17:43 +00005583 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005584 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005585 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005587
Douglas Gregor43959a92009-08-20 07:17:43 +00005588 if (!getDerived().AlwaysRebuild() &&
5589 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005590 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005591 Inc.get() == S->getInc() &&
5592 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005593 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005596 Init.get(), FullCond, ConditionVar,
5597 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005598}
5599
5600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005601StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005602TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005603 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5604 S->getLabel());
5605 if (!LD)
5606 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005607
Douglas Gregor43959a92009-08-20 07:17:43 +00005608 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005609 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005610 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005611}
5612
5613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005614StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005615TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005616 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005619 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005620
Douglas Gregor43959a92009-08-20 07:17:43 +00005621 if (!getDerived().AlwaysRebuild() &&
5622 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005623 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005624
5625 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005626 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005627}
5628
5629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005632 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005633}
Mike Stump1eb44332009-09-09 15:08:12 +00005634
Douglas Gregor43959a92009-08-20 07:17:43 +00005635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005636StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005637TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005638 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005639}
Mike Stump1eb44332009-09-09 15:08:12 +00005640
Douglas Gregor43959a92009-08-20 07:17:43 +00005641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005642StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005643TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005644 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005645 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005646 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005647
Mike Stump1eb44332009-09-09 15:08:12 +00005648 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005649 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005650 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005651}
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregor43959a92009-08-20 07:17:43 +00005653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005656 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005657 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005658 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5659 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005660 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5661 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005663 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregor43959a92009-08-20 07:17:43 +00005665 if (Transformed != *D)
5666 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor43959a92009-08-20 07:17:43 +00005668 Decls.push_back(Transformed);
5669 }
Mike Stump1eb44332009-09-09 15:08:12 +00005670
Douglas Gregor43959a92009-08-20 07:17:43 +00005671 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005672 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005674 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005675}
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregor43959a92009-08-20 07:17:43 +00005677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005678StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005679TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005680
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005681 SmallVector<Expr*, 8> Constraints;
5682 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005683 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005684
John McCall60d7b3a2010-08-24 06:29:42 +00005685 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005686 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005687
5688 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005689
Anders Carlsson703e3942010-01-24 05:50:09 +00005690 // Go through the outputs.
5691 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005692 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005693
Anders Carlsson703e3942010-01-24 05:50:09 +00005694 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005695 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005696
Anders Carlsson703e3942010-01-24 05:50:09 +00005697 // Transform the output expr.
5698 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005699 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005700 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005701 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005702
Anders Carlsson703e3942010-01-24 05:50:09 +00005703 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005704
John McCall9ae2f072010-08-23 23:25:46 +00005705 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005707
Anders Carlsson703e3942010-01-24 05:50:09 +00005708 // Go through the inputs.
5709 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005710 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005711
Anders Carlsson703e3942010-01-24 05:50:09 +00005712 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005713 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005714
Anders Carlsson703e3942010-01-24 05:50:09 +00005715 // Transform the input expr.
5716 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005717 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005718 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005719 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005720
Anders Carlsson703e3942010-01-24 05:50:09 +00005721 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
John McCall9ae2f072010-08-23 23:25:46 +00005723 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Anders Carlsson703e3942010-01-24 05:50:09 +00005726 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005727 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005728
5729 // Go through the clobbers.
5730 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005731 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005732
5733 // No need to transform the asm string literal.
5734 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005735 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5736 S->isVolatile(), S->getNumOutputs(),
5737 S->getNumInputs(), Names.data(),
5738 Constraints, Exprs, AsmString.get(),
5739 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005740}
5741
Chad Rosier8cd64b42012-06-11 20:47:18 +00005742template<typename Derived>
5743StmtResult
5744TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005745 ArrayRef<Token> AsmToks =
5746 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005747
John McCallaeeacf72013-05-03 00:10:13 +00005748 bool HadError = false, HadChange = false;
5749
5750 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5751 SmallVector<Expr*, 8> TransformedExprs;
5752 TransformedExprs.reserve(SrcExprs.size());
5753 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5754 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5755 if (!Result.isUsable()) {
5756 HadError = true;
5757 } else {
5758 HadChange |= (Result.get() != SrcExprs[i]);
5759 TransformedExprs.push_back(Result.take());
5760 }
5761 }
5762
5763 if (HadError) return StmtError();
5764 if (!HadChange && !getDerived().AlwaysRebuild())
5765 return Owned(S);
5766
Chad Rosier7bd092b2012-08-15 16:53:30 +00005767 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005768 AsmToks, S->getAsmString(),
5769 S->getNumOutputs(), S->getNumInputs(),
5770 S->getAllConstraints(), S->getClobbers(),
5771 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005772}
Douglas Gregor43959a92009-08-20 07:17:43 +00005773
5774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005775StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005776TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005777 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005778 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005779 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005780 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005781
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005782 // Transform the @catch statements (if present).
5783 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005784 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005785 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005786 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005787 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005788 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005789 if (Catch.get() != S->getCatchStmt(I))
5790 AnyCatchChanged = true;
5791 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005792 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005793
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005794 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005795 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005796 if (S->getFinallyStmt()) {
5797 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5798 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005799 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005800 }
5801
5802 // If nothing changed, just retain this statement.
5803 if (!getDerived().AlwaysRebuild() &&
5804 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005805 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005806 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005807 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005808
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005809 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005810 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005811 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005812}
Mike Stump1eb44332009-09-09 15:08:12 +00005813
Douglas Gregor43959a92009-08-20 07:17:43 +00005814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005815StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005816TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005817 // Transform the @catch parameter, if there is one.
5818 VarDecl *Var = 0;
5819 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5820 TypeSourceInfo *TSInfo = 0;
5821 if (FromVar->getTypeSourceInfo()) {
5822 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5823 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005824 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005825 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005826
Douglas Gregorbe270a02010-04-26 17:57:08 +00005827 QualType T;
5828 if (TSInfo)
5829 T = TSInfo->getType();
5830 else {
5831 T = getDerived().TransformType(FromVar->getType());
5832 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005833 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005835
Douglas Gregorbe270a02010-04-26 17:57:08 +00005836 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5837 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005838 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005840
John McCall60d7b3a2010-08-24 06:29:42 +00005841 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005842 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005843 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005844
5845 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005847 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005848}
Mike Stump1eb44332009-09-09 15:08:12 +00005849
Douglas Gregor43959a92009-08-20 07:17:43 +00005850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005851StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005852TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005853 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005854 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005855 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005856 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005857
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005858 // If nothing changed, just retain this statement.
5859 if (!getDerived().AlwaysRebuild() &&
5860 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005861 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005862
5863 // Build a new statement.
5864 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005865 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005866}
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005869StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005870TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005871 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005872 if (S->getThrowExpr()) {
5873 Operand = getDerived().TransformExpr(S->getThrowExpr());
5874 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005875 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005876 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005877
Douglas Gregord1377b22010-04-22 21:44:01 +00005878 if (!getDerived().AlwaysRebuild() &&
5879 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005880 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005881
John McCall9ae2f072010-08-23 23:25:46 +00005882 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005883}
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Douglas Gregor43959a92009-08-20 07:17:43 +00005885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005886StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005887TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005888 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005889 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005890 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005891 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005892 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005893 Object =
5894 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5895 Object.get());
5896 if (Object.isInvalid())
5897 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005898
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005899 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005900 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005901 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005902 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005903
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005904 // If nothing change, just retain the current statement.
5905 if (!getDerived().AlwaysRebuild() &&
5906 Object.get() == S->getSynchExpr() &&
5907 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005908 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005909
5910 // Build a new statement.
5911 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005912 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005913}
5914
5915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005916StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005917TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5918 ObjCAutoreleasePoolStmt *S) {
5919 // Transform the body.
5920 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5921 if (Body.isInvalid())
5922 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005923
John McCallf85e1932011-06-15 23:02:42 +00005924 // If nothing changed, just retain this statement.
5925 if (!getDerived().AlwaysRebuild() &&
5926 Body.get() == S->getSubStmt())
5927 return SemaRef.Owned(S);
5928
5929 // Build a new statement.
5930 return getDerived().RebuildObjCAutoreleasePoolStmt(
5931 S->getAtLoc(), Body.get());
5932}
5933
5934template<typename Derived>
5935StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005936TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005937 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005938 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005939 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005940 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005941 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005942
Douglas Gregorc3203e72010-04-22 23:10:45 +00005943 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005944 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005945 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005946 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005947
Douglas Gregorc3203e72010-04-22 23:10:45 +00005948 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005949 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005950 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005951 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005952
Douglas Gregorc3203e72010-04-22 23:10:45 +00005953 // If nothing changed, just retain this statement.
5954 if (!getDerived().AlwaysRebuild() &&
5955 Element.get() == S->getElement() &&
5956 Collection.get() == S->getCollection() &&
5957 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005958 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005959
Douglas Gregorc3203e72010-04-22 23:10:45 +00005960 // Build a new statement.
5961 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005962 Element.get(),
5963 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005964 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005965 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005966}
5967
5968
5969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005970StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005971TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5972 // Transform the exception declaration, if any.
5973 VarDecl *Var = 0;
5974 if (S->getExceptionDecl()) {
5975 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005976 TypeSourceInfo *T = getDerived().TransformType(
5977 ExceptionDecl->getTypeSourceInfo());
5978 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005979 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005980
Douglas Gregor83cb9422010-09-09 17:09:21 +00005981 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005982 ExceptionDecl->getInnerLocStart(),
5983 ExceptionDecl->getLocation(),
5984 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005985 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005986 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005987 }
Mike Stump1eb44332009-09-09 15:08:12 +00005988
Douglas Gregor43959a92009-08-20 07:17:43 +00005989 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005990 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005991 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005992 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005993
Douglas Gregor43959a92009-08-20 07:17:43 +00005994 if (!getDerived().AlwaysRebuild() &&
5995 !Var &&
5996 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005997 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005998
5999 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6000 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006001 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006002}
Mike Stump1eb44332009-09-09 15:08:12 +00006003
Douglas Gregor43959a92009-08-20 07:17:43 +00006004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006005StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006006TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6007 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006008 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006009 = getDerived().TransformCompoundStmt(S->getTryBlock());
6010 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006011 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006012
Douglas Gregor43959a92009-08-20 07:17:43 +00006013 // Transform the handlers.
6014 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006015 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006016 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006017 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006018 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6019 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006020 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregor43959a92009-08-20 07:17:43 +00006022 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6023 Handlers.push_back(Handler.takeAs<Stmt>());
6024 }
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregor43959a92009-08-20 07:17:43 +00006026 if (!getDerived().AlwaysRebuild() &&
6027 TryBlock.get() == S->getTryBlock() &&
6028 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006029 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006030
John McCall9ae2f072010-08-23 23:25:46 +00006031 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006032 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006033}
Mike Stump1eb44332009-09-09 15:08:12 +00006034
Richard Smithad762fc2011-04-14 22:09:26 +00006035template<typename Derived>
6036StmtResult
6037TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6038 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6039 if (Range.isInvalid())
6040 return StmtError();
6041
6042 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6043 if (BeginEnd.isInvalid())
6044 return StmtError();
6045
6046 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6047 if (Cond.isInvalid())
6048 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006049 if (Cond.get())
6050 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6051 if (Cond.isInvalid())
6052 return StmtError();
6053 if (Cond.get())
6054 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006055
6056 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6057 if (Inc.isInvalid())
6058 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006059 if (Inc.get())
6060 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006061
6062 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6063 if (LoopVar.isInvalid())
6064 return StmtError();
6065
6066 StmtResult NewStmt = S;
6067 if (getDerived().AlwaysRebuild() ||
6068 Range.get() != S->getRangeStmt() ||
6069 BeginEnd.get() != S->getBeginEndStmt() ||
6070 Cond.get() != S->getCond() ||
6071 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006072 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006073 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6074 S->getColonLoc(), Range.get(),
6075 BeginEnd.get(), Cond.get(),
6076 Inc.get(), LoopVar.get(),
6077 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006078 if (NewStmt.isInvalid())
6079 return StmtError();
6080 }
Richard Smithad762fc2011-04-14 22:09:26 +00006081
6082 StmtResult Body = getDerived().TransformStmt(S->getBody());
6083 if (Body.isInvalid())
6084 return StmtError();
6085
6086 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6087 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006088 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006089 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6090 S->getColonLoc(), Range.get(),
6091 BeginEnd.get(), Cond.get(),
6092 Inc.get(), LoopVar.get(),
6093 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006094 if (NewStmt.isInvalid())
6095 return StmtError();
6096 }
Richard Smithad762fc2011-04-14 22:09:26 +00006097
6098 if (NewStmt.get() == S)
6099 return SemaRef.Owned(S);
6100
6101 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6102}
6103
John Wiegley28bbe4b2011-04-28 01:08:34 +00006104template<typename Derived>
6105StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006106TreeTransform<Derived>::TransformMSDependentExistsStmt(
6107 MSDependentExistsStmt *S) {
6108 // Transform the nested-name-specifier, if any.
6109 NestedNameSpecifierLoc QualifierLoc;
6110 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006111 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006112 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6113 if (!QualifierLoc)
6114 return StmtError();
6115 }
6116
6117 // Transform the declaration name.
6118 DeclarationNameInfo NameInfo = S->getNameInfo();
6119 if (NameInfo.getName()) {
6120 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6121 if (!NameInfo.getName())
6122 return StmtError();
6123 }
6124
6125 // Check whether anything changed.
6126 if (!getDerived().AlwaysRebuild() &&
6127 QualifierLoc == S->getQualifierLoc() &&
6128 NameInfo.getName() == S->getNameInfo().getName())
6129 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006130
Douglas Gregorba0513d2011-10-25 01:33:02 +00006131 // Determine whether this name exists, if we can.
6132 CXXScopeSpec SS;
6133 SS.Adopt(QualifierLoc);
6134 bool Dependent = false;
6135 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6136 case Sema::IER_Exists:
6137 if (S->isIfExists())
6138 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006139
Douglas Gregorba0513d2011-10-25 01:33:02 +00006140 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6141
6142 case Sema::IER_DoesNotExist:
6143 if (S->isIfNotExists())
6144 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006145
Douglas Gregorba0513d2011-10-25 01:33:02 +00006146 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006147
Douglas Gregorba0513d2011-10-25 01:33:02 +00006148 case Sema::IER_Dependent:
6149 Dependent = true;
6150 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006151
Douglas Gregor65019ac2011-10-25 03:44:56 +00006152 case Sema::IER_Error:
6153 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006155
Douglas Gregorba0513d2011-10-25 01:33:02 +00006156 // We need to continue with the instantiation, so do so now.
6157 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6158 if (SubStmt.isInvalid())
6159 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006160
Douglas Gregorba0513d2011-10-25 01:33:02 +00006161 // If we have resolved the name, just transform to the substatement.
6162 if (!Dependent)
6163 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006164
Douglas Gregorba0513d2011-10-25 01:33:02 +00006165 // The name is still dependent, so build a dependent expression again.
6166 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6167 S->isIfExists(),
6168 QualifierLoc,
6169 NameInfo,
6170 SubStmt.get());
6171}
6172
6173template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006174ExprResult
6175TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6176 NestedNameSpecifierLoc QualifierLoc;
6177 if (E->getQualifierLoc()) {
6178 QualifierLoc
6179 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6180 if (!QualifierLoc)
6181 return ExprError();
6182 }
6183
6184 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6185 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6186 if (!PD)
6187 return ExprError();
6188
6189 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6190 if (Base.isInvalid())
6191 return ExprError();
6192
6193 return new (SemaRef.getASTContext())
6194 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6195 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6196 QualifierLoc, E->getMemberLoc());
6197}
6198
6199template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006200StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006201TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6202 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6203 if(TryBlock.isInvalid()) return StmtError();
6204
6205 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6206 if(!getDerived().AlwaysRebuild() &&
6207 TryBlock.get() == S->getTryBlock() &&
6208 Handler.get() == S->getHandler())
6209 return SemaRef.Owned(S);
6210
6211 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6212 S->getTryLoc(),
6213 TryBlock.take(),
6214 Handler.take());
6215}
6216
6217template<typename Derived>
6218StmtResult
6219TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6220 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6221 if(Block.isInvalid()) return StmtError();
6222
6223 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6224 Block.take());
6225}
6226
6227template<typename Derived>
6228StmtResult
6229TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6230 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6231 if(FilterExpr.isInvalid()) return StmtError();
6232
6233 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6234 if(Block.isInvalid()) return StmtError();
6235
6236 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6237 FilterExpr.take(),
6238 Block.take());
6239}
6240
6241template<typename Derived>
6242StmtResult
6243TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6244 if(isa<SEHFinallyStmt>(Handler))
6245 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6246 else
6247 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6248}
6249
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006250template<typename Derived>
6251StmtResult
6252TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6253 // Transform the clauses
6254 llvm::SmallVector<OMPClause *, 5> TClauses;
6255 ArrayRef<OMPClause *> Clauses = D->clauses();
6256 TClauses.reserve(Clauses.size());
6257 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6258 I != E; ++I) {
6259 if (*I) {
6260 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6261 if (!Clause)
6262 return StmtError();
6263 TClauses.push_back(Clause);
6264 }
6265 else {
6266 TClauses.push_back(0);
6267 }
6268 }
6269 if (!D->getAssociatedStmt())
6270 return StmtError();
6271 StmtResult AssociatedStmt =
6272 getDerived().TransformStmt(D->getAssociatedStmt());
6273 if (AssociatedStmt.isInvalid())
6274 return StmtError();
6275
6276 return getDerived().RebuildOMPParallelDirective(TClauses,
6277 AssociatedStmt.take(),
6278 D->getLocStart(),
6279 D->getLocEnd());
6280}
6281
6282template<typename Derived>
6283OMPClause *
6284TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6285 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6286 C->getDefaultKindKwLoc(),
6287 C->getLocStart(),
6288 C->getLParenLoc(),
6289 C->getLocEnd());
6290}
6291
6292template<typename Derived>
6293OMPClause *
6294TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
6295 llvm::SmallVector<Expr *, 5> Vars;
6296 Vars.reserve(C->varlist_size());
6297 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6298 E = C->varlist_end();
6299 I != E; ++I) {
6300 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6301 if (EVar.isInvalid())
6302 return 0;
6303 Vars.push_back(EVar.take());
6304 }
6305 return getDerived().RebuildOMPPrivateClause(Vars,
6306 C->getLocStart(),
6307 C->getLParenLoc(),
6308 C->getLocEnd());
6309}
6310
Douglas Gregor43959a92009-08-20 07:17:43 +00006311//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312// Expression transformation
6313//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006315ExprResult
John McCall454feb92009-12-08 09:21:05 +00006316TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006317 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318}
Mike Stump1eb44332009-09-09 15:08:12 +00006319
6320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006321ExprResult
John McCall454feb92009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006323 NestedNameSpecifierLoc QualifierLoc;
6324 if (E->getQualifierLoc()) {
6325 QualifierLoc
6326 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6327 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006328 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006329 }
John McCalldbd872f2009-12-08 09:08:17 +00006330
6331 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006332 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6333 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006335 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006336
John McCallec8045d2010-08-17 21:27:17 +00006337 DeclarationNameInfo NameInfo = E->getNameInfo();
6338 if (NameInfo.getName()) {
6339 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6340 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006341 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006342 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006343
6344 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006345 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006346 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006347 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006348 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006349
6350 // Mark it referenced in the new context regardless.
6351 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006352 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006353
John McCall3fa5cae2010-10-26 07:05:15 +00006354 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006355 }
John McCalldbd872f2009-12-08 09:08:17 +00006356
6357 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006358 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006359 TemplateArgs = &TransArgs;
6360 TransArgs.setLAngleLoc(E->getLAngleLoc());
6361 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006362 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6363 E->getNumTemplateArgs(),
6364 TransArgs))
6365 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006366 }
6367
Chad Rosier4a9d7952012-08-08 18:46:20 +00006368 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006369 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370}
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006373ExprResult
John McCall454feb92009-12-08 09:21:05 +00006374TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006375 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376}
Mike Stump1eb44332009-09-09 15:08:12 +00006377
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006379ExprResult
John McCall454feb92009-12-08 09:21:05 +00006380TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006381 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382}
Mike Stump1eb44332009-09-09 15:08:12 +00006383
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006385ExprResult
John McCall454feb92009-12-08 09:21:05 +00006386TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006387 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388}
Mike Stump1eb44332009-09-09 15:08:12 +00006389
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006391ExprResult
John McCall454feb92009-12-08 09:21:05 +00006392TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006393 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394}
Mike Stump1eb44332009-09-09 15:08:12 +00006395
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006397ExprResult
John McCall454feb92009-12-08 09:21:05 +00006398TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006399 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006400}
6401
6402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006403ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006404TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006405 if (FunctionDecl *FD = E->getDirectCallee())
6406 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006407 return SemaRef.MaybeBindToTemporary(E);
6408}
6409
6410template<typename Derived>
6411ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006412TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6413 ExprResult ControllingExpr =
6414 getDerived().TransformExpr(E->getControllingExpr());
6415 if (ControllingExpr.isInvalid())
6416 return ExprError();
6417
Chris Lattner686775d2011-07-20 06:58:45 +00006418 SmallVector<Expr *, 4> AssocExprs;
6419 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006420 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6421 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6422 if (TS) {
6423 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6424 if (!AssocType)
6425 return ExprError();
6426 AssocTypes.push_back(AssocType);
6427 } else {
6428 AssocTypes.push_back(0);
6429 }
6430
6431 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6432 if (AssocExpr.isInvalid())
6433 return ExprError();
6434 AssocExprs.push_back(AssocExpr.release());
6435 }
6436
6437 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6438 E->getDefaultLoc(),
6439 E->getRParenLoc(),
6440 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006441 AssocTypes,
6442 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006443}
6444
6445template<typename Derived>
6446ExprResult
John McCall454feb92009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006448 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006450 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006453 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006454
John McCall9ae2f072010-08-23 23:25:46 +00006455 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 E->getRParen());
6457}
6458
Richard Smithefeeccf2012-10-21 03:28:35 +00006459/// \brief The operand of a unary address-of operator has special rules: it's
6460/// allowed to refer to a non-static member of a class even if there's no 'this'
6461/// object available.
6462template<typename Derived>
6463ExprResult
6464TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6465 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6466 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6467 else
6468 return getDerived().TransformExpr(E);
6469}
6470
Mike Stump1eb44332009-09-09 15:08:12 +00006471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006472ExprResult
John McCall454feb92009-12-08 09:21:05 +00006473TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006474 ExprResult SubExpr;
6475 if (E->getOpcode() == UO_AddrOf)
6476 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6477 else
6478 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006483 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6486 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006487 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488}
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006491ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006492TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6493 // Transform the type.
6494 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6495 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006496 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006497
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006498 // Transform all of the components into components similar to what the
6499 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006500 // FIXME: It would be slightly more efficient in the non-dependent case to
6501 // just map FieldDecls, rather than requiring the rebuilder to look for
6502 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006503 // template code that we don't care.
6504 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006505 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006506 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006507 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006508 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6509 const Node &ON = E->getComponent(I);
6510 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006511 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006512 Comp.LocStart = ON.getSourceRange().getBegin();
6513 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006514 switch (ON.getKind()) {
6515 case Node::Array: {
6516 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006517 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006518 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006519 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006520
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006521 ExprChanged = ExprChanged || Index.get() != FromIndex;
6522 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006523 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006524 break;
6525 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006526
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006527 case Node::Field:
6528 case Node::Identifier:
6529 Comp.isBrackets = false;
6530 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006531 if (!Comp.U.IdentInfo)
6532 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006533
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006534 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006535
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006536 case Node::Base:
6537 // Will be recomputed during the rebuild.
6538 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006539 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006540
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006541 Components.push_back(Comp);
6542 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006543
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006544 // If nothing changed, retain the existing expression.
6545 if (!getDerived().AlwaysRebuild() &&
6546 Type == E->getTypeSourceInfo() &&
6547 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006548 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006549
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006550 // Build a new offsetof expression.
6551 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6552 Components.data(), Components.size(),
6553 E->getRParenLoc());
6554}
6555
6556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006557ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006558TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6559 assert(getDerived().AlreadyTransformed(E->getType()) &&
6560 "opaque value expression requires transformation");
6561 return SemaRef.Owned(E);
6562}
6563
6564template<typename Derived>
6565ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006566TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006567 // Rebuild the syntactic form. The original syntactic form has
6568 // opaque-value expressions in it, so strip those away and rebuild
6569 // the result. This is a really awful way of doing this, but the
6570 // better solution (rebuilding the semantic expressions and
6571 // rebinding OVEs as necessary) doesn't work; we'd need
6572 // TreeTransform to not strip away implicit conversions.
6573 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6574 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006575 if (result.isInvalid()) return ExprError();
6576
6577 // If that gives us a pseudo-object result back, the pseudo-object
6578 // expression must have been an lvalue-to-rvalue conversion which we
6579 // should reapply.
6580 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6581 result = SemaRef.checkPseudoObjectRValue(result.take());
6582
6583 return result;
6584}
6585
6586template<typename Derived>
6587ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006588TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6589 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006591 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006592
John McCalla93c9342009-12-07 02:54:59 +00006593 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006594 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006596
John McCall5ab75172009-11-04 07:28:41 +00006597 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006598 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006600 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6601 E->getKind(),
6602 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 }
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006605 // C++0x [expr.sizeof]p1:
6606 // The operand is either an expression, which is an unevaluated operand
6607 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006608 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6609 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006611 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6612 if (SubExpr.isInvalid())
6613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006615 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6616 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006618 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6619 E->getOperatorLoc(),
6620 E->getKind(),
6621 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622}
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006625ExprResult
John McCall454feb92009-12-08 09:21:05 +00006626TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006627 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006630
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
6635
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 if (!getDerived().AlwaysRebuild() &&
6637 LHS.get() == E->getLHS() &&
6638 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006639 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006640
John McCall9ae2f072010-08-23 23:25:46 +00006641 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006643 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 E->getRBracketLoc());
6645}
Mike Stump1eb44332009-09-09 15:08:12 +00006646
6647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
John McCall454feb92009-12-08 09:21:05 +00006649TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006651 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006653 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654
6655 // Transform arguments.
6656 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006657 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006658 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006659 &ArgChanged))
6660 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 if (!getDerived().AlwaysRebuild() &&
6663 Callee.get() == E->getCallee() &&
6664 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006665 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006668 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006670 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006671 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 E->getRParenLoc());
6673}
Mike Stump1eb44332009-09-09 15:08:12 +00006674
6675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006676ExprResult
John McCall454feb92009-12-08 09:21:05 +00006677TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006678 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregor40d96a62011-02-28 21:54:11 +00006682 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006683 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006684 QualifierLoc
6685 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006686
Douglas Gregor40d96a62011-02-28 21:54:11 +00006687 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006688 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006689 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006690 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Eli Friedmanf595cc42009-12-04 06:40:45 +00006692 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006693 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6694 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006697
John McCall6bb80172010-03-30 21:47:33 +00006698 NamedDecl *FoundDecl = E->getFoundDecl();
6699 if (FoundDecl == E->getMemberDecl()) {
6700 FoundDecl = Member;
6701 } else {
6702 FoundDecl = cast_or_null<NamedDecl>(
6703 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6704 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006705 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006706 }
6707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 if (!getDerived().AlwaysRebuild() &&
6709 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006710 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006711 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006712 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006713 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006714
Anders Carlsson1f240322009-12-22 05:24:09 +00006715 // Mark it referenced in the new context regardless.
6716 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006717 SemaRef.MarkMemberReferenced(E);
6718
John McCall3fa5cae2010-10-26 07:05:15 +00006719 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006720 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721
John McCalld5532b62009-11-23 01:53:49 +00006722 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006723 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006724 TransArgs.setLAngleLoc(E->getLAngleLoc());
6725 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006726 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6727 E->getNumTemplateArgs(),
6728 TransArgs))
6729 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006730 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 // FIXME: Bogus source location for the operator
6733 SourceLocation FakeOperatorLoc
6734 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6735
John McCallc2233c52010-01-15 08:34:02 +00006736 // FIXME: to do this check properly, we will need to preserve the
6737 // first-qualifier-in-scope here, just in case we had a dependent
6738 // base (and therefore couldn't do the check) and a
6739 // nested-name-qualifier (and therefore could do the lookup).
6740 NamedDecl *FirstQualifierInScope = 0;
6741
John McCall9ae2f072010-08-23 23:25:46 +00006742 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006744 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006745 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006746 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006747 Member,
John McCall6bb80172010-03-30 21:47:33 +00006748 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006749 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006750 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006751 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752}
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006755ExprResult
John McCall454feb92009-12-08 09:21:05 +00006756TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006757 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006760
John McCall60d7b3a2010-08-24 06:29:42 +00006761 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 if (!getDerived().AlwaysRebuild() &&
6766 LHS.get() == E->getLHS() &&
6767 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006768 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Lang Hamesbe9af122012-10-02 04:45:10 +00006770 Sema::FPContractStateRAII FPContractState(getSema());
6771 getSema().FPFeatures.fp_contract = E->isFPContractable();
6772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006774 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775}
6776
Mike Stump1eb44332009-09-09 15:08:12 +00006777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006778ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006780 CompoundAssignOperator *E) {
6781 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006785ExprResult TreeTransform<Derived>::
6786TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6787 // Just rebuild the common and RHS expressions and see whether we
6788 // get any changes.
6789
6790 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6791 if (commonExpr.isInvalid())
6792 return ExprError();
6793
6794 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6795 if (rhs.isInvalid())
6796 return ExprError();
6797
6798 if (!getDerived().AlwaysRebuild() &&
6799 commonExpr.get() == e->getCommon() &&
6800 rhs.get() == e->getFalseExpr())
6801 return SemaRef.Owned(e);
6802
6803 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6804 e->getQuestionLoc(),
6805 0,
6806 e->getColonLoc(),
6807 rhs.get());
6808}
6809
6810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006811ExprResult
John McCall454feb92009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006813 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006815 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006816
John McCall60d7b3a2010-08-24 06:29:42 +00006817 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006820
John McCall60d7b3a2010-08-24 06:29:42 +00006821 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 if (!getDerived().AlwaysRebuild() &&
6826 Cond.get() == E->getCond() &&
6827 LHS.get() == E->getLHS() &&
6828 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006829 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006830
John McCall9ae2f072010-08-23 23:25:46 +00006831 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006832 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006833 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006834 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006835 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836}
Mike Stump1eb44332009-09-09 15:08:12 +00006837
6838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006839ExprResult
John McCall454feb92009-12-08 09:21:05 +00006840TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006841 // Implicit casts are eliminated during transformation, since they
6842 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006843 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844}
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006847ExprResult
John McCall454feb92009-12-08 09:21:05 +00006848TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006849 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6850 if (!Type)
6851 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006852
John McCall60d7b3a2010-08-24 06:29:42 +00006853 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006854 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006857
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006859 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006861 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006862
John McCall9d125032010-01-15 18:39:57 +00006863 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006864 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006866 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867}
Mike Stump1eb44332009-09-09 15:08:12 +00006868
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006870ExprResult
John McCall454feb92009-12-08 09:21:05 +00006871TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006872 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6873 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6874 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006876
John McCall60d7b3a2010-08-24 06:29:42 +00006877 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006882 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006884 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885
John McCall1d7d8d62010-01-19 22:33:45 +00006886 // Note: the expression type doesn't necessarily match the
6887 // type-as-written, but that's okay, because it should always be
6888 // derivable from the initializer.
6889
John McCall42f56b52010-01-18 19:35:47 +00006890 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006892 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893}
Mike Stump1eb44332009-09-09 15:08:12 +00006894
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006896ExprResult
John McCall454feb92009-12-08 09:21:05 +00006897TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006898 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006900 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006901
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 if (!getDerived().AlwaysRebuild() &&
6903 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006907 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006909 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 E->getAccessorLoc(),
6911 E->getAccessor());
6912}
Mike Stump1eb44332009-09-09 15:08:12 +00006913
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006915ExprResult
John McCall454feb92009-12-08 09:21:05 +00006916TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006919 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006920 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006921 Inits, &InitChanged))
6922 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006923
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006925 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006926
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006927 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006928 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929}
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006932ExprResult
John McCall454feb92009-12-08 09:21:05 +00006933TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregor43959a92009-08-20 07:17:43 +00006936 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006937 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregor43959a92009-08-20 07:17:43 +00006941 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006942 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 bool ExprChanged = false;
6944 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6945 DEnd = E->designators_end();
6946 D != DEnd; ++D) {
6947 if (D->isFieldDesignator()) {
6948 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6949 D->getDotLoc(),
6950 D->getFieldLoc()));
6951 continue;
6952 }
Mike Stump1eb44332009-09-09 15:08:12 +00006953
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006955 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006958
6959 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6963 ArrayExprs.push_back(Index.release());
6964 continue;
6965 }
Mike Stump1eb44332009-09-09 15:08:12 +00006966
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006968 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6970 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006972
John McCall60d7b3a2010-08-24 06:29:42 +00006973 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
6977 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 End.get(),
6979 D->getLBracketLoc(),
6980 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006981
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6983 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 ArrayExprs.push_back(Start.release());
6986 ArrayExprs.push_back(End.release());
6987 }
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 if (!getDerived().AlwaysRebuild() &&
6990 Init.get() == E->getInit() &&
6991 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006992 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006994 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006996 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997}
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007000ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007002 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007003 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007004
Douglas Gregor5557b252009-10-28 00:29:27 +00007005 // FIXME: Will we ever have proper type location here? Will we actually
7006 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007 QualType T = getDerived().TransformType(E->getType());
7008 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 if (!getDerived().AlwaysRebuild() &&
7012 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007013 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 return getDerived().RebuildImplicitValueInitExpr(T);
7016}
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007019ExprResult
John McCall454feb92009-12-08 09:21:05 +00007020TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007021 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7022 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007024
John McCall60d7b3a2010-08-24 06:29:42 +00007025 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007030 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007032 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007033
John McCall9ae2f072010-08-23 23:25:46 +00007034 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007035 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036}
7037
7038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007039ExprResult
John McCall454feb92009-12-08 09:21:05 +00007040TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007042 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007043 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7044 &ArgumentChanged))
7045 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007046
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007048 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 E->getRParenLoc());
7050}
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052/// \brief Transform an address-of-label expression.
7053///
7054/// By default, the transformation of an address-of-label expression always
7055/// rebuilds the expression, so that the label identifier can be resolved to
7056/// the corresponding label statement by semantic analysis.
7057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007058ExprResult
John McCall454feb92009-12-08 09:21:05 +00007059TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007060 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7061 E->getLabel());
7062 if (!LD)
7063 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007066 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067}
Mike Stump1eb44332009-09-09 15:08:12 +00007068
7069template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007070ExprResult
John McCall454feb92009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007072 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007073 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007075 if (SubStmt.isInvalid()) {
7076 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007078 }
Mike Stump1eb44332009-09-09 15:08:12 +00007079
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007081 SubStmt.get() == E->getSubStmt()) {
7082 // Calling this an 'error' is unintuitive, but it does the right thing.
7083 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007084 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007085 }
Mike Stump1eb44332009-09-09 15:08:12 +00007086
7087 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007088 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 E->getRParenLoc());
7090}
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007093ExprResult
John McCall454feb92009-12-08 09:21:05 +00007094TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007095 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007098
John McCall60d7b3a2010-08-24 06:29:42 +00007099 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007102
John McCall60d7b3a2010-08-24 06:29:42 +00007103 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007106
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 if (!getDerived().AlwaysRebuild() &&
7108 Cond.get() == E->getCond() &&
7109 LHS.get() == E->getLHS() &&
7110 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007111 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007114 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 E->getRParenLoc());
7116}
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007119ExprResult
John McCall454feb92009-12-08 09:21:05 +00007120TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007121 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122}
7123
7124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007125ExprResult
John McCall454feb92009-12-08 09:21:05 +00007126TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007127 switch (E->getOperator()) {
7128 case OO_New:
7129 case OO_Delete:
7130 case OO_Array_New:
7131 case OO_Array_Delete:
7132 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007133
Douglas Gregor668d6d92009-12-13 20:44:55 +00007134 case OO_Call: {
7135 // This is a call to an object's operator().
7136 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7137
7138 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007139 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007140 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007141 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007142
7143 // FIXME: Poor location information
7144 SourceLocation FakeLParenLoc
7145 = SemaRef.PP.getLocForEndOfToken(
7146 static_cast<Expr *>(Object.get())->getLocEnd());
7147
7148 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007149 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007150 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007151 Args))
7152 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007153
John McCall9ae2f072010-08-23 23:25:46 +00007154 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007155 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007156 E->getLocEnd());
7157 }
7158
7159#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7160 case OO_##Name:
7161#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7162#include "clang/Basic/OperatorKinds.def"
7163 case OO_Subscript:
7164 // Handled below.
7165 break;
7166
7167 case OO_Conditional:
7168 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007169
7170 case OO_None:
7171 case NUM_OVERLOADED_OPERATORS:
7172 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007173 }
7174
John McCall60d7b3a2010-08-24 06:29:42 +00007175 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Richard Smithefeeccf2012-10-21 03:28:35 +00007179 ExprResult First;
7180 if (E->getOperator() == OO_Amp)
7181 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7182 else
7183 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007185 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186
John McCall60d7b3a2010-08-24 06:29:42 +00007187 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 if (E->getNumArgs() == 2) {
7189 Second = getDerived().TransformExpr(E->getArg(1));
7190 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007191 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 }
Mike Stump1eb44332009-09-09 15:08:12 +00007193
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (!getDerived().AlwaysRebuild() &&
7195 Callee.get() == E->getCallee() &&
7196 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007197 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007198 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Lang Hamesbe9af122012-10-02 04:45:10 +00007200 Sema::FPContractStateRAII FPContractState(getSema());
7201 getSema().FPFeatures.fp_contract = E->isFPContractable();
7202
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7204 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007205 Callee.get(),
7206 First.get(),
7207 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208}
Mike Stump1eb44332009-09-09 15:08:12 +00007209
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007211ExprResult
John McCall454feb92009-12-08 09:21:05 +00007212TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7213 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214}
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007217ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007218TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7219 // Transform the callee.
7220 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7221 if (Callee.isInvalid())
7222 return ExprError();
7223
7224 // Transform exec config.
7225 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7226 if (EC.isInvalid())
7227 return ExprError();
7228
7229 // Transform arguments.
7230 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007231 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007232 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007233 &ArgChanged))
7234 return ExprError();
7235
7236 if (!getDerived().AlwaysRebuild() &&
7237 Callee.get() == E->getCallee() &&
7238 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007239 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007240
7241 // FIXME: Wrong source location information for the '('.
7242 SourceLocation FakeLParenLoc
7243 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7244 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007245 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007246 E->getRParenLoc(), EC.get());
7247}
7248
7249template<typename Derived>
7250ExprResult
John McCall454feb92009-12-08 09:21:05 +00007251TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007252 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7253 if (!Type)
7254 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007255
John McCall60d7b3a2010-08-24 06:29:42 +00007256 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007257 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007262 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007264 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007266 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007267 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007268 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007269 E->getAngleBrackets().getEnd(),
7270 // FIXME. this should be '(' location
7271 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007272 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007273 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274}
Mike Stump1eb44332009-09-09 15:08:12 +00007275
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007277ExprResult
John McCall454feb92009-12-08 09:21:05 +00007278TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7279 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280}
Mike Stump1eb44332009-09-09 15:08:12 +00007281
7282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007283ExprResult
John McCall454feb92009-12-08 09:21:05 +00007284TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7285 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007286}
7287
Douglas Gregorb98b1992009-08-11 05:31:07 +00007288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007289ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007291 CXXReinterpretCastExpr *E) {
7292 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293}
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007296ExprResult
John McCall454feb92009-12-08 09:21:05 +00007297TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7298 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299}
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007302ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007304 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007305 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7306 if (!Type)
7307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007308
John McCall60d7b3a2010-08-24 06:29:42 +00007309 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007310 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007312 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007315 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007317 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007319 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007321 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322 E->getRParenLoc());
7323}
Mike Stump1eb44332009-09-09 15:08:12 +00007324
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007326ExprResult
John McCall454feb92009-12-08 09:21:05 +00007327TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007329 TypeSourceInfo *TInfo
7330 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7331 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007332 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007333
Douglas Gregorb98b1992009-08-11 05:31:07 +00007334 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007335 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007336 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007338 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7339 E->getLocStart(),
7340 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341 E->getLocEnd());
7342 }
Mike Stump1eb44332009-09-09 15:08:12 +00007343
Eli Friedmanef331b72012-01-20 01:26:23 +00007344 // We don't know whether the subexpression is potentially evaluated until
7345 // after we perform semantic analysis. We speculatively assume it is
7346 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7349 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007350
John McCall60d7b3a2010-08-24 06:29:42 +00007351 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007352 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 if (!getDerived().AlwaysRebuild() &&
7356 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007357 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007359 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7360 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007361 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 E->getLocEnd());
7363}
7364
7365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007366ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007367TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7368 if (E->isTypeOperand()) {
7369 TypeSourceInfo *TInfo
7370 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7371 if (!TInfo)
7372 return ExprError();
7373
7374 if (!getDerived().AlwaysRebuild() &&
7375 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007376 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007377
Douglas Gregor3c52a212011-03-06 17:40:41 +00007378 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007379 E->getLocStart(),
7380 TInfo,
7381 E->getLocEnd());
7382 }
7383
Francois Pichet01b7c302010-09-08 12:20:18 +00007384 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7385
7386 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7387 if (SubExpr.isInvalid())
7388 return ExprError();
7389
7390 if (!getDerived().AlwaysRebuild() &&
7391 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007392 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007393
7394 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7395 E->getLocStart(),
7396 SubExpr.get(),
7397 E->getLocEnd());
7398}
7399
7400template<typename Derived>
7401ExprResult
John McCall454feb92009-12-08 09:21:05 +00007402TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007403 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404}
Mike Stump1eb44332009-09-09 15:08:12 +00007405
Douglas Gregorb98b1992009-08-11 05:31:07 +00007406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007407ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007408TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007409 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007410 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411}
Mike Stump1eb44332009-09-09 15:08:12 +00007412
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007414ExprResult
John McCall454feb92009-12-08 09:21:05 +00007415TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007416 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007417
Douglas Gregorec79d872012-02-24 17:41:38 +00007418 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7419 // Make sure that we capture 'this'.
7420 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007421 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007422 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007423
Douglas Gregor828a1972010-01-07 23:12:05 +00007424 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425}
Mike Stump1eb44332009-09-09 15:08:12 +00007426
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007428ExprResult
John McCall454feb92009-12-08 09:21:05 +00007429TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007430 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007433
Douglas Gregorb98b1992009-08-11 05:31:07 +00007434 if (!getDerived().AlwaysRebuild() &&
7435 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007436 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437
Douglas Gregorbca01b42011-07-06 22:04:06 +00007438 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7439 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007440}
Mike Stump1eb44332009-09-09 15:08:12 +00007441
Douglas Gregorb98b1992009-08-11 05:31:07 +00007442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007443ExprResult
John McCall454feb92009-12-08 09:21:05 +00007444TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007445 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007446 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7447 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007448 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007449 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007450
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007451 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007452 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007453 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007454
Douglas Gregor036aed12009-12-23 23:03:06 +00007455 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456}
Mike Stump1eb44332009-09-09 15:08:12 +00007457
Douglas Gregorb98b1992009-08-11 05:31:07 +00007458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007459ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007460TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7461 FieldDecl *Field
7462 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7463 E->getField()));
7464 if (!Field)
7465 return ExprError();
7466
7467 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7468 return SemaRef.Owned(E);
7469
7470 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7471}
7472
7473template<typename Derived>
7474ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007475TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7476 CXXScalarValueInitExpr *E) {
7477 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7478 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007479 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007480
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007482 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007483 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007484
Chad Rosier4a9d7952012-08-08 18:46:20 +00007485 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007486 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007487 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488}
Mike Stump1eb44332009-09-09 15:08:12 +00007489
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007491ExprResult
John McCall454feb92009-12-08 09:21:05 +00007492TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007493 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007494 TypeSourceInfo *AllocTypeInfo
7495 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7496 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007498
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007500 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007501 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504 // Transform the placement arguments (if any).
7505 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007506 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007507 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007508 E->getNumPlacementArgs(), true,
7509 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007510 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007511
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007512 // Transform the initializer (if any).
7513 Expr *OldInit = E->getInitializer();
7514 ExprResult NewInit;
7515 if (OldInit)
7516 NewInit = getDerived().TransformExpr(OldInit);
7517 if (NewInit.isInvalid())
7518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007519
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007520 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007521 FunctionDecl *OperatorNew = 0;
7522 if (E->getOperatorNew()) {
7523 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007524 getDerived().TransformDecl(E->getLocStart(),
7525 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007526 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007527 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007528 }
7529
7530 FunctionDecl *OperatorDelete = 0;
7531 if (E->getOperatorDelete()) {
7532 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007533 getDerived().TransformDecl(E->getLocStart(),
7534 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007535 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007536 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007537 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007538
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007540 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007541 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007542 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007543 OperatorNew == E->getOperatorNew() &&
7544 OperatorDelete == E->getOperatorDelete() &&
7545 !ArgumentChanged) {
7546 // Mark any declarations we need as referenced.
7547 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007548 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007549 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007550 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007551 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007552
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007553 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007554 QualType ElementType
7555 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7556 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7557 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7558 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007559 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007560 }
7561 }
7562 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007563
John McCall3fa5cae2010-10-26 07:05:15 +00007564 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007565 }
Mike Stump1eb44332009-09-09 15:08:12 +00007566
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007567 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007568 if (!ArraySize.get()) {
7569 // If no array size was specified, but the new expression was
7570 // instantiated with an array type (e.g., "new T" where T is
7571 // instantiated with "int[4]"), extract the outer bound from the
7572 // array type as our array size. We do this with constant and
7573 // dependently-sized array types.
7574 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7575 if (!ArrayT) {
7576 // Do nothing
7577 } else if (const ConstantArrayType *ConsArrayT
7578 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007579 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007580 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007581 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007582 SemaRef.Context.getSizeType(),
7583 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007584 AllocType = ConsArrayT->getElementType();
7585 } else if (const DependentSizedArrayType *DepArrayT
7586 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7587 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007588 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007589 AllocType = DepArrayT->getElementType();
7590 }
7591 }
7592 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007593
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7595 E->isGlobalNew(),
7596 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007597 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007599 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007601 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007602 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007603 E->getDirectInitRange(),
7604 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605}
Mike Stump1eb44332009-09-09 15:08:12 +00007606
Douglas Gregorb98b1992009-08-11 05:31:07 +00007607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007608ExprResult
John McCall454feb92009-12-08 09:21:05 +00007609TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007610 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007611 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007613
Douglas Gregor1af74512010-02-26 00:38:10 +00007614 // Transform the delete operator, if known.
7615 FunctionDecl *OperatorDelete = 0;
7616 if (E->getOperatorDelete()) {
7617 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007618 getDerived().TransformDecl(E->getLocStart(),
7619 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007620 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007621 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007622 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623
Douglas Gregorb98b1992009-08-11 05:31:07 +00007624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007625 Operand.get() == E->getArgument() &&
7626 OperatorDelete == E->getOperatorDelete()) {
7627 // Mark any declarations we need as referenced.
7628 // FIXME: instantiation-specific.
7629 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007630 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007632 if (!E->getArgument()->isTypeDependent()) {
7633 QualType Destroyed = SemaRef.Context.getBaseElementType(
7634 E->getDestroyedType());
7635 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7636 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007637 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007638 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007639 }
7640 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007641
John McCall3fa5cae2010-10-26 07:05:15 +00007642 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007643 }
Mike Stump1eb44332009-09-09 15:08:12 +00007644
Douglas Gregorb98b1992009-08-11 05:31:07 +00007645 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7646 E->isGlobalDelete(),
7647 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007648 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649}
Mike Stump1eb44332009-09-09 15:08:12 +00007650
Douglas Gregorb98b1992009-08-11 05:31:07 +00007651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007652ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007653TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007654 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007656 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007658
John McCallb3d87482010-08-24 05:47:05 +00007659 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007660 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007661 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007662 E->getOperatorLoc(),
7663 E->isArrow()? tok::arrow : tok::period,
7664 ObjectTypePtr,
7665 MayBePseudoDestructor);
7666 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007667 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007668
John McCallb3d87482010-08-24 05:47:05 +00007669 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007670 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7671 if (QualifierLoc) {
7672 QualifierLoc
7673 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7674 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007675 return ExprError();
7676 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007677 CXXScopeSpec SS;
7678 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007679
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007680 PseudoDestructorTypeStorage Destroyed;
7681 if (E->getDestroyedTypeInfo()) {
7682 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007683 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007684 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007685 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007686 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007687 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007688 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007689 // We aren't likely to be able to resolve the identifier down to a type
7690 // now anyway, so just retain the identifier.
7691 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7692 E->getDestroyedTypeLoc());
7693 } else {
7694 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007695 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007696 *E->getDestroyedTypeIdentifier(),
7697 E->getDestroyedTypeLoc(),
7698 /*Scope=*/0,
7699 SS, ObjectTypePtr,
7700 false);
7701 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007702 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007703
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007704 Destroyed
7705 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7706 E->getDestroyedTypeLoc());
7707 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007708
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007709 TypeSourceInfo *ScopeTypeInfo = 0;
7710 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007711 CXXScopeSpec EmptySS;
7712 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7713 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007714 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007715 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007717
John McCall9ae2f072010-08-23 23:25:46 +00007718 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007719 E->getOperatorLoc(),
7720 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007721 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007722 ScopeTypeInfo,
7723 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007724 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007725 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007726}
Mike Stump1eb44332009-09-09 15:08:12 +00007727
Douglas Gregora71d8192009-09-04 17:36:40 +00007728template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007729ExprResult
John McCallba135432009-11-21 08:51:07 +00007730TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007731 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007732 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7733 Sema::LookupOrdinaryName);
7734
7735 // Transform all the decls.
7736 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7737 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007738 NamedDecl *InstD = static_cast<NamedDecl*>(
7739 getDerived().TransformDecl(Old->getNameLoc(),
7740 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007741 if (!InstD) {
7742 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7743 // This can happen because of dependent hiding.
7744 if (isa<UsingShadowDecl>(*I))
7745 continue;
7746 else
John McCallf312b1e2010-08-26 23:41:50 +00007747 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007748 }
John McCallf7a1a742009-11-24 19:00:30 +00007749
7750 // Expand using declarations.
7751 if (isa<UsingDecl>(InstD)) {
7752 UsingDecl *UD = cast<UsingDecl>(InstD);
7753 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7754 E = UD->shadow_end(); I != E; ++I)
7755 R.addDecl(*I);
7756 continue;
7757 }
7758
7759 R.addDecl(InstD);
7760 }
7761
7762 // Resolve a kind, but don't do any further analysis. If it's
7763 // ambiguous, the callee needs to deal with it.
7764 R.resolveKind();
7765
7766 // Rebuild the nested-name qualifier, if present.
7767 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007768 if (Old->getQualifierLoc()) {
7769 NestedNameSpecifierLoc QualifierLoc
7770 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7771 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007772 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007773
Douglas Gregor4c9be892011-02-28 20:01:57 +00007774 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007775 }
7776
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007777 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007778 CXXRecordDecl *NamingClass
7779 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7780 Old->getNameLoc(),
7781 Old->getNamingClass()));
7782 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007783 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007784
Douglas Gregor66c45152010-04-27 16:10:10 +00007785 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007786 }
7787
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007788 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7789
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007790 // If we have neither explicit template arguments, nor the template keyword,
7791 // it's a normal declaration name.
7792 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007793 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7794
7795 // If we have template arguments, rebuild them, then rebuild the
7796 // templateid expression.
7797 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007798 if (Old->hasExplicitTemplateArgs() &&
7799 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007800 Old->getNumTemplateArgs(),
7801 TransArgs))
7802 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007803
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007804 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007805 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806}
Mike Stump1eb44332009-09-09 15:08:12 +00007807
Douglas Gregorb98b1992009-08-11 05:31:07 +00007808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007809ExprResult
John McCall454feb92009-12-08 09:21:05 +00007810TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007811 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7812 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007814
Douglas Gregorb98b1992009-08-11 05:31:07 +00007815 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007816 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007817 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Mike Stump1eb44332009-09-09 15:08:12 +00007819 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821 T,
7822 E->getLocEnd());
7823}
Mike Stump1eb44332009-09-09 15:08:12 +00007824
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007826ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007827TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7828 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7829 if (!LhsT)
7830 return ExprError();
7831
7832 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7833 if (!RhsT)
7834 return ExprError();
7835
7836 if (!getDerived().AlwaysRebuild() &&
7837 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7838 return SemaRef.Owned(E);
7839
7840 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7841 E->getLocStart(),
7842 LhsT, RhsT,
7843 E->getLocEnd());
7844}
7845
7846template<typename Derived>
7847ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007848TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7849 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007850 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007851 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7852 TypeSourceInfo *From = E->getArg(I);
7853 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007854 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007855 TypeLocBuilder TLB;
7856 TLB.reserve(FromTL.getFullDataSize());
7857 QualType To = getDerived().TransformType(TLB, FromTL);
7858 if (To.isNull())
7859 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007860
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007861 if (To == From->getType())
7862 Args.push_back(From);
7863 else {
7864 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7865 ArgChanged = true;
7866 }
7867 continue;
7868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007869
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007870 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007871
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007872 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007873 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007874 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7875 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7876 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007877
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007878 // Determine whether the set of unexpanded parameter packs can and should
7879 // be expanded.
7880 bool Expand = true;
7881 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007882 Optional<unsigned> OrigNumExpansions =
7883 ExpansionTL.getTypePtr()->getNumExpansions();
7884 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007885 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7886 PatternTL.getSourceRange(),
7887 Unexpanded,
7888 Expand, RetainExpansion,
7889 NumExpansions))
7890 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007891
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007892 if (!Expand) {
7893 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007894 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007895 // expansion.
7896 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007897
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007898 TypeLocBuilder TLB;
7899 TLB.reserve(From->getTypeLoc().getFullDataSize());
7900
7901 QualType To = getDerived().TransformType(TLB, PatternTL);
7902 if (To.isNull())
7903 return ExprError();
7904
Chad Rosier4a9d7952012-08-08 18:46:20 +00007905 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007906 PatternTL.getSourceRange(),
7907 ExpansionTL.getEllipsisLoc(),
7908 NumExpansions);
7909 if (To.isNull())
7910 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007911
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007912 PackExpansionTypeLoc ToExpansionTL
7913 = TLB.push<PackExpansionTypeLoc>(To);
7914 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7915 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7916 continue;
7917 }
7918
7919 // Expand the pack expansion by substituting for each argument in the
7920 // pack(s).
7921 for (unsigned I = 0; I != *NumExpansions; ++I) {
7922 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7923 TypeLocBuilder TLB;
7924 TLB.reserve(PatternTL.getFullDataSize());
7925 QualType To = getDerived().TransformType(TLB, PatternTL);
7926 if (To.isNull())
7927 return ExprError();
7928
Eli Friedman20cfeca2013-07-19 21:49:32 +00007929 if (To->containsUnexpandedParameterPack()) {
7930 To = getDerived().RebuildPackExpansionType(To,
7931 PatternTL.getSourceRange(),
7932 ExpansionTL.getEllipsisLoc(),
7933 NumExpansions);
7934 if (To.isNull())
7935 return ExprError();
7936
7937 PackExpansionTypeLoc ToExpansionTL
7938 = TLB.push<PackExpansionTypeLoc>(To);
7939 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7940 }
7941
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007942 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7943 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007944
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007945 if (!RetainExpansion)
7946 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007947
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007948 // If we're supposed to retain a pack expansion, do so by temporarily
7949 // forgetting the partially-substituted parameter pack.
7950 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7951
7952 TypeLocBuilder TLB;
7953 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007955 QualType To = getDerived().TransformType(TLB, PatternTL);
7956 if (To.isNull())
7957 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007958
7959 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007960 PatternTL.getSourceRange(),
7961 ExpansionTL.getEllipsisLoc(),
7962 NumExpansions);
7963 if (To.isNull())
7964 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007965
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007966 PackExpansionTypeLoc ToExpansionTL
7967 = TLB.push<PackExpansionTypeLoc>(To);
7968 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7969 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7970 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007971
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007972 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7973 return SemaRef.Owned(E);
7974
7975 return getDerived().RebuildTypeTrait(E->getTrait(),
7976 E->getLocStart(),
7977 Args,
7978 E->getLocEnd());
7979}
7980
7981template<typename Derived>
7982ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007983TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7984 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7985 if (!T)
7986 return ExprError();
7987
7988 if (!getDerived().AlwaysRebuild() &&
7989 T == E->getQueriedTypeSourceInfo())
7990 return SemaRef.Owned(E);
7991
7992 ExprResult SubExpr;
7993 {
7994 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7995 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7996 if (SubExpr.isInvalid())
7997 return ExprError();
7998
7999 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8000 return SemaRef.Owned(E);
8001 }
8002
8003 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8004 E->getLocStart(),
8005 T,
8006 SubExpr.get(),
8007 E->getLocEnd());
8008}
8009
8010template<typename Derived>
8011ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008012TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8013 ExprResult SubExpr;
8014 {
8015 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8016 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8017 if (SubExpr.isInvalid())
8018 return ExprError();
8019
8020 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8021 return SemaRef.Owned(E);
8022 }
8023
8024 return getDerived().RebuildExpressionTrait(
8025 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8026}
8027
8028template<typename Derived>
8029ExprResult
John McCall865d4472009-11-19 22:55:06 +00008030TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008031 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008032 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8033}
8034
8035template<typename Derived>
8036ExprResult
8037TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8038 DependentScopeDeclRefExpr *E,
8039 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008040 NestedNameSpecifierLoc QualifierLoc
8041 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8042 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008043 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008044 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008045
John McCall43fed0d2010-11-12 08:19:04 +00008046 // TODO: If this is a conversion-function-id, verify that the
8047 // destination type name (if present) resolves the same way after
8048 // instantiation as it did in the local scope.
8049
Abramo Bagnara25777432010-08-11 22:01:17 +00008050 DeclarationNameInfo NameInfo
8051 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8052 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008054
John McCallf7a1a742009-11-24 19:00:30 +00008055 if (!E->hasExplicitTemplateArgs()) {
8056 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008057 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008058 // Note: it is sufficient to compare the Name component of NameInfo:
8059 // if name has not changed, DNLoc has not changed either.
8060 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008061 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008062
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008063 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008064 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008065 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008066 /*TemplateArgs*/ 0,
8067 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008068 }
John McCalld5532b62009-11-23 01:53:49 +00008069
8070 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008071 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8072 E->getNumTemplateArgs(),
8073 TransArgs))
8074 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008075
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008076 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008077 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008078 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008079 &TransArgs,
8080 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008081}
8082
8083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008084ExprResult
John McCall454feb92009-12-08 09:21:05 +00008085TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008086 // CXXConstructExprs other than for list-initialization and
8087 // CXXTemporaryObjectExpr are always implicit, so when we have
8088 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008089 if ((E->getNumArgs() == 1 ||
8090 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008091 (!getDerived().DropCallArgument(E->getArg(0))) &&
8092 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008093 return getDerived().TransformExpr(E->getArg(0));
8094
Douglas Gregorb98b1992009-08-11 05:31:07 +00008095 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8096
8097 QualType T = getDerived().TransformType(E->getType());
8098 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008099 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100
8101 CXXConstructorDecl *Constructor
8102 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008103 getDerived().TransformDecl(E->getLocStart(),
8104 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008107
Douglas Gregorb98b1992009-08-11 05:31:07 +00008108 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008109 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008110 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008111 &ArgumentChanged))
8112 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008113
Douglas Gregorb98b1992009-08-11 05:31:07 +00008114 if (!getDerived().AlwaysRebuild() &&
8115 T == E->getType() &&
8116 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008117 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008118 // Mark the constructor as referenced.
8119 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008120 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008121 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008122 }
Mike Stump1eb44332009-09-09 15:08:12 +00008123
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008124 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8125 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008126 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008127 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008128 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008129 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008130 E->getConstructionKind(),
8131 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008132}
Mike Stump1eb44332009-09-09 15:08:12 +00008133
Douglas Gregorb98b1992009-08-11 05:31:07 +00008134/// \brief Transform a C++ temporary-binding expression.
8135///
Douglas Gregor51326552009-12-24 18:51:59 +00008136/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8137/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008139ExprResult
John McCall454feb92009-12-08 09:21:05 +00008140TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008141 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008142}
Mike Stump1eb44332009-09-09 15:08:12 +00008143
John McCall4765fa02010-12-06 08:20:24 +00008144/// \brief Transform a C++ expression that contains cleanups that should
8145/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008146///
John McCall4765fa02010-12-06 08:20:24 +00008147/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008148/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008150ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008151TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008152 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008153}
Mike Stump1eb44332009-09-09 15:08:12 +00008154
Douglas Gregorb98b1992009-08-11 05:31:07 +00008155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008156ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008157TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008158 CXXTemporaryObjectExpr *E) {
8159 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8160 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008162
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163 CXXConstructorDecl *Constructor
8164 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008165 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008166 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008167 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008169
Douglas Gregorb98b1992009-08-11 05:31:07 +00008170 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008171 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008173 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008174 &ArgumentChanged))
8175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008176
Douglas Gregorb98b1992009-08-11 05:31:07 +00008177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008178 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008179 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008180 !ArgumentChanged) {
8181 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008182 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008183 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008184 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008185
Richard Smithc83c2302012-12-19 01:39:02 +00008186 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008187 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8188 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008189 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190 E->getLocEnd());
8191}
Mike Stump1eb44332009-09-09 15:08:12 +00008192
Douglas Gregorb98b1992009-08-11 05:31:07 +00008193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008194ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008195TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008196 // Transform the type of the lambda parameters and start the definition of
8197 // the lambda itself.
8198 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008199 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008200 if (!MethodTy)
8201 return ExprError();
8202
Eli Friedman8da8a662012-09-19 01:18:11 +00008203 // Create the local class that will describe the lambda.
8204 CXXRecordDecl *Class
8205 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8206 MethodTy,
8207 /*KnownDependent=*/false);
8208 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8209
Douglas Gregorc6889e72012-02-14 22:28:59 +00008210 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008211 SmallVector<QualType, 4> ParamTypes;
8212 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008213 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8214 E->getCallOperator()->param_begin(),
8215 E->getCallOperator()->param_size(),
8216 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008217 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008218
Douglas Gregordfca6f52012-02-13 22:00:16 +00008219 // Build the call operator.
8220 CXXMethodDecl *CallOperator
8221 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008222 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008223 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008224 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008225 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008226
Richard Smith612409e2012-07-25 03:56:55 +00008227 return getDerived().TransformLambdaScope(E, CallOperator);
8228}
8229
8230template<typename Derived>
8231ExprResult
8232TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8233 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008234 bool Invalid = false;
8235
8236 // Transform any init-capture expressions before entering the scope of the
8237 // lambda.
8238 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8239 InitCaptureExprs.resize(E->explicit_capture_end() -
8240 E->explicit_capture_begin());
8241 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8242 CEnd = E->capture_end();
8243 C != CEnd; ++C) {
8244 if (!C->isInitCapture())
8245 continue;
8246 InitCaptureExprs[C - E->capture_begin()] =
8247 getDerived().TransformExpr(E->getInitCaptureInit(C));
8248 }
8249
Douglas Gregord5387e82012-02-14 00:00:48 +00008250 // Introduce the context of the call operator.
8251 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8252
Douglas Gregordfca6f52012-02-13 22:00:16 +00008253 // Enter the scope of the lambda.
8254 sema::LambdaScopeInfo *LSI
8255 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8256 E->getCaptureDefault(),
8257 E->hasExplicitParameters(),
8258 E->hasExplicitResultType(),
8259 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008260
Douglas Gregordfca6f52012-02-13 22:00:16 +00008261 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008262 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008263 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008264 CEnd = E->capture_end();
8265 C != CEnd; ++C) {
8266 // When we hit the first implicit capture, tell Sema that we've finished
8267 // the list of explicit captures.
8268 if (!FinishedExplicitCaptures && C->isImplicit()) {
8269 getSema().finishLambdaExplicitCaptures(LSI);
8270 FinishedExplicitCaptures = true;
8271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008272
Douglas Gregordfca6f52012-02-13 22:00:16 +00008273 // Capturing 'this' is trivial.
8274 if (C->capturesThis()) {
8275 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8276 continue;
8277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008278
Richard Smith0d8e9642013-05-16 06:20:58 +00008279 // Rebuild init-captures, including the implied field declaration.
8280 if (C->isInitCapture()) {
8281 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8282 if (Init.isInvalid()) {
8283 Invalid = true;
8284 continue;
8285 }
8286 FieldDecl *OldFD = C->getInitCaptureField();
8287 FieldDecl *NewFD = getSema().checkInitCapture(
8288 C->getLocation(), OldFD->getType()->isReferenceType(),
8289 OldFD->getIdentifier(), Init.take());
8290 if (!NewFD)
8291 Invalid = true;
8292 else
8293 getDerived().transformedLocalDecl(OldFD, NewFD);
8294 continue;
8295 }
8296
8297 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8298
Douglas Gregora7365242012-02-14 19:27:52 +00008299 // Determine the capture kind for Sema.
8300 Sema::TryCaptureKind Kind
8301 = C->isImplicit()? Sema::TryCapture_Implicit
8302 : C->getCaptureKind() == LCK_ByCopy
8303 ? Sema::TryCapture_ExplicitByVal
8304 : Sema::TryCapture_ExplicitByRef;
8305 SourceLocation EllipsisLoc;
8306 if (C->isPackExpansion()) {
8307 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8308 bool ShouldExpand = false;
8309 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008310 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008311 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8312 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008313 Unexpanded,
8314 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008315 NumExpansions)) {
8316 Invalid = true;
8317 continue;
8318 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008319
Douglas Gregora7365242012-02-14 19:27:52 +00008320 if (ShouldExpand) {
8321 // The transform has determined that we should perform an expansion;
8322 // transform and capture each of the arguments.
8323 // expansion of the pattern. Do so.
8324 VarDecl *Pack = C->getCapturedVar();
8325 for (unsigned I = 0; I != *NumExpansions; ++I) {
8326 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8327 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008328 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008329 Pack));
8330 if (!CapturedVar) {
8331 Invalid = true;
8332 continue;
8333 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008334
Douglas Gregora7365242012-02-14 19:27:52 +00008335 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008336 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8337 }
Douglas Gregora7365242012-02-14 19:27:52 +00008338 continue;
8339 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008340
Douglas Gregora7365242012-02-14 19:27:52 +00008341 EllipsisLoc = C->getEllipsisLoc();
8342 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008343
Douglas Gregordfca6f52012-02-13 22:00:16 +00008344 // Transform the captured variable.
8345 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008346 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008347 C->getCapturedVar()));
8348 if (!CapturedVar) {
8349 Invalid = true;
8350 continue;
8351 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008352
Douglas Gregordfca6f52012-02-13 22:00:16 +00008353 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008354 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008355 }
8356 if (!FinishedExplicitCaptures)
8357 getSema().finishLambdaExplicitCaptures(LSI);
8358
Douglas Gregordfca6f52012-02-13 22:00:16 +00008359
8360 // Enter a new evaluation context to insulate the lambda from any
8361 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008362 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008363
8364 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008366 /*IsInstantiation=*/true);
8367 return ExprError();
8368 }
8369
8370 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008371 StmtResult Body = getDerived().TransformStmt(E->getBody());
8372 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008373 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008374 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008376 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008377
Chad Rosier4a9d7952012-08-08 18:46:20 +00008378 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008379 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008380}
8381
8382template<typename Derived>
8383ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008384TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008385 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008386 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8387 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008388 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008389
Douglas Gregorb98b1992009-08-11 05:31:07 +00008390 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008391 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008392 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008393 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008394 &ArgumentChanged))
8395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008396
Douglas Gregorb98b1992009-08-11 05:31:07 +00008397 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008398 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008399 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008400 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008401
Douglas Gregorb98b1992009-08-11 05:31:07 +00008402 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008403 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008404 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008405 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008406 E->getRParenLoc());
8407}
Mike Stump1eb44332009-09-09 15:08:12 +00008408
Douglas Gregorb98b1992009-08-11 05:31:07 +00008409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008410ExprResult
John McCall865d4472009-11-19 22:55:06 +00008411TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008412 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008413 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008414 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008415 Expr *OldBase;
8416 QualType BaseType;
8417 QualType ObjectType;
8418 if (!E->isImplicitAccess()) {
8419 OldBase = E->getBase();
8420 Base = getDerived().TransformExpr(OldBase);
8421 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008423
John McCallaa81e162009-12-01 22:10:20 +00008424 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008425 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008426 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008427 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008428 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008429 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008430 ObjectTy,
8431 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008432 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008433 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008434
John McCallb3d87482010-08-24 05:47:05 +00008435 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008436 BaseType = ((Expr*) Base.get())->getType();
8437 } else {
8438 OldBase = 0;
8439 BaseType = getDerived().TransformType(E->getBaseType());
8440 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8441 }
Mike Stump1eb44332009-09-09 15:08:12 +00008442
Douglas Gregor6cd21982009-10-20 05:58:46 +00008443 // Transform the first part of the nested-name-specifier that qualifies
8444 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008445 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008446 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008447 E->getFirstQualifierFoundInScope(),
8448 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008449
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008450 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008451 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008452 QualifierLoc
8453 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8454 ObjectType,
8455 FirstQualifierInScope);
8456 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008457 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008458 }
Mike Stump1eb44332009-09-09 15:08:12 +00008459
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008460 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8461
John McCall43fed0d2010-11-12 08:19:04 +00008462 // TODO: If this is a conversion-function-id, verify that the
8463 // destination type name (if present) resolves the same way after
8464 // instantiation as it did in the local scope.
8465
Abramo Bagnara25777432010-08-11 22:01:17 +00008466 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008467 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008468 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008469 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008470
John McCallaa81e162009-12-01 22:10:20 +00008471 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008472 // This is a reference to a member without an explicitly-specified
8473 // template argument list. Optimize for this common case.
8474 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008475 Base.get() == OldBase &&
8476 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008477 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008478 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008479 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008480 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008481
John McCall9ae2f072010-08-23 23:25:46 +00008482 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008483 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008484 E->isArrow(),
8485 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008486 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008487 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008488 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008489 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008490 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008491 }
8492
John McCalld5532b62009-11-23 01:53:49 +00008493 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008494 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8495 E->getNumTemplateArgs(),
8496 TransArgs))
8497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008498
John McCall9ae2f072010-08-23 23:25:46 +00008499 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008500 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008501 E->isArrow(),
8502 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008503 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008504 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008505 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008506 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008507 &TransArgs);
8508}
8509
8510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008511ExprResult
John McCall454feb92009-12-08 09:21:05 +00008512TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008513 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008514 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008515 QualType BaseType;
8516 if (!Old->isImplicitAccess()) {
8517 Base = getDerived().TransformExpr(Old->getBase());
8518 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008519 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008520 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8521 Old->isArrow());
8522 if (Base.isInvalid())
8523 return ExprError();
8524 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008525 } else {
8526 BaseType = getDerived().TransformType(Old->getBaseType());
8527 }
John McCall129e2df2009-11-30 22:42:35 +00008528
Douglas Gregor4c9be892011-02-28 20:01:57 +00008529 NestedNameSpecifierLoc QualifierLoc;
8530 if (Old->getQualifierLoc()) {
8531 QualifierLoc
8532 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8533 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008534 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008535 }
8536
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008537 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8538
Abramo Bagnara25777432010-08-11 22:01:17 +00008539 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008540 Sema::LookupOrdinaryName);
8541
8542 // Transform all the decls.
8543 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8544 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008545 NamedDecl *InstD = static_cast<NamedDecl*>(
8546 getDerived().TransformDecl(Old->getMemberLoc(),
8547 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008548 if (!InstD) {
8549 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8550 // This can happen because of dependent hiding.
8551 if (isa<UsingShadowDecl>(*I))
8552 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008553 else {
8554 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008555 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008556 }
John McCall9f54ad42009-12-10 09:41:52 +00008557 }
John McCall129e2df2009-11-30 22:42:35 +00008558
8559 // Expand using declarations.
8560 if (isa<UsingDecl>(InstD)) {
8561 UsingDecl *UD = cast<UsingDecl>(InstD);
8562 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8563 E = UD->shadow_end(); I != E; ++I)
8564 R.addDecl(*I);
8565 continue;
8566 }
8567
8568 R.addDecl(InstD);
8569 }
8570
8571 R.resolveKind();
8572
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008573 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008574 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008575 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008576 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008577 Old->getMemberLoc(),
8578 Old->getNamingClass()));
8579 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008580 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008581
Douglas Gregor66c45152010-04-27 16:10:10 +00008582 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008583 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008584
John McCall129e2df2009-11-30 22:42:35 +00008585 TemplateArgumentListInfo TransArgs;
8586 if (Old->hasExplicitTemplateArgs()) {
8587 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8588 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008589 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8590 Old->getNumTemplateArgs(),
8591 TransArgs))
8592 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008593 }
John McCallc2233c52010-01-15 08:34:02 +00008594
8595 // FIXME: to do this check properly, we will need to preserve the
8596 // first-qualifier-in-scope here, just in case we had a dependent
8597 // base (and therefore couldn't do the check) and a
8598 // nested-name-qualifier (and therefore could do the lookup).
8599 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008600
John McCall9ae2f072010-08-23 23:25:46 +00008601 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008602 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008603 Old->getOperatorLoc(),
8604 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008605 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008606 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008607 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008608 R,
8609 (Old->hasExplicitTemplateArgs()
8610 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008611}
8612
8613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008614ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008615TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008616 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008617 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8618 if (SubExpr.isInvalid())
8619 return ExprError();
8620
8621 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008622 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008623
8624 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8625}
8626
8627template<typename Derived>
8628ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008629TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008630 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8631 if (Pattern.isInvalid())
8632 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008633
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008634 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8635 return SemaRef.Owned(E);
8636
Douglas Gregor67fd1252011-01-14 21:20:45 +00008637 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8638 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008639}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008640
8641template<typename Derived>
8642ExprResult
8643TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8644 // If E is not value-dependent, then nothing will change when we transform it.
8645 // Note: This is an instantiation-centric view.
8646 if (!E->isValueDependent())
8647 return SemaRef.Owned(E);
8648
8649 // Note: None of the implementations of TryExpandParameterPacks can ever
8650 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008651 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008652 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8653 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008654 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008655 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008656 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008657 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008658 ShouldExpand, RetainExpansion,
8659 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008660 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008661
Douglas Gregor089e8932011-10-10 18:59:29 +00008662 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008663 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008664
Douglas Gregor089e8932011-10-10 18:59:29 +00008665 NamedDecl *Pack = E->getPack();
8666 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008667 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008668 Pack));
8669 if (!Pack)
8670 return ExprError();
8671 }
8672
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673
Douglas Gregoree8aff02011-01-04 17:33:58 +00008674 // We now know the length of the parameter pack, so build a new expression
8675 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008676 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8677 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008678 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008679}
8680
Douglas Gregorbe230c32011-01-03 17:17:50 +00008681template<typename Derived>
8682ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008683TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8684 SubstNonTypeTemplateParmPackExpr *E) {
8685 // Default behavior is to do nothing with this transformation.
8686 return SemaRef.Owned(E);
8687}
8688
8689template<typename Derived>
8690ExprResult
John McCall91a57552011-07-15 05:09:51 +00008691TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8692 SubstNonTypeTemplateParmExpr *E) {
8693 // Default behavior is to do nothing with this transformation.
8694 return SemaRef.Owned(E);
8695}
8696
8697template<typename Derived>
8698ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008699TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8700 // Default behavior is to do nothing with this transformation.
8701 return SemaRef.Owned(E);
8702}
8703
8704template<typename Derived>
8705ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008706TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8707 MaterializeTemporaryExpr *E) {
8708 return getDerived().TransformExpr(E->GetTemporaryExpr());
8709}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008710
Douglas Gregor03e80032011-06-21 17:03:29 +00008711template<typename Derived>
8712ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008713TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8714 CXXStdInitializerListExpr *E) {
8715 return getDerived().TransformExpr(E->getSubExpr());
8716}
8717
8718template<typename Derived>
8719ExprResult
John McCall454feb92009-12-08 09:21:05 +00008720TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008721 return SemaRef.MaybeBindToTemporary(E);
8722}
8723
8724template<typename Derived>
8725ExprResult
8726TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008727 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008728}
8729
8730template<typename Derived>
8731ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008732TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8733 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8734 if (SubExpr.isInvalid())
8735 return ExprError();
8736
8737 if (!getDerived().AlwaysRebuild() &&
8738 SubExpr.get() == E->getSubExpr())
8739 return SemaRef.Owned(E);
8740
8741 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008742}
8743
8744template<typename Derived>
8745ExprResult
8746TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8747 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008748 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008749 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008750 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008751 /*IsCall=*/false, Elements, &ArgChanged))
8752 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008753
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008754 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8755 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008757 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8758 Elements.data(),
8759 Elements.size());
8760}
8761
8762template<typename Derived>
8763ExprResult
8764TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008765 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008766 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008767 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008768 bool ArgChanged = false;
8769 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8770 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008772 if (OrigElement.isPackExpansion()) {
8773 // This key/value element is a pack expansion.
8774 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8775 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8776 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8777 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8778
8779 // Determine whether the set of unexpanded parameter packs can
8780 // and should be expanded.
8781 bool Expand = true;
8782 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008783 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8784 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008785 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8786 OrigElement.Value->getLocEnd());
8787 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8788 PatternRange,
8789 Unexpanded,
8790 Expand, RetainExpansion,
8791 NumExpansions))
8792 return ExprError();
8793
8794 if (!Expand) {
8795 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008796 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008797 // expansion.
8798 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8799 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8800 if (Key.isInvalid())
8801 return ExprError();
8802
8803 if (Key.get() != OrigElement.Key)
8804 ArgChanged = true;
8805
8806 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8807 if (Value.isInvalid())
8808 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008809
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008810 if (Value.get() != OrigElement.Value)
8811 ArgChanged = true;
8812
Chad Rosier4a9d7952012-08-08 18:46:20 +00008813 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008814 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8815 };
8816 Elements.push_back(Expansion);
8817 continue;
8818 }
8819
8820 // Record right away that the argument was changed. This needs
8821 // to happen even if the array expands to nothing.
8822 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008824 // The transform has determined that we should perform an elementwise
8825 // expansion of the pattern. Do so.
8826 for (unsigned I = 0; I != *NumExpansions; ++I) {
8827 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8828 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8829 if (Key.isInvalid())
8830 return ExprError();
8831
8832 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8833 if (Value.isInvalid())
8834 return ExprError();
8835
Chad Rosier4a9d7952012-08-08 18:46:20 +00008836 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008837 Key.get(), Value.get(), SourceLocation(), NumExpansions
8838 };
8839
8840 // If any unexpanded parameter packs remain, we still have a
8841 // pack expansion.
8842 if (Key.get()->containsUnexpandedParameterPack() ||
8843 Value.get()->containsUnexpandedParameterPack())
8844 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008845
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008846 Elements.push_back(Element);
8847 }
8848
8849 // We've finished with this pack expansion.
8850 continue;
8851 }
8852
8853 // Transform and check key.
8854 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8855 if (Key.isInvalid())
8856 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008857
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008858 if (Key.get() != OrigElement.Key)
8859 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008860
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008861 // Transform and check value.
8862 ExprResult Value
8863 = getDerived().TransformExpr(OrigElement.Value);
8864 if (Value.isInvalid())
8865 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008867 if (Value.get() != OrigElement.Value)
8868 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008869
8870 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008871 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008872 };
8873 Elements.push_back(Element);
8874 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008875
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008876 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8877 return SemaRef.MaybeBindToTemporary(E);
8878
8879 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8880 Elements.data(),
8881 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008882}
8883
Mike Stump1eb44332009-09-09 15:08:12 +00008884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008885ExprResult
John McCall454feb92009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008887 TypeSourceInfo *EncodedTypeInfo
8888 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8889 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008891
Douglas Gregorb98b1992009-08-11 05:31:07 +00008892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008893 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008894 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008895
8896 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008897 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008898 E->getRParenLoc());
8899}
Mike Stump1eb44332009-09-09 15:08:12 +00008900
Douglas Gregorb98b1992009-08-11 05:31:07 +00008901template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008902ExprResult TreeTransform<Derived>::
8903TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008904 // This is a kind of implicit conversion, and it needs to get dropped
8905 // and recomputed for the same general reasons that ImplicitCastExprs
8906 // do, as well a more specific one: this expression is only valid when
8907 // it appears *immediately* as an argument expression.
8908 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008909}
8910
8911template<typename Derived>
8912ExprResult TreeTransform<Derived>::
8913TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008914 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008915 = getDerived().TransformType(E->getTypeInfoAsWritten());
8916 if (!TSInfo)
8917 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008918
John McCallf85e1932011-06-15 23:02:42 +00008919 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008920 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008921 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008922
John McCallf85e1932011-06-15 23:02:42 +00008923 if (!getDerived().AlwaysRebuild() &&
8924 TSInfo == E->getTypeInfoAsWritten() &&
8925 Result.get() == E->getSubExpr())
8926 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008927
John McCallf85e1932011-06-15 23:02:42 +00008928 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008929 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008930 Result.get());
8931}
8932
8933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008934ExprResult
John McCall454feb92009-12-08 09:21:05 +00008935TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008936 // Transform arguments.
8937 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008938 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008939 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008940 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008941 &ArgChanged))
8942 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008943
Douglas Gregor92e986e2010-04-22 16:44:27 +00008944 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8945 // Class message: transform the receiver type.
8946 TypeSourceInfo *ReceiverTypeInfo
8947 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8948 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008949 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008950
Douglas Gregor92e986e2010-04-22 16:44:27 +00008951 // If nothing changed, just retain the existing message send.
8952 if (!getDerived().AlwaysRebuild() &&
8953 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008954 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008955
8956 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008957 SmallVector<SourceLocation, 16> SelLocs;
8958 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008959 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8960 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008961 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008962 E->getMethodDecl(),
8963 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008964 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008965 E->getRightLoc());
8966 }
8967
8968 // Instance message: transform the receiver
8969 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8970 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008971 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008972 = getDerived().TransformExpr(E->getInstanceReceiver());
8973 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008974 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008975
8976 // If nothing changed, just retain the existing message send.
8977 if (!getDerived().AlwaysRebuild() &&
8978 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008979 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008980
Douglas Gregor92e986e2010-04-22 16:44:27 +00008981 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008982 SmallVector<SourceLocation, 16> SelLocs;
8983 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008984 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008985 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008986 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008987 E->getMethodDecl(),
8988 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008989 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008990 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008991}
8992
Mike Stump1eb44332009-09-09 15:08:12 +00008993template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008994ExprResult
John McCall454feb92009-12-08 09:21:05 +00008995TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008996 return SemaRef.Owned(E);
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009008 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009009 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009010 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009011 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009012
9013 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009014
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009015 // If nothing changed, just retain the existing expression.
9016 if (!getDerived().AlwaysRebuild() &&
9017 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009018 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009019
John McCall9ae2f072010-08-23 23:25:46 +00009020 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009021 E->getLocation(),
9022 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009023}
9024
Mike Stump1eb44332009-09-09 15:08:12 +00009025template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009026ExprResult
John McCall454feb92009-12-08 09:21:05 +00009027TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009028 // 'super' and types never change. Property never changes. Just
9029 // retain the existing expression.
9030 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009031 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009032
Douglas Gregore3303542010-04-26 20:47:02 +00009033 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009034 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009035 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009036 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009037
Douglas Gregore3303542010-04-26 20:47:02 +00009038 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009039
Douglas Gregore3303542010-04-26 20:47:02 +00009040 // If nothing changed, just retain the existing expression.
9041 if (!getDerived().AlwaysRebuild() &&
9042 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009043 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009044
John McCall12f78a62010-12-02 01:19:52 +00009045 if (E->isExplicitProperty())
9046 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9047 E->getExplicitProperty(),
9048 E->getLocation());
9049
9050 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009051 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009052 E->getImplicitPropertyGetter(),
9053 E->getImplicitPropertySetter(),
9054 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009055}
9056
Mike Stump1eb44332009-09-09 15:08:12 +00009057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009058ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009059TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9060 // Transform the base expression.
9061 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9062 if (Base.isInvalid())
9063 return ExprError();
9064
9065 // Transform the key expression.
9066 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9067 if (Key.isInvalid())
9068 return ExprError();
9069
9070 // If nothing changed, just retain the existing expression.
9071 if (!getDerived().AlwaysRebuild() &&
9072 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9073 return SemaRef.Owned(E);
9074
Chad Rosier4a9d7952012-08-08 18:46:20 +00009075 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009076 Base.get(), Key.get(),
9077 E->getAtIndexMethodDecl(),
9078 E->setAtIndexMethodDecl());
9079}
9080
9081template<typename Derived>
9082ExprResult
John McCall454feb92009-12-08 09:21:05 +00009083TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009084 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009085 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009086 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009087 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009088
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009089 // If nothing changed, just retain the existing expression.
9090 if (!getDerived().AlwaysRebuild() &&
9091 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009092 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009093
John McCall9ae2f072010-08-23 23:25:46 +00009094 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009095 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009096 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009097}
9098
Mike Stump1eb44332009-09-09 15:08:12 +00009099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009100ExprResult
John McCall454feb92009-12-08 09:21:05 +00009101TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009102 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009103 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009104 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009105 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009106 SubExprs, &ArgumentChanged))
9107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009108
Douglas Gregorb98b1992009-08-11 05:31:07 +00009109 if (!getDerived().AlwaysRebuild() &&
9110 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009111 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009112
Douglas Gregorb98b1992009-08-11 05:31:07 +00009113 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009114 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009115 E->getRParenLoc());
9116}
9117
Mike Stump1eb44332009-09-09 15:08:12 +00009118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009119ExprResult
John McCall454feb92009-12-08 09:21:05 +00009120TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009121 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009122
John McCallc6ac9c32011-02-04 18:33:18 +00009123 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9124 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9125
9126 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009127 blockScope->TheDecl->setBlockMissingReturnType(
9128 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009129
Chris Lattner686775d2011-07-20 06:58:45 +00009130 SmallVector<ParmVarDecl*, 4> params;
9131 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009132
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009133 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009134 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9135 oldBlock->param_begin(),
9136 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009137 0, paramTypes, &params)) {
9138 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009139 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009140 }
John McCallc6ac9c32011-02-04 18:33:18 +00009141
Jordan Rose09189892013-03-08 22:25:36 +00009142 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009143 QualType exprResultType =
9144 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009145
Jordan Rosebea522f2013-03-08 21:51:21 +00009146 QualType functionType =
9147 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009148 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009149 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009150
9151 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009152 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009153 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009154
9155 if (!oldBlock->blockMissingReturnType()) {
9156 blockScope->HasImplicitReturnType = false;
9157 blockScope->ReturnType = exprResultType;
9158 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009159
John McCall711c52b2011-01-05 12:14:39 +00009160 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009161 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009162 if (body.isInvalid()) {
9163 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009164 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009165 }
John McCall711c52b2011-01-05 12:14:39 +00009166
John McCallc6ac9c32011-02-04 18:33:18 +00009167#ifndef NDEBUG
9168 // In builds with assertions, make sure that we captured everything we
9169 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009170 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9171 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9172 e = oldBlock->capture_end(); i != e; ++i) {
9173 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009174
Douglas Gregorfc921372011-05-20 15:32:55 +00009175 // Ignore parameter packs.
9176 if (isa<ParmVarDecl>(oldCapture) &&
9177 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9178 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009179
Douglas Gregorfc921372011-05-20 15:32:55 +00009180 VarDecl *newCapture =
9181 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9182 oldCapture));
9183 assert(blockScope->CaptureMap.count(newCapture));
9184 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009185 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009186 }
9187#endif
9188
9189 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9190 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009191}
9192
Mike Stump1eb44332009-09-09 15:08:12 +00009193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009194ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009195TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009196 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009197}
Eli Friedman276b0612011-10-11 02:20:01 +00009198
9199template<typename Derived>
9200ExprResult
9201TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009202 QualType RetTy = getDerived().TransformType(E->getType());
9203 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009204 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009205 SubExprs.reserve(E->getNumSubExprs());
9206 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9207 SubExprs, &ArgumentChanged))
9208 return ExprError();
9209
9210 if (!getDerived().AlwaysRebuild() &&
9211 !ArgumentChanged)
9212 return SemaRef.Owned(E);
9213
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009214 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009215 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009216}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009217
Douglas Gregorb98b1992009-08-11 05:31:07 +00009218//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009219// Type reconstruction
9220//===----------------------------------------------------------------------===//
9221
Mike Stump1eb44332009-09-09 15:08:12 +00009222template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009223QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9224 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009225 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009226 getDerived().getBaseEntity());
9227}
9228
Mike Stump1eb44332009-09-09 15:08:12 +00009229template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009230QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9231 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009232 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009233 getDerived().getBaseEntity());
9234}
9235
Mike Stump1eb44332009-09-09 15:08:12 +00009236template<typename Derived>
9237QualType
John McCall85737a72009-10-30 00:06:24 +00009238TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9239 bool WrittenAsLValue,
9240 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009241 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009242 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009243}
9244
9245template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009246QualType
John McCall85737a72009-10-30 00:06:24 +00009247TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9248 QualType ClassType,
9249 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009250 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009251 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009252}
9253
9254template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009255QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009256TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9257 ArrayType::ArraySizeModifier SizeMod,
9258 const llvm::APInt *Size,
9259 Expr *SizeExpr,
9260 unsigned IndexTypeQuals,
9261 SourceRange BracketsRange) {
9262 if (SizeExpr || !Size)
9263 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9264 IndexTypeQuals, BracketsRange,
9265 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009266
9267 QualType Types[] = {
9268 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9269 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9270 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009271 };
Craig Topperb9602322013-07-15 03:38:40 +00009272 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009273 QualType SizeType;
9274 for (unsigned I = 0; I != NumTypes; ++I)
9275 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9276 SizeType = Types[I];
9277 break;
9278 }
Mike Stump1eb44332009-09-09 15:08:12 +00009279
Eli Friedman01f276d2012-01-25 23:20:27 +00009280 // Note that we can return a VariableArrayType here in the case where
9281 // the element type was a dependent VariableArrayType.
9282 IntegerLiteral *ArraySize
9283 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9284 /*FIXME*/BracketsRange.getBegin());
9285 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009286 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009287 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009288}
Mike Stump1eb44332009-09-09 15:08:12 +00009289
Douglas Gregor577f75a2009-08-04 16:50:30 +00009290template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009291QualType
9292TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009293 ArrayType::ArraySizeModifier SizeMod,
9294 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009295 unsigned IndexTypeQuals,
9296 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009297 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009298 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009299}
9300
9301template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009302QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009303TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009304 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009305 unsigned IndexTypeQuals,
9306 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009307 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009308 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009309}
Mike Stump1eb44332009-09-09 15:08:12 +00009310
Douglas Gregor577f75a2009-08-04 16:50:30 +00009311template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009312QualType
9313TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009314 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009315 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009316 unsigned IndexTypeQuals,
9317 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009318 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009319 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009320 IndexTypeQuals, BracketsRange);
9321}
9322
9323template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009324QualType
9325TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009326 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009327 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009328 unsigned IndexTypeQuals,
9329 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009330 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009331 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009332 IndexTypeQuals, BracketsRange);
9333}
9334
9335template<typename Derived>
9336QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009337 unsigned NumElements,
9338 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009339 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009340 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009341}
Mike Stump1eb44332009-09-09 15:08:12 +00009342
Douglas Gregor577f75a2009-08-04 16:50:30 +00009343template<typename Derived>
9344QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9345 unsigned NumElements,
9346 SourceLocation AttributeLoc) {
9347 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9348 NumElements, true);
9349 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009350 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9351 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009352 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009353}
Mike Stump1eb44332009-09-09 15:08:12 +00009354
Douglas Gregor577f75a2009-08-04 16:50:30 +00009355template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009356QualType
9357TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009358 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009359 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009360 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009361}
Mike Stump1eb44332009-09-09 15:08:12 +00009362
Douglas Gregor577f75a2009-08-04 16:50:30 +00009363template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009364QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9365 QualType T,
9366 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009367 const FunctionProtoType::ExtProtoInfo &EPI) {
9368 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009369 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009370 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009371 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009372}
Mike Stump1eb44332009-09-09 15:08:12 +00009373
Douglas Gregor577f75a2009-08-04 16:50:30 +00009374template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009375QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9376 return SemaRef.Context.getFunctionNoProtoType(T);
9377}
9378
9379template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009380QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9381 assert(D && "no decl found");
9382 if (D->isInvalidDecl()) return QualType();
9383
Douglas Gregor92e986e2010-04-22 16:44:27 +00009384 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009385 TypeDecl *Ty;
9386 if (isa<UsingDecl>(D)) {
9387 UsingDecl *Using = cast<UsingDecl>(D);
9388 assert(Using->isTypeName() &&
9389 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9390
9391 // A valid resolved using typename decl points to exactly one type decl.
9392 assert(++Using->shadow_begin() == Using->shadow_end());
9393 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009394
John McCalled976492009-12-04 22:46:56 +00009395 } else {
9396 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9397 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9398 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9399 }
9400
9401 return SemaRef.Context.getTypeDeclType(Ty);
9402}
9403
9404template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009405QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9406 SourceLocation Loc) {
9407 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009408}
9409
9410template<typename Derived>
9411QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9412 return SemaRef.Context.getTypeOfType(Underlying);
9413}
9414
9415template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009416QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9417 SourceLocation Loc) {
9418 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009419}
9420
9421template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009422QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9423 UnaryTransformType::UTTKind UKind,
9424 SourceLocation Loc) {
9425 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9426}
9427
9428template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009429QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009430 TemplateName Template,
9431 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009432 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009433 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009434}
Mike Stump1eb44332009-09-09 15:08:12 +00009435
Douglas Gregordcee1a12009-08-06 05:28:30 +00009436template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009437QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9438 SourceLocation KWLoc) {
9439 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9440}
9441
9442template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009443TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009444TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009445 bool TemplateKW,
9446 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009447 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009448 Template);
9449}
9450
9451template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009452TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009453TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9454 const IdentifierInfo &Name,
9455 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009456 QualType ObjectType,
9457 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009458 UnqualifiedId TemplateName;
9459 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009460 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009461 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009462 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009463 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009464 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009465 /*EnteringContext=*/false,
9466 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009467 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009468}
Mike Stump1eb44332009-09-09 15:08:12 +00009469
Douglas Gregorb98b1992009-08-11 05:31:07 +00009470template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009471TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009472TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009473 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009474 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009475 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009476 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009477 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009478 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009479 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009480 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009481 Sema::TemplateTy Template;
9482 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009483 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009484 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009485 /*EnteringContext=*/false,
9486 Template);
9487 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009488}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009489
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009491ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009492TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9493 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009494 Expr *OrigCallee,
9495 Expr *First,
9496 Expr *Second) {
9497 Expr *Callee = OrigCallee->IgnoreParenCasts();
9498 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009499
Douglas Gregorb98b1992009-08-11 05:31:07 +00009500 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009501 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009502 if (!First->getType()->isOverloadableType() &&
9503 !Second->getType()->isOverloadableType())
9504 return getSema().CreateBuiltinArraySubscriptExpr(First,
9505 Callee->getLocStart(),
9506 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009507 } else if (Op == OO_Arrow) {
9508 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009509 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9510 } else if (Second == 0 || isPostIncDec) {
9511 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009512 // The argument is not of overloadable type, so try to create a
9513 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009514 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009515 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009516
John McCall9ae2f072010-08-23 23:25:46 +00009517 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009518 }
9519 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009520 if (!First->getType()->isOverloadableType() &&
9521 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009522 // Neither of the arguments is an overloadable type, so try to
9523 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009524 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009525 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009526 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009527 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009529
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009530 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009531 }
9532 }
Mike Stump1eb44332009-09-09 15:08:12 +00009533
9534 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009535 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009536 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009537
John McCall9ae2f072010-08-23 23:25:46 +00009538 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009539 assert(ULE->requiresADL());
9540
9541 // FIXME: Do we have to check
9542 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009543 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009544 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009545 // If we've resolved this to a particular non-member function, just call
9546 // that function. If we resolved it to a member function,
9547 // CreateOverloaded* will find that function for us.
9548 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9549 if (!isa<CXXMethodDecl>(ND))
9550 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009551 }
Mike Stump1eb44332009-09-09 15:08:12 +00009552
Douglas Gregorb98b1992009-08-11 05:31:07 +00009553 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009554 Expr *Args[2] = { First, Second };
9555 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009556
Douglas Gregorb98b1992009-08-11 05:31:07 +00009557 // Create the overloaded operator invocation for unary operators.
9558 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009559 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009560 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009561 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009562 }
Mike Stump1eb44332009-09-09 15:08:12 +00009563
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009564 if (Op == OO_Subscript) {
9565 SourceLocation LBrace;
9566 SourceLocation RBrace;
9567
9568 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9569 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9570 LBrace = SourceLocation::getFromRawEncoding(
9571 NameLoc.CXXOperatorName.BeginOpNameLoc);
9572 RBrace = SourceLocation::getFromRawEncoding(
9573 NameLoc.CXXOperatorName.EndOpNameLoc);
9574 } else {
9575 LBrace = Callee->getLocStart();
9576 RBrace = OpLoc;
9577 }
9578
9579 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9580 First, Second);
9581 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009582
Douglas Gregorb98b1992009-08-11 05:31:07 +00009583 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009584 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009585 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009586 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9587 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009589
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009590 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009591}
Mike Stump1eb44332009-09-09 15:08:12 +00009592
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009593template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009594ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009595TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009596 SourceLocation OperatorLoc,
9597 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009598 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009599 TypeSourceInfo *ScopeType,
9600 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009601 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009602 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009603 QualType BaseType = Base->getType();
9604 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009605 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009606 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009607 !BaseType->getAs<PointerType>()->getPointeeType()
9608 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009609 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009610 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009611 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009612 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009613 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009614 /*FIXME?*/true);
9615 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009616
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009617 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009618 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9619 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9620 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9621 NameInfo.setNamedTypeInfo(DestroyedType);
9622
Richard Smith6314db92012-05-15 06:15:11 +00009623 // The scope type is now known to be a valid nested name specifier
9624 // component. Tack it on to the end of the nested name specifier.
9625 if (ScopeType)
9626 SS.Extend(SemaRef.Context, SourceLocation(),
9627 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009628
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009629 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009630 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009631 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009632 SS, TemplateKWLoc,
9633 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009634 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009635 /*TemplateArgs*/ 0);
9636}
9637
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009638template<typename Derived>
9639StmtResult
9640TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009641 SourceLocation Loc = S->getLocStart();
9642 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9643 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9644 S->getCapturedRegionKind(), NumParams);
9645 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9646
9647 if (Body.isInvalid()) {
9648 getSema().ActOnCapturedRegionError();
9649 return StmtError();
9650 }
9651
9652 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009653}
9654
Douglas Gregor577f75a2009-08-04 16:50:30 +00009655} // end namespace clang
9656
9657#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H