blob: cd0ffdd8e962f158c0972a8fbad62c4ee30812a3 [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
Eli Friedman1ac6c932013-09-06 01:13:30 +0000601// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
602// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000603#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000604 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000605 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000606#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000607 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000608 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000609#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000610#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000611
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000612#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000613 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000614 OMPClause *Transform ## Class(Class *S);
615#include "clang/Basic/OpenMPKinds.def"
616
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617 /// \brief Build a new pointer type given its pointee type.
618 ///
619 /// By default, performs semantic analysis when building the pointer type.
620 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000621 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622
623 /// \brief Build a new block pointer type given its pointee type.
624 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000627 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628
John McCall85737a72009-10-30 00:06:24 +0000629 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 ///
John McCall85737a72009-10-30 00:06:24 +0000631 /// By default, performs semantic analysis when building the
632 /// reference type. Subclasses may override this routine to provide
633 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 ///
John McCall85737a72009-10-30 00:06:24 +0000635 /// \param LValue whether the type was written with an lvalue sigil
636 /// or an rvalue sigil.
637 QualType RebuildReferenceType(QualType ReferentType,
638 bool LValue,
639 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new member pointer type given the pointee type and the
642 /// class type it refers into.
643 ///
644 /// By default, performs semantic analysis when building the member pointer
645 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000646 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
647 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000648
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 /// \brief Build a new array type given the element type, size
650 /// modifier, size of the array (if known), size expression, and index type
651 /// qualifiers.
652 ///
653 /// By default, performs semantic analysis when building the array type.
654 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000655 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 QualType RebuildArrayType(QualType ElementType,
657 ArrayType::ArraySizeModifier SizeMod,
658 const llvm::APInt *Size,
659 Expr *SizeExpr,
660 unsigned IndexTypeQuals,
661 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// \brief Build a new constant array type given the element type, size
664 /// modifier, (known) size of the array, and index type qualifiers.
665 ///
666 /// By default, performs semantic analysis when building the array type.
667 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000668 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 ArrayType::ArraySizeModifier SizeMod,
670 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673
Douglas Gregor577f75a2009-08-04 16:50:30 +0000674 /// \brief Build a new incomplete array type given the element type, size
675 /// modifier, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000679 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683
Mike Stump1eb44332009-09-09 15:08:12 +0000684 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// size modifier, size expression, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000689 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000691 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
694
Mike Stump1eb44332009-09-09 15:08:12 +0000695 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000700 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
706 /// \brief Build a new vector type given the element type and
707 /// number of elements.
708 ///
709 /// By default, performs semantic analysis when building the vector type.
710 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000711 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000712 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000713
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 /// \brief Build a new extended vector type given the element type and
715 /// number of elements.
716 ///
717 /// By default, performs semantic analysis when building the vector type.
718 /// Subclasses may override this routine to provide different behavior.
719 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
720 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000721
722 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// given the element type and number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000727 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000728 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000729 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000730
Douglas Gregor577f75a2009-08-04 16:50:30 +0000731 /// \brief Build a new function type.
732 ///
733 /// By default, performs semantic analysis when building the function type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000736 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000737 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000738
John McCalla2becad2009-10-21 00:40:46 +0000739 /// \brief Build a new unprototyped function type.
740 QualType RebuildFunctionNoProtoType(QualType ResultType);
741
John McCalled976492009-12-04 22:46:56 +0000742 /// \brief Rebuild an unresolved typename type, given the decl that
743 /// the UnresolvedUsingTypenameDecl was transformed to.
744 QualType RebuildUnresolvedUsingType(Decl *D);
745
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000747 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 return SemaRef.Context.getTypeDeclType(Typedef);
749 }
750
751 /// \brief Build a new class/struct/union type.
752 QualType RebuildRecordType(RecordDecl *Record) {
753 return SemaRef.Context.getTypeDeclType(Record);
754 }
755
756 /// \brief Build a new Enum type.
757 QualType RebuildEnumType(EnumDecl *Enum) {
758 return SemaRef.Context.getTypeDeclType(Enum);
759 }
John McCall7da24312009-09-05 00:15:47 +0000760
Mike Stump1eb44332009-09-09 15:08:12 +0000761 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000762 ///
763 /// By default, performs semantic analysis when building the typeof type.
764 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000765 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000766
Mike Stump1eb44332009-09-09 15:08:12 +0000767 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000768 ///
769 /// By default, builds a new TypeOfType with the given underlying type.
770 QualType RebuildTypeOfType(QualType Underlying);
771
Sean Huntca63c202011-05-24 22:41:36 +0000772 /// \brief Build a new unary transform type.
773 QualType RebuildUnaryTransformType(QualType BaseType,
774 UnaryTransformType::UTTKind UKind,
775 SourceLocation Loc);
776
Richard Smitha2c36462013-04-26 16:15:35 +0000777 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 ///
779 /// By default, performs semantic analysis when building the decltype type.
780 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000781 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Richard Smitha2c36462013-04-26 16:15:35 +0000783 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000784 ///
785 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000786 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000787 // Note, IsDependent is always false here: we implicitly convert an 'auto'
788 // which has been deduced to a dependent type into an undeduced 'auto', so
789 // that we'll retry deduction after the transformation.
Manuel Klimek152b4e42013-08-22 12:12:24 +0000790 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000791 }
792
Douglas Gregor577f75a2009-08-04 16:50:30 +0000793 /// \brief Build a new template specialization type.
794 ///
795 /// By default, performs semantic analysis when building the template
796 /// specialization type. Subclasses may override this routine to provide
797 /// different behavior.
798 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000799 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000800 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000801
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000802 /// \brief Build a new parenthesized type.
803 ///
804 /// By default, builds a new ParenType type from the inner type.
805 /// Subclasses may override this routine to provide different behavior.
806 QualType RebuildParenType(QualType InnerType) {
807 return SemaRef.Context.getParenType(InnerType);
808 }
809
Douglas Gregor577f75a2009-08-04 16:50:30 +0000810 /// \brief Build a new qualified name type.
811 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000812 /// By default, builds a new ElaboratedType type from the keyword,
813 /// the nested-name-specifier and the named type.
814 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000815 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
816 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000817 NestedNameSpecifierLoc QualifierLoc,
818 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 return SemaRef.Context.getElaboratedType(Keyword,
820 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000821 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000822 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000823
824 /// \brief Build a new typename type that refers to a template-id.
825 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 /// By default, builds a new DependentNameType type from the
827 /// nested-name-specifier and the given type. Subclasses may override
828 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000829 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 ElaboratedTypeKeyword Keyword,
831 NestedNameSpecifierLoc QualifierLoc,
832 const IdentifierInfo *Name,
833 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000834 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 // Rebuild the template name.
836 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000837 CXXScopeSpec SS;
838 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000840 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000842 if (InstName.isNull())
843 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000844
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000845 // If it's still dependent, make a dependent specialization.
846 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000847 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000851
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000852 // Otherwise, make an elaborated type wrapping a non-dependent
853 // specialization.
854 QualType T =
855 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
856 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000857
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
859 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000860
861 return SemaRef.Context.getElaboratedType(Keyword,
862 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000863 T);
864 }
865
Douglas Gregor577f75a2009-08-04 16:50:30 +0000866 /// \brief Build a new typename type that refers to an identifier.
867 ///
868 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000870 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000871 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000873 NestedNameSpecifierLoc QualifierLoc,
874 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000875 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000876 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000880 // If the name is still dependent, just build a new dependent name type.
881 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882 return SemaRef.Context.getDependentNameType(Keyword,
883 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000885 }
886
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000887 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000888 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000889 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000890
891 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
892
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000893 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000894 // into a non-dependent elaborated-type-specifier. Find the tag we're
895 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000896 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000897 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
898 if (!DC)
899 return QualType();
900
John McCall56138762010-05-27 06:40:31 +0000901 if (SemaRef.RequireCompleteDeclContext(SS, DC))
902 return QualType();
903
Douglas Gregor40336422010-03-31 22:19:08 +0000904 TagDecl *Tag = 0;
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::NotFound:
908 case LookupResult::NotFoundInCurrentInstantiation:
909 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000910
Douglas Gregor40336422010-03-31 22:19:08 +0000911 case LookupResult::Found:
912 Tag = Result.getAsSingle<TagDecl>();
913 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000914
Douglas Gregor40336422010-03-31 22:19:08 +0000915 case LookupResult::FoundOverloaded:
916 case LookupResult::FoundUnresolvedValue:
917 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000918
Douglas Gregor40336422010-03-31 22:19:08 +0000919 case LookupResult::Ambiguous:
920 // Let the LookupResult structure handle ambiguities.
921 return QualType();
922 }
923
924 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000925 // Check where the name exists but isn't a tag type and use that to emit
926 // better diagnostics.
927 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
928 SemaRef.LookupQualifiedName(Result, DC);
929 switch (Result.getResultKind()) {
930 case LookupResult::Found:
931 case LookupResult::FoundOverloaded:
932 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000933 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000934 unsigned Kind = 0;
935 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000936 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
937 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000938 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
939 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
940 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000941 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000942 default:
943 // FIXME: Would be nice to highlight just the source range.
944 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
945 << Kind << Id << DC;
946 break;
947 }
Douglas Gregor40336422010-03-31 22:19:08 +0000948 return QualType();
949 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000950
Richard Trieubbf34c02011-06-10 03:11:26 +0000951 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
952 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000953 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000954 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
955 return QualType();
956 }
957
958 // Build the elaborated-type-specifier type.
959 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000960 return SemaRef.Context.getElaboratedType(Keyword,
961 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000962 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000963 }
Mike Stump1eb44332009-09-09 15:08:12 +0000964
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000965 /// \brief Build a new pack expansion type.
966 ///
967 /// By default, builds a new PackExpansionType type from the given pattern.
968 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000969 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000972 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000973 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
974 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000975 }
976
Eli Friedmanb001de72011-10-06 23:00:33 +0000977 /// \brief Build a new atomic type given its value type.
978 ///
979 /// By default, performs semantic analysis when building the atomic type.
980 /// Subclasses may override this routine to provide different behavior.
981 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
982
Douglas Gregord1067e52009-08-06 06:41:21 +0000983 /// \brief Build a new template name given a nested name specifier, a flag
984 /// indicating whether the "template" keyword was provided, and the template
985 /// that the template name refers to.
986 ///
987 /// By default, builds the new template name directly. Subclasses may override
988 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000989 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000990 bool TemplateKW,
991 TemplateDecl *Template);
992
Douglas Gregord1067e52009-08-06 06:41:21 +0000993 /// \brief Build a new template name given a nested name specifier and the
994 /// name that is referred to as a template.
995 ///
996 /// By default, performs semantic analysis to determine whether the name can
997 /// be resolved to a specific template, then builds the appropriate kind of
998 /// template name. Subclasses may override this routine to provide different
999 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1001 const IdentifierInfo &Name,
1002 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001003 QualType ObjectType,
1004 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001006 /// \brief Build a new template name given a nested name specifier and the
1007 /// overloaded operator name that is referred to as a template.
1008 ///
1009 /// By default, performs semantic analysis to determine whether the name can
1010 /// be resolved to a specific template, then builds the appropriate kind of
1011 /// template name. Subclasses may override this routine to provide different
1012 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001015 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001016 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001017
1018 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001019 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
1025 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1026 const TemplateArgument &ArgPack) {
1027 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1028 }
1029
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 /// \brief Build a new compound statement.
1031 ///
1032 /// By default, performs semantic analysis to build the new statement.
1033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001034 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 MultiStmtArg Statements,
1036 SourceLocation RBraceLoc,
1037 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001038 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 IsStmtExpr);
1040 }
1041
1042 /// \brief Build a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001049 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 ColonLoc);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Attach the body to a new case statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001059 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 getSema().ActOnCaseStmtBody(S, Body);
1061 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 /// \brief Build a new default statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Stmt *SubStmt) {
1071 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /*CurScope=*/0);
1073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new label statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001079 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1080 SourceLocation ColonLoc, Stmt *SubStmt) {
1081 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Richard Smith534986f2012-04-14 00:33:13 +00001084 /// \brief Build a new label statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001088 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1089 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001090 Stmt *SubStmt) {
1091 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1092 }
1093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Build a new "if" statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001099 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001101 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Start building a new switch statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001109 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001110 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001111 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregor43959a92009-08-20 07:17:43 +00001114 /// \brief Attach the body to the switch statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001119 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new while statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001127 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1128 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001129 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new do-while statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation WhileLoc, SourceLocation LParenLoc,
1138 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1140 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 }
1142
1143 /// \brief Build a new for statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001148 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 VarDecl *CondVar, Sema::FullExprArg Inc,
1150 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001151 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001152 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new goto statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1160 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001161 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
1163
1164 /// \brief Build a new indirect goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001169 SourceLocation StarLoc,
1170 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001171 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor43959a92009-08-20 07:17:43 +00001174 /// \brief Build a new return statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001178 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor43959a92009-08-20 07:17:43 +00001182 /// \brief Build a new declaration statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001186 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1187 SourceLocation StartLoc, SourceLocation EndLoc) {
1188 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001189 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001190 }
Mike Stump1eb44332009-09-09 15:08:12 +00001191
Anders Carlsson703e3942010-01-24 05:50:09 +00001192 /// \brief Build a new inline asm statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001196 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1197 bool IsVolatile, unsigned NumOutputs,
1198 unsigned NumInputs, IdentifierInfo **Names,
1199 MultiExprArg Constraints, MultiExprArg Exprs,
1200 Expr *AsmString, MultiExprArg Clobbers,
1201 SourceLocation RParenLoc) {
1202 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1203 NumInputs, Names, Constraints, Exprs,
1204 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001205 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206
Chad Rosier8cd64b42012-06-11 20:47:18 +00001207 /// \brief Build a new MS style inline asm statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001211 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001212 ArrayRef<Token> AsmToks,
1213 StringRef AsmString,
1214 unsigned NumOutputs, unsigned NumInputs,
1215 ArrayRef<StringRef> Constraints,
1216 ArrayRef<StringRef> Clobbers,
1217 ArrayRef<Expr*> Exprs,
1218 SourceLocation EndLoc) {
1219 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1220 NumOutputs, NumInputs,
1221 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001222 }
1223
James Dennett699c9042012-06-15 07:13:21 +00001224 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001230 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001232 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001233 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 }
1235
Douglas Gregorbe270a02010-04-26 17:57:08 +00001236 /// \brief Rebuild an Objective-C exception declaration.
1237 ///
1238 /// By default, performs semantic analysis to build the new declaration.
1239 /// Subclasses may override this routine to provide different behavior.
1240 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1241 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001242 return getSema().BuildObjCExceptionDecl(TInfo, T,
1243 ExceptionDecl->getInnerLocStart(),
1244 ExceptionDecl->getLocation(),
1245 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 SourceLocation RParenLoc,
1254 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001257 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001265 Stmt *Body) {
1266 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001274 Expr *Operand) {
1275 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001277
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001278 /// \brief Build a new OpenMP parallel directive.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
1282 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1283 Stmt *AStmt,
1284 SourceLocation StartLoc,
1285 SourceLocation EndLoc) {
1286 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1287 StartLoc, EndLoc);
1288 }
1289
1290 /// \brief Build a new OpenMP 'default' clause.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1295 SourceLocation KindKwLoc,
1296 SourceLocation StartLoc,
1297 SourceLocation LParenLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1300 StartLoc, LParenLoc, EndLoc);
1301 }
1302
1303 /// \brief Build a new OpenMP 'private' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1312 EndLoc);
1313 }
1314
James Dennett699c9042012-06-15 07:13:21 +00001315 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1320 Expr *object) {
1321 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1322 }
1323
James Dennett699c9042012-06-15 07:13:21 +00001324 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001325 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001329 Expr *Object, Stmt *Body) {
1330 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001331 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001332
James Dennett699c9042012-06-15 07:13:21 +00001333 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001334 ///
1335 /// By default, performs semantic analysis to build the new statement.
1336 /// Subclasses may override this routine to provide different behavior.
1337 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1338 Stmt *Body) {
1339 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1340 }
John McCall990567c2011-07-27 01:07:15 +00001341
Douglas Gregorc3203e72010-04-22 23:10:45 +00001342 /// \brief Build a new Objective-C fast enumeration statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001346 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001347 Stmt *Element,
1348 Expr *Collection,
1349 SourceLocation RParenLoc,
1350 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001351 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001352 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001353 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001354 RParenLoc);
1355 if (ForEachStmt.isInvalid())
1356 return StmtError();
1357
1358 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001360
Douglas Gregor43959a92009-08-20 07:17:43 +00001361 /// \brief Build a new C++ exception declaration.
1362 ///
1363 /// By default, performs semantic analysis to build the new decaration.
1364 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001365 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001366 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001367 SourceLocation StartLoc,
1368 SourceLocation IdLoc,
1369 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001370 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1371 StartLoc, IdLoc, Id);
1372 if (Var)
1373 getSema().CurContext->addDecl(Var);
1374 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001375 }
1376
1377 /// \brief Build a new C++ catch statement.
1378 ///
1379 /// By default, performs semantic analysis to build the new statement.
1380 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001381 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001382 VarDecl *ExceptionDecl,
1383 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001384 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1385 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001386 }
Mike Stump1eb44332009-09-09 15:08:12 +00001387
Douglas Gregor43959a92009-08-20 07:17:43 +00001388 /// \brief Build a new C++ try statement.
1389 ///
1390 /// By default, performs semantic analysis to build the new statement.
1391 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001392 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1393 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001394 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001395 }
Mike Stump1eb44332009-09-09 15:08:12 +00001396
Richard Smithad762fc2011-04-14 22:09:26 +00001397 /// \brief Build a new C++0x range-based for statement.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
1401 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1402 SourceLocation ColonLoc,
1403 Stmt *Range, Stmt *BeginEnd,
1404 Expr *Cond, Expr *Inc,
1405 Stmt *LoopVar,
1406 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001407 // If we've just learned that the range is actually an Objective-C
1408 // collection, treat this as an Objective-C fast enumeration loop.
1409 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1410 if (RangeStmt->isSingleDecl()) {
1411 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001412 if (RangeVar->isInvalidDecl())
1413 return StmtError();
1414
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001415 Expr *RangeExpr = RangeVar->getInit();
1416 if (!RangeExpr->isTypeDependent() &&
1417 RangeExpr->getType()->isObjCObjectPointerType())
1418 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1419 RParenLoc);
1420 }
1421 }
1422 }
1423
Richard Smithad762fc2011-04-14 22:09:26 +00001424 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001425 Cond, Inc, LoopVar, RParenLoc,
1426 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001427 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001428
1429 /// \brief Build a new C++0x range-based for statement.
1430 ///
1431 /// By default, performs semantic analysis to build the new statement.
1432 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001433 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001434 bool IsIfExists,
1435 NestedNameSpecifierLoc QualifierLoc,
1436 DeclarationNameInfo NameInfo,
1437 Stmt *Nested) {
1438 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1439 QualifierLoc, NameInfo, Nested);
1440 }
1441
Richard Smithad762fc2011-04-14 22:09:26 +00001442 /// \brief Attach body to a C++0x range-based for statement.
1443 ///
1444 /// By default, performs semantic analysis to finish the new statement.
1445 /// Subclasses may override this routine to provide different behavior.
1446 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1447 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1448 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001449
John Wiegley28bbe4b2011-04-28 01:08:34 +00001450 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1451 SourceLocation TryLoc,
1452 Stmt *TryBlock,
1453 Stmt *Handler) {
1454 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1455 }
1456
1457 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1458 Expr *FilterExpr,
1459 Stmt *Block) {
1460 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1461 }
1462
1463 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1464 Stmt *Block) {
1465 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1466 }
1467
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// \brief Build a new expression that references a declaration.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001473 LookupResult &R,
1474 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001475 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1476 }
1477
1478
1479 /// \brief Build a new expression that references a declaration.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001483 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001484 ValueDecl *VD,
1485 const DeclarationNameInfo &NameInfo,
1486 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001487 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001488 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001489
1490 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001491
1492 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 }
Mike Stump1eb44332009-09-09 15:08:12 +00001494
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001496 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001499 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001501 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 }
1503
Douglas Gregora71d8192009-09-04 17:36:40 +00001504 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001505 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001508 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001509 SourceLocation OperatorLoc,
1510 bool isArrow,
1511 CXXScopeSpec &SS,
1512 TypeSourceInfo *ScopeType,
1513 SourceLocation CCLoc,
1514 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001515 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001518 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001521 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001522 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001523 Expr *SubExpr) {
1524 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 }
Mike Stump1eb44332009-09-09 15:08:12 +00001526
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001527 /// \brief Build a new builtin offsetof expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001532 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001533 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001534 unsigned NumComponents,
1535 SourceLocation RParenLoc) {
1536 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1537 NumComponents, RParenLoc);
1538 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001539
1540 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001541 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001542 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001545 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1546 SourceLocation OpLoc,
1547 UnaryExprOrTypeTrait ExprKind,
1548 SourceRange R) {
1549 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 }
1551
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001552 /// \brief Build a new sizeof, alignof or vec step expression with an
1553 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001554 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001557 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1558 UnaryExprOrTypeTrait ExprKind,
1559 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001560 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001561 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001564
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001565 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 }
Mike Stump1eb44332009-09-09 15:08:12 +00001567
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001569 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001572 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001574 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1577 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 RBracketLoc);
1579 }
1580
1581 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001582 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001587 SourceLocation RParenLoc,
1588 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001589 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001590 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 }
1592
1593 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001597 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001598 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001599 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001600 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001601 const DeclarationNameInfo &MemberNameInfo,
1602 ValueDecl *Member,
1603 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001604 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001605 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001606 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1607 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001608 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001609 // We have a reference to an unnamed field. This is always the
1610 // base of an anonymous struct/union member access, i.e. the
1611 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001612 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001613 assert(Member->getType()->isRecordType() &&
1614 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Richard Smith9138b4e2011-10-26 19:06:56 +00001616 BaseResult =
1617 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001618 QualifierLoc.getNestedNameSpecifier(),
1619 FoundDecl, Member);
1620 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001621 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001622 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001623 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001624 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001625 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001626 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001627 cast<FieldDecl>(Member)->getType(),
1628 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001629 return getSema().Owned(ME);
1630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001632 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001633 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001634
John Wiegley429bb272011-04-08 18:41:53 +00001635 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001636 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001637
John McCall6bb80172010-03-30 21:47:33 +00001638 // FIXME: this involves duplicating earlier analysis in a lot of
1639 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001640 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001641 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001642 R.resolveKind();
1643
John McCall9ae2f072010-08-23 23:25:46 +00001644 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001645 SS, TemplateKWLoc,
1646 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001647 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001651 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001654 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001655 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001656 Expr *LHS, Expr *RHS) {
1657 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
1659
1660 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001661 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001664 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001665 SourceLocation QuestionLoc,
1666 Expr *LHS,
1667 SourceLocation ColonLoc,
1668 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001669 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1670 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 }
1672
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001674 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001677 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001678 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001681 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 }
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001686 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001690 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001692 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001693 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001694 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 }
Mike Stump1eb44332009-09-09 15:08:12 +00001696
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001698 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001701 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 SourceLocation OpLoc,
1703 SourceLocation AccessorLoc,
1704 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001705
John McCall129e2df2009-11-30 22:42:35 +00001706 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001707 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001708 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001709 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001710 SS, SourceLocation(),
1711 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001712 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001713 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001717 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001720 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001721 MultiExprArg Inits,
1722 SourceLocation RBraceLoc,
1723 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001725 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001726 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001727 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001728
Douglas Gregore48319a2009-11-09 17:16:50 +00001729 // Patch in the result type we were given, which may have been computed
1730 // when the initial InitListExpr was built.
1731 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1732 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001733 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 }
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001737 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 MultiExprArg ArrayExprs,
1742 SourceLocation EqualOrColonLoc,
1743 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001745 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001747 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001750
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001751 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 }
Mike Stump1eb44332009-09-09 15:08:12 +00001753
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001755 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// By default, builds the implicit value initialization without performing
1757 /// any semantic analysis. Subclasses may override this routine to provide
1758 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1761 }
Mike Stump1eb44332009-09-09 15:08:12 +00001762
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001764 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001768 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001769 SourceLocation RParenLoc) {
1770 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001771 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001772 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 }
1774
1775 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001776 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001779 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001780 MultiExprArg SubExprs,
1781 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001782 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 }
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001786 ///
1787 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 /// rather than attempting to map the label statement itself.
1789 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001790 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001791 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001792 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 }
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001796 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001800 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001802 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
Mike Stump1eb44332009-09-09 15:08:12 +00001804
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// \brief Build a new __builtin_choose_expr expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001809 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001810 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RParenLoc) {
1812 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 RParenLoc);
1815 }
Mike Stump1eb44332009-09-09 15:08:12 +00001816
Peter Collingbournef111d932011-04-15 00:35:48 +00001817 /// \brief Build a new generic selection expression.
1818 ///
1819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
1821 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1822 SourceLocation DefaultLoc,
1823 SourceLocation RParenLoc,
1824 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001825 ArrayRef<TypeSourceInfo *> Types,
1826 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001827 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001828 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001829 }
1830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new overloaded operator call expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// The semantic analysis provides the behavior of template instantiation,
1835 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001836 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 /// argument-dependent lookup, etc. Subclasses may override this routine to
1838 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001839 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001841 Expr *Callee,
1842 Expr *First,
1843 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001844
1845 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 /// reinterpret_cast.
1847 ///
1848 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001849 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001851 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 Stmt::StmtClass Class,
1853 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001854 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation RAngleLoc,
1856 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation RParenLoc) {
1859 switch (Class) {
1860 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001861 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001862 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001863 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864
1865 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001866 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001867 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001869
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001871 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001872 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001873 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001877 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001878 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001879 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001882 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 }
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 /// \brief Build a new C++ static_cast expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001892 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 SourceLocation RAngleLoc,
1894 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001897 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001898 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001899 SourceRange(LAngleLoc, RAngleLoc),
1900 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 }
1902
1903 /// \brief Build a new C++ dynamic_cast expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001907 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001909 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 SourceLocation RAngleLoc,
1911 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001912 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001914 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001915 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001916 SourceRange(LAngleLoc, RAngleLoc),
1917 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 }
1919
1920 /// \brief Build a new C++ reinterpret_cast expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001924 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001926 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 SourceLocation RAngleLoc,
1928 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001929 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001931 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001932 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001933 SourceRange(LAngleLoc, RAngleLoc),
1934 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 }
1936
1937 /// \brief Build a new C++ const_cast expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001941 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001943 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 SourceLocation RAngleLoc,
1945 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001946 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001948 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001949 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001950 SourceRange(LAngleLoc, RAngleLoc),
1951 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 }
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 /// \brief Build a new C++ functional-style cast expression.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001958 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1959 SourceLocation LParenLoc,
1960 Expr *Sub,
1961 SourceLocation RParenLoc) {
1962 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001963 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 RParenLoc);
1965 }
Mike Stump1eb44332009-09-09 15:08:12 +00001966
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 /// \brief Build a new C++ typeid(type) expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001971 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001972 SourceLocation TypeidLoc,
1973 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001975 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001976 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 }
Mike Stump1eb44332009-09-09 15:08:12 +00001978
Francois Pichet01b7c302010-09-08 12:20:18 +00001979
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 /// \brief Build a new C++ typeid(expr) expression.
1981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001984 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001985 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001986 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001988 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001989 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001990 }
1991
Francois Pichet01b7c302010-09-08 12:20:18 +00001992 /// \brief Build a new C++ __uuidof(type) expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
1996 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1997 SourceLocation TypeidLoc,
1998 TypeSourceInfo *Operand,
1999 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002000 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002001 RParenLoc);
2002 }
2003
2004 /// \brief Build a new C++ __uuidof(expr) expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2009 SourceLocation TypeidLoc,
2010 Expr *Operand,
2011 SourceLocation RParenLoc) {
2012 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2013 RParenLoc);
2014 }
2015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// \brief Build a new C++ "this" expression.
2017 ///
2018 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002019 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002022 QualType ThisType,
2023 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002024 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002025 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002026 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2027 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 }
2029
2030 /// \brief Build a new C++ throw expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002034 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2035 bool IsThrownVariableInScope) {
2036 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 }
2038
2039 /// \brief Build a new C++ default-argument expression.
2040 ///
2041 /// By default, builds a new default-argument expression, which does not
2042 /// require any semantic analysis. Subclasses may override this routine to
2043 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002044 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002045 ParmVarDecl *Param) {
2046 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2047 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002048 }
2049
Richard Smithc3bf52c2013-04-20 22:23:05 +00002050 /// \brief Build a new C++11 default-initialization expression.
2051 ///
2052 /// By default, builds a new default field initialization expression, which
2053 /// does not require any semantic analysis. Subclasses may override this
2054 /// routine to provide different behavior.
2055 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2056 FieldDecl *Field) {
2057 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2058 Field));
2059 }
2060
Douglas Gregorb98b1992009-08-11 05:31:07 +00002061 /// \brief Build a new C++ zero-initialization expression.
2062 ///
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002065 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2066 SourceLocation LParenLoc,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002069 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002070 }
Mike Stump1eb44332009-09-09 15:08:12 +00002071
Douglas Gregorb98b1992009-08-11 05:31:07 +00002072 /// \brief Build a new C++ "new" expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002076 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002077 bool UseGlobal,
2078 SourceLocation PlacementLParen,
2079 MultiExprArg PlacementArgs,
2080 SourceLocation PlacementRParen,
2081 SourceRange TypeIdParens,
2082 QualType AllocatedType,
2083 TypeSourceInfo *AllocatedTypeInfo,
2084 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002085 SourceRange DirectInitRange,
2086 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002087 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002089 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002091 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002092 AllocatedType,
2093 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002094 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002095 DirectInitRange,
2096 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 }
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 /// \brief Build a new C++ "delete" expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002103 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 bool IsGlobalDelete,
2105 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002106 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002108 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 }
Mike Stump1eb44332009-09-09 15:08:12 +00002110
Douglas Gregorb98b1992009-08-11 05:31:07 +00002111 /// \brief Build a new unary type trait expression.
2112 ///
2113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002115 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002116 SourceLocation StartLoc,
2117 TypeSourceInfo *T,
2118 SourceLocation RParenLoc) {
2119 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 }
2121
Francois Pichet6ad6f282010-12-07 00:08:36 +00002122 /// \brief Build a new binary type trait expression.
2123 ///
2124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
2126 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2127 SourceLocation StartLoc,
2128 TypeSourceInfo *LhsT,
2129 TypeSourceInfo *RhsT,
2130 SourceLocation RParenLoc) {
2131 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2132 }
2133
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002134 /// \brief Build a new type trait expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
2138 ExprResult RebuildTypeTrait(TypeTrait Trait,
2139 SourceLocation StartLoc,
2140 ArrayRef<TypeSourceInfo *> Args,
2141 SourceLocation RParenLoc) {
2142 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2143 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002144
John Wiegley21ff2e52011-04-28 00:16:57 +00002145 /// \brief Build a new array type trait expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
2149 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2150 SourceLocation StartLoc,
2151 TypeSourceInfo *TSInfo,
2152 Expr *DimExpr,
2153 SourceLocation RParenLoc) {
2154 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2155 }
2156
John Wiegley55262202011-04-25 06:54:41 +00002157 /// \brief Build a new expression trait expression.
2158 ///
2159 /// By default, performs semantic analysis to build the new expression.
2160 /// Subclasses may override this routine to provide different behavior.
2161 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2162 SourceLocation StartLoc,
2163 Expr *Queried,
2164 SourceLocation RParenLoc) {
2165 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2166 }
2167
Mike Stump1eb44332009-09-09 15:08:12 +00002168 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169 /// expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002173 ExprResult RebuildDependentScopeDeclRefExpr(
2174 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002175 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002176 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002177 const TemplateArgumentListInfo *TemplateArgs,
2178 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002179 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002180 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002181
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002182 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002183 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002184 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002185
Richard Smithefeeccf2012-10-21 03:28:35 +00002186 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2187 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 }
2189
2190 /// \brief Build a new template-id expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002194 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002195 SourceLocation TemplateKWLoc,
2196 LookupResult &R,
2197 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002198 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002199 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2200 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002201 }
2202
2203 /// \brief Build a new object-construction expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002208 SourceLocation Loc,
2209 CXXConstructorDecl *Constructor,
2210 bool IsElidable,
2211 MultiExprArg Args,
2212 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002213 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002214 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002215 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002216 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002217 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002218 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002219 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002220 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002221
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002222 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002223 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002224 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002225 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002226 RequiresZeroInit, ConstructKind,
2227 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002228 }
2229
2230 /// \brief Build a new object-construction expression.
2231 ///
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002234 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2235 SourceLocation LParenLoc,
2236 MultiExprArg Args,
2237 SourceLocation RParenLoc) {
2238 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002239 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002240 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002241 RParenLoc);
2242 }
2243
2244 /// \brief Build a new object-construction expression.
2245 ///
2246 /// By default, performs semantic analysis to build the new expression.
2247 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002248 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2249 SourceLocation LParenLoc,
2250 MultiExprArg Args,
2251 SourceLocation RParenLoc) {
2252 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002253 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002254 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002255 RParenLoc);
2256 }
Mike Stump1eb44332009-09-09 15:08:12 +00002257
Douglas Gregorb98b1992009-08-11 05:31:07 +00002258 /// \brief Build a new member reference expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002262 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002263 QualType BaseType,
2264 bool IsArrow,
2265 SourceLocation OperatorLoc,
2266 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002267 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002268 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002269 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002270 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002272 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002273
John McCall9ae2f072010-08-23 23:25:46 +00002274 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002275 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002276 SS, TemplateKWLoc,
2277 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002278 MemberNameInfo,
2279 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 }
2281
John McCall129e2df2009-11-30 22:42:35 +00002282 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002286 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2287 SourceLocation OperatorLoc,
2288 bool IsArrow,
2289 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002290 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002291 NamedDecl *FirstQualifierInScope,
2292 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002293 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002294 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002295 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002296
John McCall9ae2f072010-08-23 23:25:46 +00002297 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002298 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002299 SS, TemplateKWLoc,
2300 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002301 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002302 }
Mike Stump1eb44332009-09-09 15:08:12 +00002303
Sebastian Redl2e156222010-09-10 20:55:43 +00002304 /// \brief Build a new noexcept expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
2308 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2309 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2310 }
2311
Douglas Gregoree8aff02011-01-04 17:33:58 +00002312 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002313 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2314 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002315 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002316 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002317 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002318 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2319 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002320 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002321
2322 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2323 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002324 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002325 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002326
Patrick Beardeb382ec2012-04-19 00:25:12 +00002327 /// \brief Build a new Objective-C boxed expression.
2328 ///
2329 /// By default, performs semantic analysis to build the new expression.
2330 /// Subclasses may override this routine to provide different behavior.
2331 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2332 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2333 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002335 /// \brief Build a new Objective-C array literal.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
2339 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2340 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002341 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002342 MultiExprArg(Elements, NumElements));
2343 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002344
2345 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002346 Expr *Base, Expr *Key,
2347 ObjCMethodDecl *getterMethod,
2348 ObjCMethodDecl *setterMethod) {
2349 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2350 getterMethod, setterMethod);
2351 }
2352
2353 /// \brief Build a new Objective-C dictionary literal.
2354 ///
2355 /// By default, performs semantic analysis to build the new expression.
2356 /// Subclasses may override this routine to provide different behavior.
2357 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2358 ObjCDictionaryElement *Elements,
2359 unsigned NumElements) {
2360 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2361 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362
James Dennett699c9042012-06-15 07:13:21 +00002363 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002364 ///
2365 /// By default, performs semantic analysis to build the new expression.
2366 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002367 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002368 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002369 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002370 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002371 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002372 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002373
Douglas Gregor92e986e2010-04-22 16:44:27 +00002374 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002375 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002376 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002377 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002378 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002379 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002380 MultiExprArg Args,
2381 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002382 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2383 ReceiverTypeInfo->getType(),
2384 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002385 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002386 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002387 }
2388
2389 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002390 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002391 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002392 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002393 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002394 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002395 MultiExprArg Args,
2396 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002397 return SemaRef.BuildInstanceMessage(Receiver,
2398 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002399 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002400 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002401 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002402 }
2403
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 /// \brief Build a new Objective-C ivar reference expression.
2405 ///
2406 /// By default, performs semantic analysis to build the new expression.
2407 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002408 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002409 SourceLocation IvarLoc,
2410 bool IsArrow, bool IsFreeIvar) {
2411 // FIXME: We lose track of the IsFreeIvar bit.
2412 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002413 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002414 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2415 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002417 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002418 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002419 false);
John Wiegley429bb272011-04-08 18:41:53 +00002420 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002421 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002422
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002423 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002424 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002425
John Wiegley429bb272011-04-08 18:41:53 +00002426 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002427 /*FIXME:*/IvarLoc, IsArrow,
2428 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002429 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002430 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002431 /*TemplateArgs=*/0);
2432 }
Douglas Gregore3303542010-04-26 20:47:02 +00002433
2434 /// \brief Build a new Objective-C property reference expression.
2435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002439 ObjCPropertyDecl *Property,
2440 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002441 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002442 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002443 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2444 Sema::LookupMemberName);
2445 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002446 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002447 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002448 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002449 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002450 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451
Douglas Gregore3303542010-04-26 20:47:02 +00002452 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002453 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454
John Wiegley429bb272011-04-08 18:41:53 +00002455 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002456 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002457 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002458 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002459 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002460 /*TemplateArgs=*/0);
2461 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002462
John McCall12f78a62010-12-02 01:19:52 +00002463 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002464 ///
2465 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002466 /// Subclasses may override this routine to provide different behavior.
2467 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2468 ObjCMethodDecl *Getter,
2469 ObjCMethodDecl *Setter,
2470 SourceLocation PropertyLoc) {
2471 // Since these expressions can only be value-dependent, we do not
2472 // need to perform semantic analysis again.
2473 return Owned(
2474 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2475 VK_LValue, OK_ObjCProperty,
2476 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002477 }
2478
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002479 /// \brief Build a new Objective-C "isa" expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002483 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002484 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002485 bool IsArrow) {
2486 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002487 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002488 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2489 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002490 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002491 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002492 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002493 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002494 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002496 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002497 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002498
John Wiegley429bb272011-04-08 18:41:53 +00002499 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002500 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002501 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002502 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 /*TemplateArgs=*/0);
2505 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002506
Douglas Gregorb98b1992009-08-11 05:31:07 +00002507 /// \brief Build a new shuffle vector expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002511 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002512 MultiExprArg SubExprs,
2513 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002514 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002515 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002516 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2517 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2518 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002519 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002520
Douglas Gregorb98b1992009-08-11 05:31:07 +00002521 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002522 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002523 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2524 SemaRef.Context.BuiltinFnTy,
2525 VK_RValue, BuiltinLoc);
2526 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2527 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2528 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002529
2530 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002531 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002532 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002533 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002534 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002535 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002536
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002538 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002539 }
John McCall43fed0d2010-11-12 08:19:04 +00002540
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002541 /// \brief Build a new template argument pack expansion.
2542 ///
2543 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002544 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002545 /// different behavior.
2546 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002547 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002548 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002549 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002550 case TemplateArgument::Expression: {
2551 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002552 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2553 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002554 if (Result.isInvalid())
2555 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002556
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002557 return TemplateArgumentLoc(Result.get(), Result.get());
2558 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002559
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002560 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002561 return TemplateArgumentLoc(TemplateArgument(
2562 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002563 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002564 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002565 Pattern.getTemplateNameLoc(),
2566 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002567
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002568 case TemplateArgument::Null:
2569 case TemplateArgument::Integral:
2570 case TemplateArgument::Declaration:
2571 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002572 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002573 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002574 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002575
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002577 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002578 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002579 EllipsisLoc,
2580 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002581 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2582 Expansion);
2583 break;
2584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002585
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002586 return TemplateArgumentLoc();
2587 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 /// \brief Build a new expression pack expansion.
2590 ///
2591 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002592 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002593 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002594 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002595 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002596 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002597 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002598
2599 /// \brief Build a new atomic operation expression.
2600 ///
2601 /// By default, performs semantic analysis to build the new expression.
2602 /// Subclasses may override this routine to provide different behavior.
2603 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2604 MultiExprArg SubExprs,
2605 QualType RetTy,
2606 AtomicExpr::AtomicOp Op,
2607 SourceLocation RParenLoc) {
2608 // Just create the expression; there is not any interesting semantic
2609 // analysis here because we can't actually build an AtomicExpr until
2610 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002611 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002612 RParenLoc);
2613 }
2614
John McCall43fed0d2010-11-12 08:19:04 +00002615private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002616 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2617 QualType ObjectType,
2618 NamedDecl *FirstQualifierInScope,
2619 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002620
2621 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2622 QualType ObjectType,
2623 NamedDecl *FirstQualifierInScope,
2624 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002626
Douglas Gregor43959a92009-08-20 07:17:43 +00002627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002628StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002629 if (!S)
2630 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002631
Douglas Gregor43959a92009-08-20 07:17:43 +00002632 switch (S->getStmtClass()) {
2633 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002634
Douglas Gregor43959a92009-08-20 07:17:43 +00002635 // Transform individual statement nodes
2636#define STMT(Node, Parent) \
2637 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002638#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002639#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002640#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002641
Douglas Gregor43959a92009-08-20 07:17:43 +00002642 // Transform expressions by calling TransformExpr.
2643#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002644#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002645#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002646#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002647 {
John McCall60d7b3a2010-08-24 06:29:42 +00002648 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002649 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002650 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002651
Richard Smith41956372013-01-14 22:39:08 +00002652 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002653 }
Mike Stump1eb44332009-09-09 15:08:12 +00002654 }
2655
John McCall3fa5cae2010-10-26 07:05:15 +00002656 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002657}
Mike Stump1eb44332009-09-09 15:08:12 +00002658
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002659template<typename Derived>
2660OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2661 if (!S)
2662 return S;
2663
2664 switch (S->getClauseKind()) {
2665 default: break;
2666 // Transform individual clause nodes
2667#define OPENMP_CLAUSE(Name, Class) \
2668 case OMPC_ ## Name : \
2669 return getDerived().Transform ## Class(cast<Class>(S));
2670#include "clang/Basic/OpenMPKinds.def"
2671 }
2672
2673 return S;
2674}
2675
Mike Stump1eb44332009-09-09 15:08:12 +00002676
Douglas Gregor670444e2009-08-04 22:27:00 +00002677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002678ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002679 if (!E)
2680 return SemaRef.Owned(E);
2681
2682 switch (E->getStmtClass()) {
2683 case Stmt::NoStmtClass: break;
2684#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002685#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002686#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002687 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002688#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002689 }
2690
John McCall3fa5cae2010-10-26 07:05:15 +00002691 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002692}
2693
2694template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002695ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2696 bool CXXDirectInit) {
2697 // Initializers are instantiated like expressions, except that various outer
2698 // layers are stripped.
2699 if (!Init)
2700 return SemaRef.Owned(Init);
2701
2702 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2703 Init = ExprTemp->getSubExpr();
2704
Richard Smith858c2c32013-05-30 22:40:16 +00002705 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2706 Init = MTE->GetTemporaryExpr();
2707
Richard Smithc83c2302012-12-19 01:39:02 +00002708 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2709 Init = Binder->getSubExpr();
2710
2711 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2712 Init = ICE->getSubExprAsWritten();
2713
Richard Smith7c3e6152013-06-12 22:31:48 +00002714 if (CXXStdInitializerListExpr *ILE =
2715 dyn_cast<CXXStdInitializerListExpr>(Init))
2716 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2717
Richard Smith5cf15892012-12-21 08:13:35 +00002718 // If this is not a direct-initializer, we only need to reconstruct
2719 // InitListExprs. Other forms of copy-initialization will be a no-op if
2720 // the initializer is already the right type.
2721 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2722 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2723 return getDerived().TransformExpr(Init);
2724
2725 // Revert value-initialization back to empty parens.
2726 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2727 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002728 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002729 Parens.getEnd());
2730 }
2731
2732 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2733 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002734 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002735 SourceLocation());
2736
2737 // Revert initialization by constructor back to a parenthesized or braced list
2738 // of expressions. Any other form of initializer can just be reused directly.
2739 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002740 return getDerived().TransformExpr(Init);
2741
2742 SmallVector<Expr*, 8> NewArgs;
2743 bool ArgChanged = false;
2744 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2745 /*IsCall*/true, NewArgs, &ArgChanged))
2746 return ExprError();
2747
2748 // If this was list initialization, revert to list form.
2749 if (Construct->isListInitialization())
2750 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2751 Construct->getLocEnd(),
2752 Construct->getType());
2753
Richard Smithc83c2302012-12-19 01:39:02 +00002754 // Build a ParenListExpr to represent anything else.
2755 SourceRange Parens = Construct->getParenRange();
2756 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2757 Parens.getEnd());
2758}
2759
2760template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2762 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002763 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002764 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002765 bool *ArgChanged) {
2766 for (unsigned I = 0; I != NumInputs; ++I) {
2767 // If requested, drop call arguments that need to be dropped.
2768 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2769 if (ArgChanged)
2770 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002771
Douglas Gregoraa165f82011-01-03 19:04:46 +00002772 break;
2773 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002774
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002775 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2776 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777
Chris Lattner686775d2011-07-20 06:58:45 +00002778 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002779 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2780 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002781
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002782 // Determine whether the set of unexpanded parameter packs can and should
2783 // be expanded.
2784 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002785 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002786 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2787 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002788 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2789 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002790 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002791 Expand, RetainExpansion,
2792 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002793 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002794
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002795 if (!Expand) {
2796 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002798 // expansion.
2799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2800 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2801 if (OutPattern.isInvalid())
2802 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002803
2804 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002805 Expansion->getEllipsisLoc(),
2806 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002807 if (Out.isInvalid())
2808 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002809
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002810 if (ArgChanged)
2811 *ArgChanged = true;
2812 Outputs.push_back(Out.get());
2813 continue;
2814 }
John McCallc8fc90a2011-07-06 07:30:07 +00002815
2816 // Record right away that the argument was changed. This needs
2817 // to happen even if the array expands to nothing.
2818 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002819
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002820 // The transform has determined that we should perform an elementwise
2821 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002822 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002823 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2824 ExprResult Out = getDerived().TransformExpr(Pattern);
2825 if (Out.isInvalid())
2826 return true;
2827
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002828 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002829 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2830 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002831 if (Out.isInvalid())
2832 return true;
2833 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002834
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002835 Outputs.push_back(Out.get());
2836 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002838 continue;
2839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002840
Richard Smithc83c2302012-12-19 01:39:02 +00002841 ExprResult Result =
2842 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2843 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002844 if (Result.isInvalid())
2845 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002846
Douglas Gregoraa165f82011-01-03 19:04:46 +00002847 if (Result.get() != Inputs[I] && ArgChanged)
2848 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849
2850 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852
Douglas Gregoraa165f82011-01-03 19:04:46 +00002853 return false;
2854}
2855
2856template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002857NestedNameSpecifierLoc
2858TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2859 NestedNameSpecifierLoc NNS,
2860 QualType ObjectType,
2861 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002862 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002863 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002864 Qualifier = Qualifier.getPrefix())
2865 Qualifiers.push_back(Qualifier);
2866
2867 CXXScopeSpec SS;
2868 while (!Qualifiers.empty()) {
2869 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2870 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002872 switch (QNNS->getKind()) {
2873 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002875 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002877 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002879 FirstQualifierInScope, false))
2880 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002882 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002883
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002884 case NestedNameSpecifier::Namespace: {
2885 NamespaceDecl *NS
2886 = cast_or_null<NamespaceDecl>(
2887 getDerived().TransformDecl(
2888 Q.getLocalBeginLoc(),
2889 QNNS->getAsNamespace()));
2890 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2891 break;
2892 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002893
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002894 case NestedNameSpecifier::NamespaceAlias: {
2895 NamespaceAliasDecl *Alias
2896 = cast_or_null<NamespaceAliasDecl>(
2897 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2898 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002900 Q.getLocalEndLoc());
2901 break;
2902 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002903
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002904 case NestedNameSpecifier::Global:
2905 // There is no meaningful transformation that one could perform on the
2906 // global scope.
2907 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2908 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002910 case NestedNameSpecifier::TypeSpecWithTemplate:
2911 case NestedNameSpecifier::TypeSpec: {
2912 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2913 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002914
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002915 if (!TL)
2916 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002919 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002920 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002921 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002922 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002923 if (TL.getType()->isEnumeralType())
2924 SemaRef.Diag(TL.getBeginLoc(),
2925 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002926 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2927 Q.getLocalEndLoc());
2928 break;
2929 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002930 // If the nested-name-specifier is an invalid type def, don't emit an
2931 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002932 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2933 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002935 << TL.getType() << SS.getRange();
2936 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002937 return NestedNameSpecifierLoc();
2938 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002941 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002943 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002946 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002948 !getDerived().AlwaysRebuild())
2949 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950
2951 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002952 // nested-name-specifier, do so.
2953 if (SS.location_size() == NNS.getDataLength() &&
2954 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2955 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2956
2957 // Allocate new nested-name-specifier location information.
2958 return SS.getWithLocInContext(SemaRef.Context);
2959}
2960
2961template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002962DeclarationNameInfo
2963TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002964::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002965 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002966 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002967 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002968
2969 switch (Name.getNameKind()) {
2970 case DeclarationName::Identifier:
2971 case DeclarationName::ObjCZeroArgSelector:
2972 case DeclarationName::ObjCOneArgSelector:
2973 case DeclarationName::ObjCMultiArgSelector:
2974 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002975 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002976 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002977 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002978
Douglas Gregor81499bb2009-09-03 22:13:48 +00002979 case DeclarationName::CXXConstructorName:
2980 case DeclarationName::CXXDestructorName:
2981 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002982 TypeSourceInfo *NewTInfo;
2983 CanQualType NewCanTy;
2984 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002985 NewTInfo = getDerived().TransformType(OldTInfo);
2986 if (!NewTInfo)
2987 return DeclarationNameInfo();
2988 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002989 }
2990 else {
2991 NewTInfo = 0;
2992 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002993 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002994 if (NewT.isNull())
2995 return DeclarationNameInfo();
2996 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2997 }
Mike Stump1eb44332009-09-09 15:08:12 +00002998
Abramo Bagnara25777432010-08-11 22:01:17 +00002999 DeclarationName NewName
3000 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3001 NewCanTy);
3002 DeclarationNameInfo NewNameInfo(NameInfo);
3003 NewNameInfo.setName(NewName);
3004 NewNameInfo.setNamedTypeInfo(NewTInfo);
3005 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003006 }
Mike Stump1eb44332009-09-09 15:08:12 +00003007 }
3008
David Blaikieb219cfc2011-09-23 05:06:16 +00003009 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003010}
3011
3012template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003013TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003014TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3015 TemplateName Name,
3016 SourceLocation NameLoc,
3017 QualType ObjectType,
3018 NamedDecl *FirstQualifierInScope) {
3019 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3020 TemplateDecl *Template = QTN->getTemplateDecl();
3021 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003022
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003023 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003024 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003025 Template));
3026 if (!TransTemplate)
3027 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003028
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003029 if (!getDerived().AlwaysRebuild() &&
3030 SS.getScopeRep() == QTN->getQualifier() &&
3031 TransTemplate == Template)
3032 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003033
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003034 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3035 TransTemplate);
3036 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003037
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003038 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3039 if (SS.getScopeRep()) {
3040 // These apply to the scope specifier, not the template.
3041 ObjectType = QualType();
3042 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003043 }
3044
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003045 if (!getDerived().AlwaysRebuild() &&
3046 SS.getScopeRep() == DTN->getQualifier() &&
3047 ObjectType.isNull())
3048 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003050 if (DTN->isIdentifier()) {
3051 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003053 NameLoc,
3054 ObjectType,
3055 FirstQualifierInScope);
3056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3059 ObjectType);
3060 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003062 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3063 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003064 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003065 Template));
3066 if (!TransTemplate)
3067 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003068
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 if (!getDerived().AlwaysRebuild() &&
3070 TransTemplate == Template)
3071 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003073 return TemplateName(TransTemplate);
3074 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003075
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003076 if (SubstTemplateTemplateParmPackStorage *SubstPack
3077 = Name.getAsSubstTemplateTemplateParmPack()) {
3078 TemplateTemplateParmDecl *TransParam
3079 = cast_or_null<TemplateTemplateParmDecl>(
3080 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3081 if (!TransParam)
3082 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003083
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003084 if (!getDerived().AlwaysRebuild() &&
3085 TransParam == SubstPack->getParameterPack())
3086 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003087
3088 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003089 SubstPack->getArgumentPack());
3090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003091
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003092 // These should be getting filtered out before they reach the AST.
3093 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003094}
3095
3096template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003097void TreeTransform<Derived>::InventTemplateArgumentLoc(
3098 const TemplateArgument &Arg,
3099 TemplateArgumentLoc &Output) {
3100 SourceLocation Loc = getDerived().getBaseLocation();
3101 switch (Arg.getKind()) {
3102 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003103 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003104 break;
3105
3106 case TemplateArgument::Type:
3107 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003108 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
John McCall833ca992009-10-29 08:12:44 +00003110 break;
3111
Douglas Gregor788cd062009-11-11 01:00:40 +00003112 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003113 case TemplateArgument::TemplateExpansion: {
3114 NestedNameSpecifierLocBuilder Builder;
3115 TemplateName Template = Arg.getAsTemplate();
3116 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3117 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3118 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3119 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003121 if (Arg.getKind() == TemplateArgument::Template)
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);
3125 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003127 Builder.getWithLocInContext(SemaRef.Context),
3128 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor788cd062009-11-11 01:00:40 +00003130 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003131 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003132
John McCall833ca992009-10-29 08:12:44 +00003133 case TemplateArgument::Expression:
3134 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3135 break;
3136
3137 case TemplateArgument::Declaration:
3138 case TemplateArgument::Integral:
3139 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003140 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003141 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003142 break;
3143 }
3144}
3145
3146template<typename Derived>
3147bool TreeTransform<Derived>::TransformTemplateArgument(
3148 const TemplateArgumentLoc &Input,
3149 TemplateArgumentLoc &Output) {
3150 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003151 switch (Arg.getKind()) {
3152 case TemplateArgument::Null:
3153 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003154 case TemplateArgument::Pack:
3155 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003156 case TemplateArgument::NullPtr:
3157 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003158
Douglas Gregor670444e2009-08-04 22:27:00 +00003159 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003160 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003161 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003162 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003163
3164 DI = getDerived().TransformType(DI);
3165 if (!DI) return true;
3166
3167 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3168 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003169 }
Mike Stump1eb44332009-09-09 15:08:12 +00003170
Douglas Gregor788cd062009-11-11 01:00:40 +00003171 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003172 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3173 if (QualifierLoc) {
3174 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3175 if (!QualifierLoc)
3176 return true;
3177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003178
Douglas Gregor1d752d72011-03-02 18:46:51 +00003179 CXXScopeSpec SS;
3180 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003181 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003182 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3183 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003184 if (Template.isNull())
3185 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003187 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003188 Input.getTemplateNameLoc());
3189 return false;
3190 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003191
3192 case TemplateArgument::TemplateExpansion:
3193 llvm_unreachable("Caller should expand pack expansions");
3194
Douglas Gregor670444e2009-08-04 22:27:00 +00003195 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003196 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003197 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003198 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003199
John McCall833ca992009-10-29 08:12:44 +00003200 Expr *InputExpr = Input.getSourceExpression();
3201 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3202
Chris Lattner223de242011-04-25 20:37:58 +00003203 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003204 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003205 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003206 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003207 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003208 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003209 }
Mike Stump1eb44332009-09-09 15:08:12 +00003210
Douglas Gregor670444e2009-08-04 22:27:00 +00003211 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003212 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003213}
3214
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003215/// \brief Iterator adaptor that invents template argument location information
3216/// for each of the template arguments in its underlying iterator.
3217template<typename Derived, typename InputIterator>
3218class TemplateArgumentLocInventIterator {
3219 TreeTransform<Derived> &Self;
3220 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003221
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003222public:
3223 typedef TemplateArgumentLoc value_type;
3224 typedef TemplateArgumentLoc reference;
3225 typedef typename std::iterator_traits<InputIterator>::difference_type
3226 difference_type;
3227 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003229 class pointer {
3230 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003231
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003232 public:
3233 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003235 const TemplateArgumentLoc *operator->() const { return &Arg; }
3236 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003238 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003240 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3241 InputIterator Iter)
3242 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003244 TemplateArgumentLocInventIterator &operator++() {
3245 ++Iter;
3246 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003249 TemplateArgumentLocInventIterator operator++(int) {
3250 TemplateArgumentLocInventIterator Old(*this);
3251 ++(*this);
3252 return Old;
3253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003255 reference operator*() const {
3256 TemplateArgumentLoc Result;
3257 Self.InventTemplateArgumentLoc(*Iter, Result);
3258 return Result;
3259 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003261 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003263 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3264 const TemplateArgumentLocInventIterator &Y) {
3265 return X.Iter == Y.Iter;
3266 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003267
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003268 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3269 const TemplateArgumentLocInventIterator &Y) {
3270 return X.Iter != Y.Iter;
3271 }
3272};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003273
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003274template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003275template<typename InputIterator>
3276bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3277 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003278 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003280 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003281 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003282
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003283 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3284 // Unpack argument packs, which we translate them into separate
3285 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003286 // FIXME: We could do much better if we could guarantee that the
3287 // TemplateArgumentLocInfo for the pack expansion would be usable for
3288 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003289 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003290 TemplateArgument::pack_iterator>
3291 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003292 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003293 In.getArgument().pack_begin()),
3294 PackLocIterator(*this,
3295 In.getArgument().pack_end()),
3296 Outputs))
3297 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003298
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003299 continue;
3300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003301
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003302 if (In.getArgument().isPackExpansion()) {
3303 // We have a pack expansion, for which we will be substituting into
3304 // the pattern.
3305 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003306 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003308 = getSema().getTemplateArgumentPackExpansionPattern(
3309 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003310
Chris Lattner686775d2011-07-20 06:58:45 +00003311 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003312 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3313 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003314
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003315 // Determine whether the set of unexpanded parameter packs can and should
3316 // be expanded.
3317 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003318 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003319 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003320 if (getDerived().TryExpandParameterPacks(Ellipsis,
3321 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003322 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003323 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003324 RetainExpansion,
3325 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003326 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003327
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003328 if (!Expand) {
3329 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003330 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003331 // expansion.
3332 TemplateArgumentLoc OutPattern;
3333 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3334 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3335 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003336
Douglas Gregorcded4f62011-01-14 17:04:44 +00003337 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3338 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003339 if (Out.getArgument().isNull())
3340 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003341
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003342 Outputs.addArgument(Out);
3343 continue;
3344 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003345
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003346 // The transform has determined that we should perform an elementwise
3347 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003348 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003349 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3350
3351 if (getDerived().TransformTemplateArgument(Pattern, Out))
3352 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003353
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003354 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003355 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3356 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003357 if (Out.getArgument().isNull())
3358 return true;
3359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003361 Outputs.addArgument(Out);
3362 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003363
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003364 // If we're supposed to retain a pack expansion, do so by temporarily
3365 // forgetting the partially-substituted parameter pack.
3366 if (RetainExpansion) {
3367 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003368
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003369 if (getDerived().TransformTemplateArgument(Pattern, Out))
3370 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371
Douglas Gregorcded4f62011-01-14 17:04:44 +00003372 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3373 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003374 if (Out.getArgument().isNull())
3375 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003376
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003377 Outputs.addArgument(Out);
3378 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003379
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003380 continue;
3381 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003382
3383 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003384 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003385 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003386
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003387 Outputs.addArgument(Out);
3388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003389
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003390 return false;
3391
3392}
3393
Douglas Gregor577f75a2009-08-04 16:50:30 +00003394//===----------------------------------------------------------------------===//
3395// Type transformation
3396//===----------------------------------------------------------------------===//
3397
3398template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003399QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003400 if (getDerived().AlreadyTransformed(T))
3401 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003402
John McCalla2becad2009-10-21 00:40:46 +00003403 // Temporary workaround. All of these transformations should
3404 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003405 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3406 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407
John McCall43fed0d2010-11-12 08:19:04 +00003408 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003409
John McCalla2becad2009-10-21 00:40:46 +00003410 if (!NewDI)
3411 return QualType();
3412
3413 return NewDI->getType();
3414}
3415
3416template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003417TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003418 // Refine the base location to the type's location.
3419 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3420 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003421 if (getDerived().AlreadyTransformed(DI->getType()))
3422 return DI;
3423
3424 TypeLocBuilder TLB;
3425
3426 TypeLoc TL = DI->getTypeLoc();
3427 TLB.reserve(TL.getFullDataSize());
3428
John McCall43fed0d2010-11-12 08:19:04 +00003429 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003430 if (Result.isNull())
3431 return 0;
3432
John McCalla93c9342009-12-07 02:54:59 +00003433 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003434}
3435
3436template<typename Derived>
3437QualType
John McCall43fed0d2010-11-12 08:19:04 +00003438TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003439 switch (T.getTypeLocClass()) {
3440#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003441#define TYPELOC(CLASS, PARENT) \
3442 case TypeLoc::CLASS: \
3443 return getDerived().Transform##CLASS##Type(TLB, \
3444 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003445#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003446 }
Mike Stump1eb44332009-09-09 15:08:12 +00003447
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003448 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003449}
3450
3451/// FIXME: By default, this routine adds type qualifiers only to types
3452/// that can have qualifiers, and silently suppresses those qualifiers
3453/// that are not permitted (e.g., qualifiers on reference or function
3454/// types). This is the right thing for template instantiation, but
3455/// probably not for other clients.
3456template<typename Derived>
3457QualType
3458TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003459 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003460 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003461
John McCall43fed0d2010-11-12 08:19:04 +00003462 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003463 if (Result.isNull())
3464 return QualType();
3465
3466 // Silently suppress qualifiers if the result type can't be qualified.
3467 // FIXME: this is the right thing for template instantiation, but
3468 // probably not for other clients.
3469 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003470 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003471
John McCallf85e1932011-06-15 23:02:42 +00003472 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003473 // resulting type.
3474 if (Quals.hasObjCLifetime()) {
3475 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3476 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003477 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003479 // A lifetime qualifier applied to a substituted template parameter
3480 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003481 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003482 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003483 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3484 QualType Replacement = SubstTypeParam->getReplacementType();
3485 Qualifiers Qs = Replacement.getQualifiers();
3486 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003488 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3489 Qs);
3490 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003492 Replacement);
3493 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003494 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3495 // 'auto' types behave the same way as template parameters.
3496 QualType Deduced = AutoTy->getDeducedType();
3497 Qualifiers Qs = Deduced.getQualifiers();
3498 Qs.removeObjCLifetime();
3499 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3500 Qs);
Manuel Klimek152b4e42013-08-22 12:12:24 +00003501 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003502 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003503 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003504 // Otherwise, complain about the addition of a qualifier to an
3505 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003506 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003507 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003508 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003509
Douglas Gregore559ca12011-06-17 22:11:49 +00003510 Quals.removeObjCLifetime();
3511 }
3512 }
3513 }
John McCall28654742010-06-05 06:41:15 +00003514 if (!Quals.empty()) {
3515 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003516 // BuildQualifiedType might not add qualifiers if they are invalid.
3517 if (Result.hasLocalQualifiers())
3518 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003519 // No location information to preserve.
3520 }
John McCalla2becad2009-10-21 00:40:46 +00003521
3522 return Result;
3523}
3524
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003525template<typename Derived>
3526TypeLoc
3527TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3528 QualType ObjectType,
3529 NamedDecl *UnqualLookup,
3530 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003531 QualType T = TL.getType();
3532 if (getDerived().AlreadyTransformed(T))
3533 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003535 TypeLocBuilder TLB;
3536 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003538 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003539 TemplateSpecializationTypeLoc SpecTL =
3540 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003542 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003543 getDerived().TransformTemplateName(SS,
3544 SpecTL.getTypePtr()->getTemplateName(),
3545 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003546 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003548 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003549
3550 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003551 Template);
3552 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003553 DependentTemplateSpecializationTypeLoc SpecTL =
3554 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555
Douglas Gregora88f09f2011-02-28 17:23:35 +00003556 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557 = getDerived().RebuildTemplateName(SS,
3558 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003559 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003560 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003561 if (Template.isNull())
3562 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003563
3564 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003565 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003566 Template,
3567 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003568 } else {
3569 // Nothing special needs to be done for these.
3570 Result = getDerived().TransformType(TLB, TL);
3571 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572
3573 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003574 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3577}
3578
Douglas Gregorb71d8212011-03-02 18:32:08 +00003579template<typename Derived>
3580TypeSourceInfo *
3581TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3582 QualType ObjectType,
3583 NamedDecl *UnqualLookup,
3584 CXXScopeSpec &SS) {
3585 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003586
Douglas Gregorb71d8212011-03-02 18:32:08 +00003587 QualType T = TSInfo->getType();
3588 if (getDerived().AlreadyTransformed(T))
3589 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003590
Douglas Gregorb71d8212011-03-02 18:32:08 +00003591 TypeLocBuilder TLB;
3592 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593
Douglas Gregorb71d8212011-03-02 18:32:08 +00003594 TypeLoc TL = TSInfo->getTypeLoc();
3595 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003596 TemplateSpecializationTypeLoc SpecTL =
3597 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003598
Douglas Gregorb71d8212011-03-02 18:32:08 +00003599 TemplateName Template
3600 = getDerived().TransformTemplateName(SS,
3601 SpecTL.getTypePtr()->getTemplateName(),
3602 SpecTL.getTemplateNameLoc(),
3603 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003604 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003605 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
3607 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003608 Template);
3609 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003610 DependentTemplateSpecializationTypeLoc SpecTL =
3611 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003612
Douglas Gregorb71d8212011-03-02 18:32:08 +00003613 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614 = getDerived().RebuildTemplateName(SS,
3615 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003616 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003617 ObjectType, UnqualLookup);
3618 if (Template.isNull())
3619 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620
3621 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003622 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003623 Template,
3624 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003625 } else {
3626 // Nothing special needs to be done for these.
3627 Result = getDerived().TransformType(TLB, TL);
3628 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003629
3630 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003631 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003632
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3634}
3635
John McCalla2becad2009-10-21 00:40:46 +00003636template <class TyLoc> static inline
3637QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3638 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3639 NewT.setNameLoc(T.getNameLoc());
3640 return T.getType();
3641}
3642
John McCalla2becad2009-10-21 00:40:46 +00003643template<typename Derived>
3644QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003645 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003646 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3647 NewT.setBuiltinLoc(T.getBuiltinLoc());
3648 if (T.needsExtraLocalData())
3649 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3650 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651}
Mike Stump1eb44332009-09-09 15:08:12 +00003652
Douglas Gregor577f75a2009-08-04 16:50:30 +00003653template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003654QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003655 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003656 // FIXME: recurse?
3657 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658}
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003661QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3662 DecayedTypeLoc TL) {
3663 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3664 if (OriginalType.isNull())
3665 return QualType();
3666
3667 QualType Result = TL.getType();
3668 if (getDerived().AlwaysRebuild() ||
3669 OriginalType != TL.getOriginalLoc().getType())
3670 Result = SemaRef.Context.getDecayedType(OriginalType);
3671 TLB.push<DecayedTypeLoc>(Result);
3672 // Nothing to set for DecayedTypeLoc.
3673 return Result;
3674}
3675
3676template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003677QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003678 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003679 QualType PointeeType
3680 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003681 if (PointeeType.isNull())
3682 return QualType();
3683
3684 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003685 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003686 // A dependent pointer type 'T *' has is being transformed such
3687 // that an Objective-C class type is being replaced for 'T'. The
3688 // resulting pointer type is an ObjCObjectPointerType, not a
3689 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003690 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003691
John McCallc12c5bb2010-05-15 11:32:37 +00003692 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3693 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003694 return Result;
3695 }
John McCall43fed0d2010-11-12 08:19:04 +00003696
Douglas Gregor92e986e2010-04-22 16:44:27 +00003697 if (getDerived().AlwaysRebuild() ||
3698 PointeeType != TL.getPointeeLoc().getType()) {
3699 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3700 if (Result.isNull())
3701 return QualType();
3702 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003703
John McCallf85e1932011-06-15 23:02:42 +00003704 // Objective-C ARC can add lifetime qualifiers to the type that we're
3705 // pointing to.
3706 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003707
Douglas Gregor92e986e2010-04-22 16:44:27 +00003708 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3709 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003710 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003711}
Mike Stump1eb44332009-09-09 15:08:12 +00003712
3713template<typename Derived>
3714QualType
John McCalla2becad2009-10-21 00:40:46 +00003715TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003716 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003717 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003718 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3719 if (PointeeType.isNull())
3720 return QualType();
3721
3722 QualType Result = TL.getType();
3723 if (getDerived().AlwaysRebuild() ||
3724 PointeeType != TL.getPointeeLoc().getType()) {
3725 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003726 TL.getSigilLoc());
3727 if (Result.isNull())
3728 return QualType();
3729 }
3730
Douglas Gregor39968ad2010-04-22 16:50:51 +00003731 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003732 NewT.setSigilLoc(TL.getSigilLoc());
3733 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734}
3735
John McCall85737a72009-10-30 00:06:24 +00003736/// Transforms a reference type. Note that somewhat paradoxically we
3737/// don't care whether the type itself is an l-value type or an r-value
3738/// type; we only care if the type was *written* as an l-value type
3739/// or an r-value type.
3740template<typename Derived>
3741QualType
3742TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003743 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003744 const ReferenceType *T = TL.getTypePtr();
3745
3746 // Note that this works with the pointee-as-written.
3747 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3748 if (PointeeType.isNull())
3749 return QualType();
3750
3751 QualType Result = TL.getType();
3752 if (getDerived().AlwaysRebuild() ||
3753 PointeeType != T->getPointeeTypeAsWritten()) {
3754 Result = getDerived().RebuildReferenceType(PointeeType,
3755 T->isSpelledAsLValue(),
3756 TL.getSigilLoc());
3757 if (Result.isNull())
3758 return QualType();
3759 }
3760
John McCallf85e1932011-06-15 23:02:42 +00003761 // Objective-C ARC can add lifetime qualifiers to the type that we're
3762 // referring to.
3763 TLB.TypeWasModifiedSafely(
3764 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3765
John McCall85737a72009-10-30 00:06:24 +00003766 // r-value references can be rebuilt as l-value references.
3767 ReferenceTypeLoc NewTL;
3768 if (isa<LValueReferenceType>(Result))
3769 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3770 else
3771 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3772 NewTL.setSigilLoc(TL.getSigilLoc());
3773
3774 return Result;
3775}
3776
Mike Stump1eb44332009-09-09 15:08:12 +00003777template<typename Derived>
3778QualType
John McCalla2becad2009-10-21 00:40:46 +00003779TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003780 LValueReferenceTypeLoc TL) {
3781 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
3783
Mike Stump1eb44332009-09-09 15:08:12 +00003784template<typename Derived>
3785QualType
John McCalla2becad2009-10-21 00:40:46 +00003786TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 RValueReferenceTypeLoc TL) {
3788 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003789}
Mike Stump1eb44332009-09-09 15:08:12 +00003790
Douglas Gregor577f75a2009-08-04 16:50:30 +00003791template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003792QualType
John McCalla2becad2009-10-21 00:40:46 +00003793TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003794 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003795 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796 if (PointeeType.isNull())
3797 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003798
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003799 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3800 TypeSourceInfo* NewClsTInfo = 0;
3801 if (OldClsTInfo) {
3802 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3803 if (!NewClsTInfo)
3804 return QualType();
3805 }
3806
3807 const MemberPointerType *T = TL.getTypePtr();
3808 QualType OldClsType = QualType(T->getClass(), 0);
3809 QualType NewClsType;
3810 if (NewClsTInfo)
3811 NewClsType = NewClsTInfo->getType();
3812 else {
3813 NewClsType = getDerived().TransformType(OldClsType);
3814 if (NewClsType.isNull())
3815 return QualType();
3816 }
Mike Stump1eb44332009-09-09 15:08:12 +00003817
John McCalla2becad2009-10-21 00:40:46 +00003818 QualType Result = TL.getType();
3819 if (getDerived().AlwaysRebuild() ||
3820 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003821 NewClsType != OldClsType) {
3822 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003823 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003824 if (Result.isNull())
3825 return QualType();
3826 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003827
John McCalla2becad2009-10-21 00:40:46 +00003828 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3829 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003830 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003831
3832 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833}
3834
Mike Stump1eb44332009-09-09 15:08:12 +00003835template<typename Derived>
3836QualType
John McCalla2becad2009-10-21 00:40:46 +00003837TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003838 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003839 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003840 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003841 if (ElementType.isNull())
3842 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003843
John McCalla2becad2009-10-21 00:40:46 +00003844 QualType Result = TL.getType();
3845 if (getDerived().AlwaysRebuild() ||
3846 ElementType != T->getElementType()) {
3847 Result = getDerived().RebuildConstantArrayType(ElementType,
3848 T->getSizeModifier(),
3849 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003850 T->getIndexTypeCVRQualifiers(),
3851 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003852 if (Result.isNull())
3853 return QualType();
3854 }
Eli Friedman457a3772012-01-25 22:19:07 +00003855
3856 // We might have either a ConstantArrayType or a VariableArrayType now:
3857 // a ConstantArrayType is allowed to have an element type which is a
3858 // VariableArrayType if the type is dependent. Fortunately, all array
3859 // types have the same location layout.
3860 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003861 NewTL.setLBracketLoc(TL.getLBracketLoc());
3862 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003863
John McCalla2becad2009-10-21 00:40:46 +00003864 Expr *Size = TL.getSizeExpr();
3865 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003866 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3867 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003868 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003869 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003870 }
3871 NewTL.setSizeExpr(Size);
3872
3873 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874}
Mike Stump1eb44332009-09-09 15:08:12 +00003875
Douglas Gregor577f75a2009-08-04 16:50:30 +00003876template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003878 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003879 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003880 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003881 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003882 if (ElementType.isNull())
3883 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003884
John McCalla2becad2009-10-21 00:40:46 +00003885 QualType Result = TL.getType();
3886 if (getDerived().AlwaysRebuild() ||
3887 ElementType != T->getElementType()) {
3888 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003889 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003890 T->getIndexTypeCVRQualifiers(),
3891 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003892 if (Result.isNull())
3893 return QualType();
3894 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003895
John McCalla2becad2009-10-21 00:40:46 +00003896 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3897 NewTL.setLBracketLoc(TL.getLBracketLoc());
3898 NewTL.setRBracketLoc(TL.getRBracketLoc());
3899 NewTL.setSizeExpr(0);
3900
3901 return Result;
3902}
3903
3904template<typename Derived>
3905QualType
3906TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003907 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003908 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003909 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3910 if (ElementType.isNull())
3911 return QualType();
3912
John McCall60d7b3a2010-08-24 06:29:42 +00003913 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003914 = getDerived().TransformExpr(T->getSizeExpr());
3915 if (SizeResult.isInvalid())
3916 return QualType();
3917
John McCall9ae2f072010-08-23 23:25:46 +00003918 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003919
3920 QualType Result = TL.getType();
3921 if (getDerived().AlwaysRebuild() ||
3922 ElementType != T->getElementType() ||
3923 Size != T->getSizeExpr()) {
3924 Result = getDerived().RebuildVariableArrayType(ElementType,
3925 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003926 Size,
John McCalla2becad2009-10-21 00:40:46 +00003927 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003928 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003929 if (Result.isNull())
3930 return QualType();
3931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003932
John McCalla2becad2009-10-21 00:40:46 +00003933 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3934 NewTL.setLBracketLoc(TL.getLBracketLoc());
3935 NewTL.setRBracketLoc(TL.getRBracketLoc());
3936 NewTL.setSizeExpr(Size);
3937
3938 return Result;
3939}
3940
3941template<typename Derived>
3942QualType
3943TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003944 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003945 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003946 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3947 if (ElementType.isNull())
3948 return QualType();
3949
Richard Smithf6702a32011-12-20 02:08:33 +00003950 // Array bounds are constant expressions.
3951 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3952 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003953
John McCall3b657512011-01-19 10:06:00 +00003954 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3955 Expr *origSize = TL.getSizeExpr();
3956 if (!origSize) origSize = T->getSizeExpr();
3957
3958 ExprResult sizeResult
3959 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003960 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003961 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003962 return QualType();
3963
John McCall3b657512011-01-19 10:06:00 +00003964 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003965
3966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() ||
3968 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003969 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003970 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3971 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003972 size,
John McCalla2becad2009-10-21 00:40:46 +00003973 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003974 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003975 if (Result.isNull())
3976 return QualType();
3977 }
John McCalla2becad2009-10-21 00:40:46 +00003978
3979 // We might have any sort of array type now, but fortunately they
3980 // all have the same location layout.
3981 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3982 NewTL.setLBracketLoc(TL.getLBracketLoc());
3983 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003984 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003985
3986 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003987}
Mike Stump1eb44332009-09-09 15:08:12 +00003988
3989template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003990QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003991 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003992 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003993 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003994
3995 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003996 QualType ElementType = getDerived().TransformType(T->getElementType());
3997 if (ElementType.isNull())
3998 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003999
Richard Smithf6702a32011-12-20 02:08:33 +00004000 // Vector sizes are constant expressions.
4001 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4002 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004003
John McCall60d7b3a2010-08-24 06:29:42 +00004004 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004005 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004006 if (Size.isInvalid())
4007 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004008
John McCalla2becad2009-10-21 00:40:46 +00004009 QualType Result = TL.getType();
4010 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004011 ElementType != T->getElementType() ||
4012 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004013 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004014 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004015 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004016 if (Result.isNull())
4017 return QualType();
4018 }
John McCalla2becad2009-10-21 00:40:46 +00004019
4020 // Result might be dependent or not.
4021 if (isa<DependentSizedExtVectorType>(Result)) {
4022 DependentSizedExtVectorTypeLoc NewTL
4023 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4024 NewTL.setNameLoc(TL.getNameLoc());
4025 } else {
4026 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4027 NewTL.setNameLoc(TL.getNameLoc());
4028 }
4029
4030 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031}
Mike Stump1eb44332009-09-09 15:08:12 +00004032
4033template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004034QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004035 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004036 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004037 QualType ElementType = getDerived().TransformType(T->getElementType());
4038 if (ElementType.isNull())
4039 return QualType();
4040
John McCalla2becad2009-10-21 00:40:46 +00004041 QualType Result = TL.getType();
4042 if (getDerived().AlwaysRebuild() ||
4043 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004044 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004045 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004046 if (Result.isNull())
4047 return QualType();
4048 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004049
John McCalla2becad2009-10-21 00:40:46 +00004050 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4051 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004052
John McCalla2becad2009-10-21 00:40:46 +00004053 return Result;
4054}
4055
4056template<typename Derived>
4057QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004058 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004059 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004060 QualType ElementType = getDerived().TransformType(T->getElementType());
4061 if (ElementType.isNull())
4062 return QualType();
4063
4064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 ElementType != T->getElementType()) {
4067 Result = getDerived().RebuildExtVectorType(ElementType,
4068 T->getNumElements(),
4069 /*FIXME*/ SourceLocation());
4070 if (Result.isNull())
4071 return QualType();
4072 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004073
John McCalla2becad2009-10-21 00:40:46 +00004074 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4075 NewTL.setNameLoc(TL.getNameLoc());
4076
4077 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004078}
Mike Stump1eb44332009-09-09 15:08:12 +00004079
David Blaikiedc84cd52013-02-20 22:23:23 +00004080template <typename Derived>
4081ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4082 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4083 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004084 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004085 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004086
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004087 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004089 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004090 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004091 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004092
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 TypeLocBuilder TLB;
4094 TypeLoc NewTL = OldDI->getTypeLoc();
4095 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096
4097 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004098 OldExpansionTL.getPatternLoc());
4099 if (Result.isNull())
4100 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004101
4102 Result = RebuildPackExpansionType(Result,
4103 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004104 OldExpansionTL.getEllipsisLoc(),
4105 NumExpansions);
4106 if (Result.isNull())
4107 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004109 PackExpansionTypeLoc NewExpansionTL
4110 = TLB.push<PackExpansionTypeLoc>(Result);
4111 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4112 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4113 } else
4114 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004115 if (!NewDI)
4116 return 0;
4117
John McCallfb44de92011-05-01 22:35:37 +00004118 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004119 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004120
4121 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4122 OldParm->getDeclContext(),
4123 OldParm->getInnerLocStart(),
4124 OldParm->getLocation(),
4125 OldParm->getIdentifier(),
4126 NewDI->getType(),
4127 NewDI,
4128 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004129 /* DefArg */ NULL);
4130 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4131 OldParm->getFunctionScopeIndex() + indexAdjustment);
4132 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004133}
4134
4135template<typename Derived>
4136bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004137 TransformFunctionTypeParams(SourceLocation Loc,
4138 ParmVarDecl **Params, unsigned NumParams,
4139 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004140 SmallVectorImpl<QualType> &OutParamTypes,
4141 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004142 int indexAdjustment = 0;
4143
Douglas Gregora009b592011-01-07 00:20:55 +00004144 for (unsigned i = 0; i != NumParams; ++i) {
4145 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004146 assert(OldParm->getFunctionScopeIndex() == i);
4147
David Blaikiedc84cd52013-02-20 22:23:23 +00004148 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004149 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 if (OldParm->isParameterPack()) {
4151 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004152 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004153
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004155 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004156 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004157 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4158 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004159 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4160
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 // Determine whether we should expand the parameter packs.
4162 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004163 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004164 Optional<unsigned> OrigNumExpansions =
4165 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004166 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004167 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4168 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004169 Unexpanded,
4170 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004171 RetainExpansion,
4172 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 return true;
4174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004175
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 if (ShouldExpand) {
4177 // Expand the function parameter pack into multiple, separate
4178 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004179 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004180 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004182 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004183 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004184 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004185 OrigNumExpansions,
4186 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004187 if (!NewParm)
4188 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004189
Douglas Gregora009b592011-01-07 00:20:55 +00004190 OutParamTypes.push_back(NewParm->getType());
4191 if (PVars)
4192 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004193 }
Douglas Gregord3731192011-01-10 07:32:04 +00004194
4195 // If we're supposed to retain a pack expansion, do so by temporarily
4196 // forgetting the partially-substituted parameter pack.
4197 if (RetainExpansion) {
4198 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004199 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004200 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004201 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004202 OrigNumExpansions,
4203 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004204 if (!NewParm)
4205 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206
Douglas Gregord3731192011-01-10 07:32:04 +00004207 OutParamTypes.push_back(NewParm->getType());
4208 if (PVars)
4209 PVars->push_back(NewParm);
4210 }
4211
John McCallfb44de92011-05-01 22:35:37 +00004212 // The next parameter should have the same adjustment as the
4213 // last thing we pushed, but we post-incremented indexAdjustment
4214 // on every push. Also, if we push nothing, the adjustment should
4215 // go down by one.
4216 indexAdjustment--;
4217
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 // We're done with the pack expansion.
4219 continue;
4220 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221
4222 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004223 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004224 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4225 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004226 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004227 NumExpansions,
4228 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004229 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004230 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004231 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004232 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004233
John McCall21ef0fa2010-03-11 09:03:00 +00004234 if (!NewParm)
4235 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236
Douglas Gregora009b592011-01-07 00:20:55 +00004237 OutParamTypes.push_back(NewParm->getType());
4238 if (PVars)
4239 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004240 continue;
4241 }
John McCall21ef0fa2010-03-11 09:03:00 +00004242
4243 // Deal with the possibility that we don't have a parameter
4244 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004245 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004246 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004247 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004248 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004249 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004250 = dyn_cast<PackExpansionType>(OldType)) {
4251 // We have a function parameter pack that may need to be expanded.
4252 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004253 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004254 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255
Douglas Gregor603cfb42011-01-05 23:12:31 +00004256 // Determine whether we should expand the parameter packs.
4257 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004258 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004259 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004260 Unexpanded,
4261 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004262 RetainExpansion,
4263 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004264 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266
Douglas Gregor603cfb42011-01-05 23:12:31 +00004267 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004268 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004269 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004270 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004271 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4272 QualType NewType = getDerived().TransformType(Pattern);
4273 if (NewType.isNull())
4274 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004275
Douglas Gregora009b592011-01-07 00:20:55 +00004276 OutParamTypes.push_back(NewType);
4277 if (PVars)
4278 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 // We're done with the pack expansion.
4282 continue;
4283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004284
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004285 // If we're supposed to retain a pack expansion, do so by temporarily
4286 // forgetting the partially-substituted parameter pack.
4287 if (RetainExpansion) {
4288 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4289 QualType NewType = getDerived().TransformType(Pattern);
4290 if (NewType.isNull())
4291 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004292
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004293 OutParamTypes.push_back(NewType);
4294 if (PVars)
4295 PVars->push_back(0);
4296 }
Douglas Gregord3731192011-01-10 07:32:04 +00004297
Chad Rosier4a9d7952012-08-08 18:46:20 +00004298 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004299 // expansion.
4300 OldType = Expansion->getPattern();
4301 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004302 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4303 NewType = getDerived().TransformType(OldType);
4304 } else {
4305 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004307
Douglas Gregor603cfb42011-01-05 23:12:31 +00004308 if (NewType.isNull())
4309 return true;
4310
4311 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004312 NewType = getSema().Context.getPackExpansionType(NewType,
4313 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314
Douglas Gregora009b592011-01-07 00:20:55 +00004315 OutParamTypes.push_back(NewType);
4316 if (PVars)
4317 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004318 }
4319
John McCallfb44de92011-05-01 22:35:37 +00004320#ifndef NDEBUG
4321 if (PVars) {
4322 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4323 if (ParmVarDecl *parm = (*PVars)[i])
4324 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004325 }
John McCallfb44de92011-05-01 22:35:37 +00004326#endif
4327
4328 return false;
4329}
John McCall21ef0fa2010-03-11 09:03:00 +00004330
4331template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004332QualType
John McCalla2becad2009-10-21 00:40:46 +00004333TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004334 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004335 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4336}
4337
4338template<typename Derived>
4339QualType
4340TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4341 FunctionProtoTypeLoc TL,
4342 CXXRecordDecl *ThisContext,
4343 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004344 // Transform the parameters and return type.
4345 //
Richard Smithe6975e92012-04-17 00:58:00 +00004346 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004347 // When the function has a trailing return type, we instantiate the
4348 // parameters before the return type, since the return type can then refer
4349 // to the parameters themselves (via decltype, sizeof, etc.).
4350 //
Chris Lattner686775d2011-07-20 06:58:45 +00004351 SmallVector<QualType, 4> ParamTypes;
4352 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004353 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004354
Douglas Gregordab60ad2010-10-01 18:44:50 +00004355 QualType ResultType;
4356
Richard Smith9fbf3272012-08-14 22:51:13 +00004357 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004358 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004359 TL.getParmArray(),
4360 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004361 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004362 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004363 return QualType();
4364
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004365 {
4366 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004367 // If a declaration declares a member function or member function
4368 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004369 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004370 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004371 // declarator.
4372 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004373
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004374 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4375 if (ResultType.isNull())
4376 return QualType();
4377 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004378 }
4379 else {
4380 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4381 if (ResultType.isNull())
4382 return QualType();
4383
Chad Rosier4a9d7952012-08-08 18:46:20 +00004384 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004385 TL.getParmArray(),
4386 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004387 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004388 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004389 return QualType();
4390 }
4391
Richard Smithe6975e92012-04-17 00:58:00 +00004392 // FIXME: Need to transform the exception-specification too.
4393
John McCalla2becad2009-10-21 00:40:46 +00004394 QualType Result = TL.getType();
4395 if (getDerived().AlwaysRebuild() ||
4396 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004397 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004398 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004399 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004400 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004401 if (Result.isNull())
4402 return QualType();
4403 }
Mike Stump1eb44332009-09-09 15:08:12 +00004404
John McCalla2becad2009-10-21 00:40:46 +00004405 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004406 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004407 NewTL.setLParenLoc(TL.getLParenLoc());
4408 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004409 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004410 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4411 NewTL.setArg(i, ParamDecls[i]);
4412
4413 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414}
Mike Stump1eb44332009-09-09 15:08:12 +00004415
Douglas Gregor577f75a2009-08-04 16:50:30 +00004416template<typename Derived>
4417QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004418 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004419 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004420 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004421 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4422 if (ResultType.isNull())
4423 return QualType();
4424
4425 QualType Result = TL.getType();
4426 if (getDerived().AlwaysRebuild() ||
4427 ResultType != T->getResultType())
4428 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4429
4430 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004431 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004432 NewTL.setLParenLoc(TL.getLParenLoc());
4433 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004434 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004435
4436 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004437}
Mike Stump1eb44332009-09-09 15:08:12 +00004438
John McCalled976492009-12-04 22:46:56 +00004439template<typename Derived> QualType
4440TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004441 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004442 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004443 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004444 if (!D)
4445 return QualType();
4446
4447 QualType Result = TL.getType();
4448 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4449 Result = getDerived().RebuildUnresolvedUsingType(D);
4450 if (Result.isNull())
4451 return QualType();
4452 }
4453
4454 // We might get an arbitrary type spec type back. We should at
4455 // least always get a type spec type, though.
4456 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4457 NewTL.setNameLoc(TL.getNameLoc());
4458
4459 return Result;
4460}
4461
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004463QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004464 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004465 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004466 TypedefNameDecl *Typedef
4467 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4468 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004469 if (!Typedef)
4470 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCalla2becad2009-10-21 00:40:46 +00004472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() ||
4474 Typedef != T->getDecl()) {
4475 Result = getDerived().RebuildTypedefType(Typedef);
4476 if (Result.isNull())
4477 return QualType();
4478 }
Mike Stump1eb44332009-09-09 15:08:12 +00004479
John McCalla2becad2009-10-21 00:40:46 +00004480 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4481 NewTL.setNameLoc(TL.getNameLoc());
4482
4483 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004484}
Mike Stump1eb44332009-09-09 15:08:12 +00004485
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004487QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004488 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004489 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004490 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4491 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004492
John McCall60d7b3a2010-08-24 06:29:42 +00004493 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 if (E.isInvalid())
4495 return QualType();
4496
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004497 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4498 if (E.isInvalid())
4499 return QualType();
4500
John McCalla2becad2009-10-21 00:40:46 +00004501 QualType Result = TL.getType();
4502 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004503 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004504 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004505 if (Result.isNull())
4506 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004507 }
John McCalla2becad2009-10-21 00:40:46 +00004508 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004511 NewTL.setTypeofLoc(TL.getTypeofLoc());
4512 NewTL.setLParenLoc(TL.getLParenLoc());
4513 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004514
4515 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516}
Mike Stump1eb44332009-09-09 15:08:12 +00004517
4518template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004519QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004520 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004521 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4522 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4523 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
John McCalla2becad2009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004527 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4528 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004529 if (Result.isNull())
4530 return QualType();
4531 }
Mike Stump1eb44332009-09-09 15:08:12 +00004532
John McCalla2becad2009-10-21 00:40:46 +00004533 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004534 NewTL.setTypeofLoc(TL.getTypeofLoc());
4535 NewTL.setLParenLoc(TL.getLParenLoc());
4536 NewTL.setRParenLoc(TL.getRParenLoc());
4537 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004538
4539 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004540}
Mike Stump1eb44332009-09-09 15:08:12 +00004541
4542template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004543QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004544 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004545 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004546
Douglas Gregor670444e2009-08-04 22:27:00 +00004547 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004548 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4549 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCall60d7b3a2010-08-24 06:29:42 +00004551 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004552 if (E.isInvalid())
4553 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Richard Smith76f3f692012-02-22 02:04:18 +00004555 E = getSema().ActOnDecltypeExpression(E.take());
4556 if (E.isInvalid())
4557 return QualType();
4558
John McCalla2becad2009-10-21 00:40:46 +00004559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() ||
4561 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004562 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004563 if (Result.isNull())
4564 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565 }
John McCalla2becad2009-10-21 00:40:46 +00004566 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004567
John McCalla2becad2009-10-21 00:40:46 +00004568 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570
4571 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004572}
4573
4574template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004575QualType TreeTransform<Derived>::TransformUnaryTransformType(
4576 TypeLocBuilder &TLB,
4577 UnaryTransformTypeLoc TL) {
4578 QualType Result = TL.getType();
4579 if (Result->isDependentType()) {
4580 const UnaryTransformType *T = TL.getTypePtr();
4581 QualType NewBase =
4582 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4583 Result = getDerived().RebuildUnaryTransformType(NewBase,
4584 T->getUTTKind(),
4585 TL.getKWLoc());
4586 if (Result.isNull())
4587 return QualType();
4588 }
4589
4590 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4591 NewTL.setKWLoc(TL.getKWLoc());
4592 NewTL.setParensRange(TL.getParensRange());
4593 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4594 return Result;
4595}
4596
4597template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004598QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4599 AutoTypeLoc TL) {
4600 const AutoType *T = TL.getTypePtr();
4601 QualType OldDeduced = T->getDeducedType();
4602 QualType NewDeduced;
4603 if (!OldDeduced.isNull()) {
4604 NewDeduced = getDerived().TransformType(OldDeduced);
4605 if (NewDeduced.isNull())
4606 return QualType();
4607 }
4608
4609 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004610 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4611 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004612 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004613 if (Result.isNull())
4614 return QualType();
4615 }
4616
4617 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4618 NewTL.setNameLoc(TL.getNameLoc());
4619
4620 return Result;
4621}
4622
4623template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004624QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004625 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004626 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004627 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004628 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4629 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004630 if (!Record)
4631 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
John McCalla2becad2009-10-21 00:40:46 +00004633 QualType Result = TL.getType();
4634 if (getDerived().AlwaysRebuild() ||
4635 Record != T->getDecl()) {
4636 Result = getDerived().RebuildRecordType(Record);
4637 if (Result.isNull())
4638 return QualType();
4639 }
Mike Stump1eb44332009-09-09 15:08:12 +00004640
John McCalla2becad2009-10-21 00:40:46 +00004641 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4642 NewTL.setNameLoc(TL.getNameLoc());
4643
4644 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004645}
Mike Stump1eb44332009-09-09 15:08:12 +00004646
4647template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004648QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004649 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004650 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004651 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004652 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4653 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004654 if (!Enum)
4655 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004656
John McCalla2becad2009-10-21 00:40:46 +00004657 QualType Result = TL.getType();
4658 if (getDerived().AlwaysRebuild() ||
4659 Enum != T->getDecl()) {
4660 Result = getDerived().RebuildEnumType(Enum);
4661 if (Result.isNull())
4662 return QualType();
4663 }
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCalla2becad2009-10-21 00:40:46 +00004665 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4666 NewTL.setNameLoc(TL.getNameLoc());
4667
4668 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004669}
John McCall7da24312009-09-05 00:15:47 +00004670
John McCall3cb0ebd2010-03-10 03:28:59 +00004671template<typename Derived>
4672QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4673 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004674 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004675 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4676 TL.getTypePtr()->getDecl());
4677 if (!D) return QualType();
4678
4679 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4680 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4681 return T;
4682}
4683
Douglas Gregor577f75a2009-08-04 16:50:30 +00004684template<typename Derived>
4685QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004686 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004687 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004688 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004689}
4690
Mike Stump1eb44332009-09-09 15:08:12 +00004691template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004692QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004693 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004694 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004695 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004697 // Substitute into the replacement type, which itself might involve something
4698 // that needs to be transformed. This only tends to occur with default
4699 // template arguments of template template parameters.
4700 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4701 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4702 if (Replacement.isNull())
4703 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004705 // Always canonicalize the replacement type.
4706 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4707 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004708 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004709 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004711 // Propagate type-source information.
4712 SubstTemplateTypeParmTypeLoc NewTL
4713 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4714 NewTL.setNameLoc(TL.getNameLoc());
4715 return Result;
4716
John McCall49a832b2009-10-18 09:09:24 +00004717}
4718
4719template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004720QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4721 TypeLocBuilder &TLB,
4722 SubstTemplateTypeParmPackTypeLoc TL) {
4723 return TransformTypeSpecType(TLB, TL);
4724}
4725
4726template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004727QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004728 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004729 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004730 const TemplateSpecializationType *T = TL.getTypePtr();
4731
Douglas Gregor1d752d72011-03-02 18:46:51 +00004732 // The nested-name-specifier never matters in a TemplateSpecializationType,
4733 // because we can't have a dependent nested-name-specifier anyway.
4734 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004735 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004736 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4737 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004738 if (Template.isNull())
4739 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004740
John McCall43fed0d2010-11-12 08:19:04 +00004741 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4742}
4743
Eli Friedmanb001de72011-10-06 23:00:33 +00004744template<typename Derived>
4745QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4746 AtomicTypeLoc TL) {
4747 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4748 if (ValueType.isNull())
4749 return QualType();
4750
4751 QualType Result = TL.getType();
4752 if (getDerived().AlwaysRebuild() ||
4753 ValueType != TL.getValueLoc().getType()) {
4754 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4755 if (Result.isNull())
4756 return QualType();
4757 }
4758
4759 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4760 NewTL.setKWLoc(TL.getKWLoc());
4761 NewTL.setLParenLoc(TL.getLParenLoc());
4762 NewTL.setRParenLoc(TL.getRParenLoc());
4763
4764 return Result;
4765}
4766
Chad Rosier4a9d7952012-08-08 18:46:20 +00004767 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004768 /// container that provides a \c getArgLoc() member function.
4769 ///
4770 /// This iterator is intended to be used with the iterator form of
4771 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4772 template<typename ArgLocContainer>
4773 class TemplateArgumentLocContainerIterator {
4774 ArgLocContainer *Container;
4775 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004776
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004777 public:
4778 typedef TemplateArgumentLoc value_type;
4779 typedef TemplateArgumentLoc reference;
4780 typedef int difference_type;
4781 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004782
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004783 class pointer {
4784 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004785
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004786 public:
4787 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004788
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004789 const TemplateArgumentLoc *operator->() const {
4790 return &Arg;
4791 }
4792 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793
4794
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004795 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004797 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4798 unsigned Index)
4799 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004801 TemplateArgumentLocContainerIterator &operator++() {
4802 ++Index;
4803 return *this;
4804 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004806 TemplateArgumentLocContainerIterator operator++(int) {
4807 TemplateArgumentLocContainerIterator Old(*this);
4808 ++(*this);
4809 return Old;
4810 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004811
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004812 TemplateArgumentLoc operator*() const {
4813 return Container->getArgLoc(Index);
4814 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004816 pointer operator->() const {
4817 return pointer(Container->getArgLoc(Index));
4818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004821 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 return X.Container == Y.Container && X.Index == Y.Index;
4823 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004824
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004825 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004826 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004827 return !(X == Y);
4828 }
4829 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
4831
John McCall43fed0d2010-11-12 08:19:04 +00004832template <typename Derived>
4833QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4834 TypeLocBuilder &TLB,
4835 TemplateSpecializationTypeLoc TL,
4836 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004837 TemplateArgumentListInfo NewTemplateArgs;
4838 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4839 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004840 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4841 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004842 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004843 ArgIterator(TL, TL.getNumArgs()),
4844 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004845 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004846
John McCall833ca992009-10-29 08:12:44 +00004847 // FIXME: maybe don't rebuild if all the template arguments are the same.
4848
4849 QualType Result =
4850 getDerived().RebuildTemplateSpecializationType(Template,
4851 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004852 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004853
4854 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004855 // Specializations of template template parameters are represented as
4856 // TemplateSpecializationTypes, and substitution of type alias templates
4857 // within a dependent context can transform them into
4858 // DependentTemplateSpecializationTypes.
4859 if (isa<DependentTemplateSpecializationType>(Result)) {
4860 DependentTemplateSpecializationTypeLoc NewTL
4861 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004862 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004863 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004864 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004865 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004866 NewTL.setLAngleLoc(TL.getLAngleLoc());
4867 NewTL.setRAngleLoc(TL.getRAngleLoc());
4868 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4869 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4870 return Result;
4871 }
4872
John McCall833ca992009-10-29 08:12:44 +00004873 TemplateSpecializationTypeLoc NewTL
4874 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004875 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004876 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4877 NewTL.setLAngleLoc(TL.getLAngleLoc());
4878 NewTL.setRAngleLoc(TL.getRAngleLoc());
4879 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4880 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004881 }
Mike Stump1eb44332009-09-09 15:08:12 +00004882
John McCall833ca992009-10-29 08:12:44 +00004883 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004884}
Mike Stump1eb44332009-09-09 15:08:12 +00004885
Douglas Gregora88f09f2011-02-28 17:23:35 +00004886template <typename Derived>
4887QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4888 TypeLocBuilder &TLB,
4889 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004890 TemplateName Template,
4891 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004892 TemplateArgumentListInfo NewTemplateArgs;
4893 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4894 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4895 typedef TemplateArgumentLocContainerIterator<
4896 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004897 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004898 ArgIterator(TL, TL.getNumArgs()),
4899 NewTemplateArgs))
4900 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004901
Douglas Gregora88f09f2011-02-28 17:23:35 +00004902 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004903
Douglas Gregora88f09f2011-02-28 17:23:35 +00004904 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4905 QualType Result
4906 = getSema().Context.getDependentTemplateSpecializationType(
4907 TL.getTypePtr()->getKeyword(),
4908 DTN->getQualifier(),
4909 DTN->getIdentifier(),
4910 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004911
Douglas Gregora88f09f2011-02-28 17:23:35 +00004912 DependentTemplateSpecializationTypeLoc NewTL
4913 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004914 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004915 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004916 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004917 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004918 NewTL.setLAngleLoc(TL.getLAngleLoc());
4919 NewTL.setRAngleLoc(TL.getRAngleLoc());
4920 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4921 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4922 return Result;
4923 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004924
4925 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004926 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004927 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004928 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004929
Douglas Gregora88f09f2011-02-28 17:23:35 +00004930 if (!Result.isNull()) {
4931 /// FIXME: Wrap this in an elaborated-type-specifier?
4932 TemplateSpecializationTypeLoc NewTL
4933 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004934 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 NewTL.setLAngleLoc(TL.getLAngleLoc());
4937 NewTL.setRAngleLoc(TL.getRAngleLoc());
4938 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4939 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004941
Douglas Gregora88f09f2011-02-28 17:23:35 +00004942 return Result;
4943}
4944
Mike Stump1eb44332009-09-09 15:08:12 +00004945template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004946QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004947TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004948 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004949 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004950
Douglas Gregor9e876872011-03-01 18:12:44 +00004951 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004952 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004953 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004955 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4956 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004957 return QualType();
4958 }
Mike Stump1eb44332009-09-09 15:08:12 +00004959
John McCall43fed0d2010-11-12 08:19:04 +00004960 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4961 if (NamedT.isNull())
4962 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004963
Richard Smith3e4c6c42011-05-05 21:57:07 +00004964 // C++0x [dcl.type.elab]p2:
4965 // If the identifier resolves to a typedef-name or the simple-template-id
4966 // resolves to an alias template specialization, the
4967 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004968 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4969 if (const TemplateSpecializationType *TST =
4970 NamedT->getAs<TemplateSpecializationType>()) {
4971 TemplateName Template = TST->getTemplateName();
4972 if (TypeAliasTemplateDecl *TAT =
4973 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4974 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4975 diag::err_tag_reference_non_tag) << 4;
4976 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4977 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004978 }
4979 }
4980
John McCalla2becad2009-10-21 00:40:46 +00004981 QualType Result = TL.getType();
4982 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004983 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004984 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004985 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004987 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004988 if (Result.isNull())
4989 return QualType();
4990 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004991
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004992 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004994 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004995 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004996}
Mike Stump1eb44332009-09-09 15:08:12 +00004997
4998template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004999QualType TreeTransform<Derived>::TransformAttributedType(
5000 TypeLocBuilder &TLB,
5001 AttributedTypeLoc TL) {
5002 const AttributedType *oldType = TL.getTypePtr();
5003 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5004 if (modifiedType.isNull())
5005 return QualType();
5006
5007 QualType result = TL.getType();
5008
5009 // FIXME: dependent operand expressions?
5010 if (getDerived().AlwaysRebuild() ||
5011 modifiedType != oldType->getModifiedType()) {
5012 // TODO: this is really lame; we should really be rebuilding the
5013 // equivalent type from first principles.
5014 QualType equivalentType
5015 = getDerived().TransformType(oldType->getEquivalentType());
5016 if (equivalentType.isNull())
5017 return QualType();
5018 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5019 modifiedType,
5020 equivalentType);
5021 }
5022
5023 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5024 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5025 if (TL.hasAttrOperand())
5026 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5027 if (TL.hasAttrExprOperand())
5028 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5029 else if (TL.hasAttrEnumOperand())
5030 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5031
5032 return result;
5033}
5034
5035template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005036QualType
5037TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5038 ParenTypeLoc TL) {
5039 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5040 if (Inner.isNull())
5041 return QualType();
5042
5043 QualType Result = TL.getType();
5044 if (getDerived().AlwaysRebuild() ||
5045 Inner != TL.getInnerLoc().getType()) {
5046 Result = getDerived().RebuildParenType(Inner);
5047 if (Result.isNull())
5048 return QualType();
5049 }
5050
5051 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5052 NewTL.setLParenLoc(TL.getLParenLoc());
5053 NewTL.setRParenLoc(TL.getRParenLoc());
5054 return Result;
5055}
5056
5057template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005058QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005059 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005060 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005061
Douglas Gregor2494dd02011-03-01 01:34:45 +00005062 NestedNameSpecifierLoc QualifierLoc
5063 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5064 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005065 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005066
John McCall33500952010-06-11 00:33:02 +00005067 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005068 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005069 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005070 QualifierLoc,
5071 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005072 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005073 if (Result.isNull())
5074 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005075
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005076 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5077 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005078 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5079
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005080 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005081 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005082 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005083 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005084 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005085 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005086 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005087 NewTL.setNameLoc(TL.getNameLoc());
5088 }
John McCalla2becad2009-10-21 00:40:46 +00005089 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregor577f75a2009-08-04 16:50:30 +00005092template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005093QualType TreeTransform<Derived>::
5094 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005095 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005096 NestedNameSpecifierLoc QualifierLoc;
5097 if (TL.getQualifierLoc()) {
5098 QualifierLoc
5099 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5100 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005101 return QualType();
5102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005103
John McCall43fed0d2010-11-12 08:19:04 +00005104 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005105 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005106}
5107
5108template<typename Derived>
5109QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005110TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5111 DependentTemplateSpecializationTypeLoc TL,
5112 NestedNameSpecifierLoc QualifierLoc) {
5113 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005114
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005115 TemplateArgumentListInfo NewTemplateArgs;
5116 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5117 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005118
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005119 typedef TemplateArgumentLocContainerIterator<
5120 DependentTemplateSpecializationTypeLoc> ArgIterator;
5121 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5122 ArgIterator(TL, TL.getNumArgs()),
5123 NewTemplateArgs))
5124 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005125
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005126 QualType Result
5127 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5128 QualifierLoc,
5129 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005130 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005131 NewTemplateArgs);
5132 if (Result.isNull())
5133 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005134
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5136 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005137
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005138 // Copy information relevant to the template specialization.
5139 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005140 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005141 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005142 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005143 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5144 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005145 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005146 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005147
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005148 // Copy information relevant to the elaborated type.
5149 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005150 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005152 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5153 DependentTemplateSpecializationTypeLoc SpecTL
5154 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005155 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005156 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005157 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005158 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005159 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5160 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005161 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005162 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005163 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005164 TemplateSpecializationTypeLoc SpecTL
5165 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005166 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005167 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005168 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5169 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005171 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005172 }
5173 return Result;
5174}
5175
5176template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005177QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5178 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005179 QualType Pattern
5180 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005181 if (Pattern.isNull())
5182 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005183
5184 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005185 if (getDerived().AlwaysRebuild() ||
5186 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005187 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005188 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005189 TL.getEllipsisLoc(),
5190 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005191 if (Result.isNull())
5192 return QualType();
5193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005194
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005195 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5196 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5197 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005198}
5199
5200template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005201QualType
5202TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005203 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005204 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005205 TLB.pushFullCopy(TL);
5206 return TL.getType();
5207}
5208
5209template<typename Derived>
5210QualType
5211TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005212 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005213 // ObjCObjectType is never dependent.
5214 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005215 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005216}
Mike Stump1eb44332009-09-09 15:08:12 +00005217
5218template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005219QualType
5220TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005221 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005222 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005223 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005224 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005225}
5226
Douglas Gregor577f75a2009-08-04 16:50:30 +00005227//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005228// Statement transformation
5229//===----------------------------------------------------------------------===//
5230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005231StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005233 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005234}
5235
5236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005237StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005238TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5239 return getDerived().TransformCompoundStmt(S, false);
5240}
5241
5242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005243StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005244TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005246 Sema::CompoundScopeRAII CompoundScope(getSema());
5247
John McCall7114cba2010-08-27 19:56:05 +00005248 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005250 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5252 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005253 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005254 if (Result.isInvalid()) {
5255 // Immediately fail if this was a DeclStmt, since it's very
5256 // likely that this will cause problems for future statements.
5257 if (isa<DeclStmt>(*B))
5258 return StmtError();
5259
5260 // Otherwise, just keep processing substatements and fail later.
5261 SubStmtInvalid = true;
5262 continue;
5263 }
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5266 Statements.push_back(Result.takeAs<Stmt>());
5267 }
Mike Stump1eb44332009-09-09 15:08:12 +00005268
John McCall7114cba2010-08-27 19:56:05 +00005269 if (SubStmtInvalid)
5270 return StmtError();
5271
Douglas Gregor43959a92009-08-20 07:17:43 +00005272 if (!getDerived().AlwaysRebuild() &&
5273 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005274 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005275
5276 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005277 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 S->getRBracLoc(),
5279 IsStmtExpr);
5280}
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005283StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005284TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005286 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005287 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5288 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Eli Friedman264c1f82009-11-19 03:14:00 +00005290 // Transform the left-hand case value.
5291 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005292 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005293 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Eli Friedman264c1f82009-11-19 03:14:00 +00005296 // Transform the right-hand case value (for the GNU case-range extension).
5297 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005298 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005299 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005301 }
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Build the case statement.
5304 // Case statements are always rebuilt so that they will attached to their
5305 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005306 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005307 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005309 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 S->getColonLoc());
5311 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005315 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005320 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321}
5322
5323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005324StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005327 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331 // Default statements are always rebuilt
5332 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005333 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334}
Mike Stump1eb44332009-09-09 15:08:12 +00005335
Douglas Gregor43959a92009-08-20 07:17:43 +00005336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005337StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005338TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005339 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Chris Lattner57ad3782011-02-17 20:34:02 +00005343 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5344 S->getDecl());
5345 if (!LD)
5346 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005347
5348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005350 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005351 cast<LabelDecl>(LD), SourceLocation(),
5352 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353}
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005356StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005357TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5358 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5359 if (SubStmt.isInvalid())
5360 return StmtError();
5361
5362 // TODO: transform attributes
5363 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5364 return S;
5365
5366 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5367 S->getAttrs(),
5368 SubStmt.get());
5369}
5370
5371template<typename Derived>
5372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005376 VarDecl *ConditionVar = 0;
5377 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005378 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005379 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005380 getDerived().TransformDefinition(
5381 S->getConditionVariable()->getLocation(),
5382 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005383 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005385 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005386 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005387
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005388 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005390
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005391 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005392 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005393 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005394 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005395 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005397
John McCall9ae2f072010-08-23 23:25:46 +00005398 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005399 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005400 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401
John McCall9ae2f072010-08-23 23:25:46 +00005402 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5403 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005407 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005412 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005415
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005417 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005418 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 Then.get() == S->getThen() &&
5420 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005421 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005423 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005424 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005425 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005426}
5427
5428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005429StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005430TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005432 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005433 VarDecl *ConditionVar = 0;
5434 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005436 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005437 getDerived().TransformDefinition(
5438 S->getConditionVariable()->getLocation(),
5439 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005440 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005442 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005443 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005444
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005445 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005446 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005447 }
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005450 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005451 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005452 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005454 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005457 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005459 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005462 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5463 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor43959a92009-08-20 07:17:43 +00005466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005467StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005468TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005471 VarDecl *ConditionVar = 0;
5472 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005473 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005474 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005475 getDerived().TransformDefinition(
5476 S->getConditionVariable()->getLocation(),
5477 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005478 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005480 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005481 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005482
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005483 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005485
5486 if (S->getCond()) {
5487 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005488 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005489 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005490 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005491 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005492 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005493 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005494 }
Mike Stump1eb44332009-09-09 15:08:12 +00005495
John McCall9ae2f072010-08-23 23:25:46 +00005496 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5497 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005501 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005506 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005507 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005509 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005511 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005512 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005517TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005519 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005523 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005524 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005525 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005527
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (!getDerived().AlwaysRebuild() &&
5529 Cond.get() == S->getCond() &&
5530 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005532
John McCall9ae2f072010-08-23 23:25:46 +00005533 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5534 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005535 S->getRParenLoc());
5536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005542 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005544 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005548 VarDecl *ConditionVar = 0;
5549 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005551 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005552 getDerived().TransformDefinition(
5553 S->getConditionVariable()->getLocation(),
5554 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005555 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005557 } else {
5558 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005560 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005562
5563 if (S->getCond()) {
5564 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005566 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005567 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005568 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005569
John McCall9ae2f072010-08-23 23:25:46 +00005570 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005571 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005572 }
Mike Stump1eb44332009-09-09 15:08:12 +00005573
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005575 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005577
Douglas Gregor43959a92009-08-20 07:17:43 +00005578 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005579 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Richard Smith41956372013-01-14 22:39:08 +00005583 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005584 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005585 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005588 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005589 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005590 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005591
Douglas Gregor43959a92009-08-20 07:17:43 +00005592 if (!getDerived().AlwaysRebuild() &&
5593 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005594 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 Inc.get() == S->getInc() &&
5596 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005597 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregor43959a92009-08-20 07:17:43 +00005599 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005600 Init.get(), FullCond, ConditionVar,
5601 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005602}
5603
5604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005605StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005606TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005607 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5608 S->getLabel());
5609 if (!LD)
5610 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Douglas Gregor43959a92009-08-20 07:17:43 +00005612 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005613 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005614 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005615}
5616
5617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005618StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005619TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005620 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005621 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005622 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005623 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregor43959a92009-08-20 07:17:43 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005628
5629 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005630 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005631}
5632
5633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005634StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005635TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005636 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005637}
Mike Stump1eb44332009-09-09 15:08:12 +00005638
Douglas Gregor43959a92009-08-20 07:17:43 +00005639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005640StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005641TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005642 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005643}
Mike Stump1eb44332009-09-09 15:08:12 +00005644
Douglas Gregor43959a92009-08-20 07:17:43 +00005645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005646StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005647TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005648 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005649 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005651
Mike Stump1eb44332009-09-09 15:08:12 +00005652 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005653 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005654 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005655}
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregor43959a92009-08-20 07:17:43 +00005657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005658StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005660 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005661 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5663 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005664 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5665 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005666 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 if (Transformed != *D)
5670 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregor43959a92009-08-20 07:17:43 +00005672 Decls.push_back(Transformed);
5673 }
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005677
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005678 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005679}
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregor43959a92009-08-20 07:17:43 +00005681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005682StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005683TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005685 SmallVector<Expr*, 8> Constraints;
5686 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005687 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005688
John McCall60d7b3a2010-08-24 06:29:42 +00005689 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005690 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005691
5692 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005693
Anders Carlsson703e3942010-01-24 05:50:09 +00005694 // Go through the outputs.
5695 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005696 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005697
Anders Carlsson703e3942010-01-24 05:50:09 +00005698 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005699 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005700
Anders Carlsson703e3942010-01-24 05:50:09 +00005701 // Transform the output expr.
5702 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005703 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005704 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005705 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005706
Anders Carlsson703e3942010-01-24 05:50:09 +00005707 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
John McCall9ae2f072010-08-23 23:25:46 +00005709 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005711
Anders Carlsson703e3942010-01-24 05:50:09 +00005712 // Go through the inputs.
5713 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005714 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
Anders Carlsson703e3942010-01-24 05:50:09 +00005716 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005717 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Anders Carlsson703e3942010-01-24 05:50:09 +00005719 // Transform the input expr.
5720 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005721 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005722 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005723 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Anders Carlsson703e3942010-01-24 05:50:09 +00005725 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
John McCall9ae2f072010-08-23 23:25:46 +00005727 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005729
Anders Carlsson703e3942010-01-24 05:50:09 +00005730 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005731 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005732
5733 // Go through the clobbers.
5734 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005735 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005736
5737 // No need to transform the asm string literal.
5738 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005739 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5740 S->isVolatile(), S->getNumOutputs(),
5741 S->getNumInputs(), Names.data(),
5742 Constraints, Exprs, AsmString.get(),
5743 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005744}
5745
Chad Rosier8cd64b42012-06-11 20:47:18 +00005746template<typename Derived>
5747StmtResult
5748TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005749 ArrayRef<Token> AsmToks =
5750 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005751
John McCallaeeacf72013-05-03 00:10:13 +00005752 bool HadError = false, HadChange = false;
5753
5754 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5755 SmallVector<Expr*, 8> TransformedExprs;
5756 TransformedExprs.reserve(SrcExprs.size());
5757 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5758 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5759 if (!Result.isUsable()) {
5760 HadError = true;
5761 } else {
5762 HadChange |= (Result.get() != SrcExprs[i]);
5763 TransformedExprs.push_back(Result.take());
5764 }
5765 }
5766
5767 if (HadError) return StmtError();
5768 if (!HadChange && !getDerived().AlwaysRebuild())
5769 return Owned(S);
5770
Chad Rosier7bd092b2012-08-15 16:53:30 +00005771 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005772 AsmToks, S->getAsmString(),
5773 S->getNumOutputs(), S->getNumInputs(),
5774 S->getAllConstraints(), S->getClobbers(),
5775 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005776}
Douglas Gregor43959a92009-08-20 07:17:43 +00005777
5778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005780TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005781 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005782 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005783 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005784 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005785
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005786 // Transform the @catch statements (if present).
5787 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005788 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005789 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005791 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005793 if (Catch.get() != S->getCatchStmt(I))
5794 AnyCatchChanged = true;
5795 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005796 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005797
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005798 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005799 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005800 if (S->getFinallyStmt()) {
5801 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5802 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005803 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005804 }
5805
5806 // If nothing changed, just retain this statement.
5807 if (!getDerived().AlwaysRebuild() &&
5808 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005809 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005810 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005811 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005812
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005813 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005814 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005815 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005816}
Mike Stump1eb44332009-09-09 15:08:12 +00005817
Douglas Gregor43959a92009-08-20 07:17:43 +00005818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005819StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005820TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005821 // Transform the @catch parameter, if there is one.
5822 VarDecl *Var = 0;
5823 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5824 TypeSourceInfo *TSInfo = 0;
5825 if (FromVar->getTypeSourceInfo()) {
5826 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5827 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005830
Douglas Gregorbe270a02010-04-26 17:57:08 +00005831 QualType T;
5832 if (TSInfo)
5833 T = TSInfo->getType();
5834 else {
5835 T = getDerived().TransformType(FromVar->getType());
5836 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005837 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005839
Douglas Gregorbe270a02010-04-26 17:57:08 +00005840 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5841 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005842 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005843 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005844
John McCall60d7b3a2010-08-24 06:29:42 +00005845 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005847 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005848
5849 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005850 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005851 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005852}
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005855StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005856TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005857 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005859 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005860 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005861
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005862 // If nothing changed, just retain this statement.
5863 if (!getDerived().AlwaysRebuild() &&
5864 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005865 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005866
5867 // Build a new statement.
5868 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005869 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005870}
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005873StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005874TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005875 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005876 if (S->getThrowExpr()) {
5877 Operand = getDerived().TransformExpr(S->getThrowExpr());
5878 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005879 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005881
Douglas Gregord1377b22010-04-22 21:44:01 +00005882 if (!getDerived().AlwaysRebuild() &&
5883 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005884 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005885
John McCall9ae2f072010-08-23 23:25:46 +00005886 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005887}
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregor43959a92009-08-20 07:17:43 +00005889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005890StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005891TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005892 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005893 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005894 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005895 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005896 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005897 Object =
5898 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5899 Object.get());
5900 if (Object.isInvalid())
5901 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005902
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005903 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005904 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005905 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005906 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005907
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005908 // If nothing change, just retain the current statement.
5909 if (!getDerived().AlwaysRebuild() &&
5910 Object.get() == S->getSynchExpr() &&
5911 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005912 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005913
5914 // Build a new statement.
5915 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005916 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005917}
5918
5919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005920StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005921TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5922 ObjCAutoreleasePoolStmt *S) {
5923 // Transform the body.
5924 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5925 if (Body.isInvalid())
5926 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005927
John McCallf85e1932011-06-15 23:02:42 +00005928 // If nothing changed, just retain this statement.
5929 if (!getDerived().AlwaysRebuild() &&
5930 Body.get() == S->getSubStmt())
5931 return SemaRef.Owned(S);
5932
5933 // Build a new statement.
5934 return getDerived().RebuildObjCAutoreleasePoolStmt(
5935 S->getAtLoc(), Body.get());
5936}
5937
5938template<typename Derived>
5939StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005940TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005941 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005942 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005943 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005944 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005945 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005946
Douglas Gregorc3203e72010-04-22 23:10:45 +00005947 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005948 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005949 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005950 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005951
Douglas Gregorc3203e72010-04-22 23:10:45 +00005952 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005953 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005954 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005955 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005956
Douglas Gregorc3203e72010-04-22 23:10:45 +00005957 // If nothing changed, just retain this statement.
5958 if (!getDerived().AlwaysRebuild() &&
5959 Element.get() == S->getElement() &&
5960 Collection.get() == S->getCollection() &&
5961 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005962 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005963
Douglas Gregorc3203e72010-04-22 23:10:45 +00005964 // Build a new statement.
5965 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005966 Element.get(),
5967 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005968 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005969 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005970}
5971
5972
5973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005974StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005975TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5976 // Transform the exception declaration, if any.
5977 VarDecl *Var = 0;
5978 if (S->getExceptionDecl()) {
5979 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005980 TypeSourceInfo *T = getDerived().TransformType(
5981 ExceptionDecl->getTypeSourceInfo());
5982 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005983 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregor83cb9422010-09-09 17:09:21 +00005985 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005986 ExceptionDecl->getInnerLocStart(),
5987 ExceptionDecl->getLocation(),
5988 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005989 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005990 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005991 }
Mike Stump1eb44332009-09-09 15:08:12 +00005992
Douglas Gregor43959a92009-08-20 07:17:43 +00005993 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005994 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005995 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005996 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005997
Douglas Gregor43959a92009-08-20 07:17:43 +00005998 if (!getDerived().AlwaysRebuild() &&
5999 !Var &&
6000 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006001 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006002
6003 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6004 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006005 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006006}
Mike Stump1eb44332009-09-09 15:08:12 +00006007
Douglas Gregor43959a92009-08-20 07:17:43 +00006008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006010TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6011 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006012 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006013 = getDerived().TransformCompoundStmt(S->getTryBlock());
6014 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006015 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006016
Douglas Gregor43959a92009-08-20 07:17:43 +00006017 // Transform the handlers.
6018 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006019 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006020 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006021 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006022 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6023 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006024 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregor43959a92009-08-20 07:17:43 +00006026 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6027 Handlers.push_back(Handler.takeAs<Stmt>());
6028 }
Mike Stump1eb44332009-09-09 15:08:12 +00006029
Douglas Gregor43959a92009-08-20 07:17:43 +00006030 if (!getDerived().AlwaysRebuild() &&
6031 TryBlock.get() == S->getTryBlock() &&
6032 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006033 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006034
John McCall9ae2f072010-08-23 23:25:46 +00006035 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006036 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006037}
Mike Stump1eb44332009-09-09 15:08:12 +00006038
Richard Smithad762fc2011-04-14 22:09:26 +00006039template<typename Derived>
6040StmtResult
6041TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6042 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6043 if (Range.isInvalid())
6044 return StmtError();
6045
6046 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6047 if (BeginEnd.isInvalid())
6048 return StmtError();
6049
6050 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6051 if (Cond.isInvalid())
6052 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006053 if (Cond.get())
6054 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6055 if (Cond.isInvalid())
6056 return StmtError();
6057 if (Cond.get())
6058 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006059
6060 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6061 if (Inc.isInvalid())
6062 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006063 if (Inc.get())
6064 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006065
6066 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6067 if (LoopVar.isInvalid())
6068 return StmtError();
6069
6070 StmtResult NewStmt = S;
6071 if (getDerived().AlwaysRebuild() ||
6072 Range.get() != S->getRangeStmt() ||
6073 BeginEnd.get() != S->getBeginEndStmt() ||
6074 Cond.get() != S->getCond() ||
6075 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006076 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006077 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6078 S->getColonLoc(), Range.get(),
6079 BeginEnd.get(), Cond.get(),
6080 Inc.get(), LoopVar.get(),
6081 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006082 if (NewStmt.isInvalid())
6083 return StmtError();
6084 }
Richard Smithad762fc2011-04-14 22:09:26 +00006085
6086 StmtResult Body = getDerived().TransformStmt(S->getBody());
6087 if (Body.isInvalid())
6088 return StmtError();
6089
6090 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6091 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006092 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006093 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6094 S->getColonLoc(), Range.get(),
6095 BeginEnd.get(), Cond.get(),
6096 Inc.get(), LoopVar.get(),
6097 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006098 if (NewStmt.isInvalid())
6099 return StmtError();
6100 }
Richard Smithad762fc2011-04-14 22:09:26 +00006101
6102 if (NewStmt.get() == S)
6103 return SemaRef.Owned(S);
6104
6105 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6106}
6107
John Wiegley28bbe4b2011-04-28 01:08:34 +00006108template<typename Derived>
6109StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006110TreeTransform<Derived>::TransformMSDependentExistsStmt(
6111 MSDependentExistsStmt *S) {
6112 // Transform the nested-name-specifier, if any.
6113 NestedNameSpecifierLoc QualifierLoc;
6114 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006115 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006116 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6117 if (!QualifierLoc)
6118 return StmtError();
6119 }
6120
6121 // Transform the declaration name.
6122 DeclarationNameInfo NameInfo = S->getNameInfo();
6123 if (NameInfo.getName()) {
6124 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6125 if (!NameInfo.getName())
6126 return StmtError();
6127 }
6128
6129 // Check whether anything changed.
6130 if (!getDerived().AlwaysRebuild() &&
6131 QualifierLoc == S->getQualifierLoc() &&
6132 NameInfo.getName() == S->getNameInfo().getName())
6133 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006134
Douglas Gregorba0513d2011-10-25 01:33:02 +00006135 // Determine whether this name exists, if we can.
6136 CXXScopeSpec SS;
6137 SS.Adopt(QualifierLoc);
6138 bool Dependent = false;
6139 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6140 case Sema::IER_Exists:
6141 if (S->isIfExists())
6142 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006143
Douglas Gregorba0513d2011-10-25 01:33:02 +00006144 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6145
6146 case Sema::IER_DoesNotExist:
6147 if (S->isIfNotExists())
6148 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006149
Douglas Gregorba0513d2011-10-25 01:33:02 +00006150 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006151
Douglas Gregorba0513d2011-10-25 01:33:02 +00006152 case Sema::IER_Dependent:
6153 Dependent = true;
6154 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006155
Douglas Gregor65019ac2011-10-25 03:44:56 +00006156 case Sema::IER_Error:
6157 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 // We need to continue with the instantiation, so do so now.
6161 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6162 if (SubStmt.isInvalid())
6163 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006164
Douglas Gregorba0513d2011-10-25 01:33:02 +00006165 // If we have resolved the name, just transform to the substatement.
6166 if (!Dependent)
6167 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006168
Douglas Gregorba0513d2011-10-25 01:33:02 +00006169 // The name is still dependent, so build a dependent expression again.
6170 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6171 S->isIfExists(),
6172 QualifierLoc,
6173 NameInfo,
6174 SubStmt.get());
6175}
6176
6177template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006178ExprResult
6179TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6180 NestedNameSpecifierLoc QualifierLoc;
6181 if (E->getQualifierLoc()) {
6182 QualifierLoc
6183 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6184 if (!QualifierLoc)
6185 return ExprError();
6186 }
6187
6188 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6189 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6190 if (!PD)
6191 return ExprError();
6192
6193 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6194 if (Base.isInvalid())
6195 return ExprError();
6196
6197 return new (SemaRef.getASTContext())
6198 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6199 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6200 QualifierLoc, E->getMemberLoc());
6201}
6202
6203template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006204StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006205TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6206 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6207 if(TryBlock.isInvalid()) return StmtError();
6208
6209 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6210 if(!getDerived().AlwaysRebuild() &&
6211 TryBlock.get() == S->getTryBlock() &&
6212 Handler.get() == S->getHandler())
6213 return SemaRef.Owned(S);
6214
6215 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6216 S->getTryLoc(),
6217 TryBlock.take(),
6218 Handler.take());
6219}
6220
6221template<typename Derived>
6222StmtResult
6223TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6224 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6225 if(Block.isInvalid()) return StmtError();
6226
6227 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6228 Block.take());
6229}
6230
6231template<typename Derived>
6232StmtResult
6233TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6234 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6235 if(FilterExpr.isInvalid()) return StmtError();
6236
6237 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6238 if(Block.isInvalid()) return StmtError();
6239
6240 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6241 FilterExpr.take(),
6242 Block.take());
6243}
6244
6245template<typename Derived>
6246StmtResult
6247TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6248 if(isa<SEHFinallyStmt>(Handler))
6249 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6250 else
6251 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6252}
6253
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006254template<typename Derived>
6255StmtResult
6256TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6257 // Transform the clauses
Rafael Espindola43678292013-09-03 14:33:09 +00006258 SmallVector<OMPClause *, 5> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006259 ArrayRef<OMPClause *> Clauses = D->clauses();
6260 TClauses.reserve(Clauses.size());
6261 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6262 I != E; ++I) {
6263 if (*I) {
6264 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Rafael Espindola43678292013-09-03 14:33:09 +00006265 if (!Clause)
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006266 return StmtError();
6267 TClauses.push_back(Clause);
6268 }
6269 else {
6270 TClauses.push_back(0);
6271 }
6272 }
Rafael Espindola43678292013-09-03 14:33:09 +00006273 if (!D->getAssociatedStmt())
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006274 return StmtError();
6275 StmtResult AssociatedStmt =
6276 getDerived().TransformStmt(D->getAssociatedStmt());
Rafael Espindola43678292013-09-03 14:33:09 +00006277 if (AssociatedStmt.isInvalid())
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006278 return StmtError();
6279
Rafael Espindola43678292013-09-03 14:33:09 +00006280 return getDerived().RebuildOMPParallelDirective(TClauses,
6281 AssociatedStmt.take(),
6282 D->getLocStart(),
6283 D->getLocEnd());
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006284}
6285
6286template<typename Derived>
6287OMPClause *
6288TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6289 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6290 C->getDefaultKindKwLoc(),
6291 C->getLocStart(),
6292 C->getLParenLoc(),
6293 C->getLocEnd());
6294}
6295
6296template<typename Derived>
6297OMPClause *
6298TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Rafael Espindola43678292013-09-03 14:33:09 +00006299 SmallVector<Expr *, 5> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006300 Vars.reserve(C->varlist_size());
6301 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6302 E = C->varlist_end();
6303 I != E; ++I) {
6304 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6305 if (EVar.isInvalid())
6306 return 0;
6307 Vars.push_back(EVar.take());
6308 }
6309 return getDerived().RebuildOMPPrivateClause(Vars,
6310 C->getLocStart(),
6311 C->getLParenLoc(),
6312 C->getLocEnd());
6313}
6314
Douglas Gregor43959a92009-08-20 07:17:43 +00006315//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316// Expression transformation
6317//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006319ExprResult
John McCall454feb92009-12-08 09:21:05 +00006320TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006321 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
6324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006325ExprResult
John McCall454feb92009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006327 NestedNameSpecifierLoc QualifierLoc;
6328 if (E->getQualifierLoc()) {
6329 QualifierLoc
6330 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6331 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006332 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006333 }
John McCalldbd872f2009-12-08 09:08:17 +00006334
6335 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006336 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6337 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
John McCallec8045d2010-08-17 21:27:17 +00006341 DeclarationNameInfo NameInfo = E->getNameInfo();
6342 if (NameInfo.getName()) {
6343 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6344 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006345 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006346 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006347
6348 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006349 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006350 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006351 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006352 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006353
6354 // Mark it referenced in the new context regardless.
6355 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006356 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006357
John McCall3fa5cae2010-10-26 07:05:15 +00006358 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006359 }
John McCalldbd872f2009-12-08 09:08:17 +00006360
6361 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006362 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006363 TemplateArgs = &TransArgs;
6364 TransArgs.setLAngleLoc(E->getLAngleLoc());
6365 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006366 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6367 E->getNumTemplateArgs(),
6368 TransArgs))
6369 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006370 }
6371
Chad Rosier4a9d7952012-08-08 18:46:20 +00006372 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006373 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCall454feb92009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006379 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380}
Mike Stump1eb44332009-09-09 15:08:12 +00006381
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006383ExprResult
John McCall454feb92009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006385 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386}
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006389ExprResult
John McCall454feb92009-12-08 09:21:05 +00006390TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006391 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392}
Mike Stump1eb44332009-09-09 15:08:12 +00006393
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006395ExprResult
John McCall454feb92009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006397 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398}
Mike Stump1eb44332009-09-09 15:08:12 +00006399
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006401ExprResult
John McCall454feb92009-12-08 09:21:05 +00006402TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006404}
6405
6406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006407ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006408TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006409 if (FunctionDecl *FD = E->getDirectCallee())
6410 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006411 return SemaRef.MaybeBindToTemporary(E);
6412}
6413
6414template<typename Derived>
6415ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006416TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6417 ExprResult ControllingExpr =
6418 getDerived().TransformExpr(E->getControllingExpr());
6419 if (ControllingExpr.isInvalid())
6420 return ExprError();
6421
Chris Lattner686775d2011-07-20 06:58:45 +00006422 SmallVector<Expr *, 4> AssocExprs;
6423 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006424 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6425 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6426 if (TS) {
6427 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6428 if (!AssocType)
6429 return ExprError();
6430 AssocTypes.push_back(AssocType);
6431 } else {
6432 AssocTypes.push_back(0);
6433 }
6434
6435 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6436 if (AssocExpr.isInvalid())
6437 return ExprError();
6438 AssocExprs.push_back(AssocExpr.release());
6439 }
6440
6441 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6442 E->getDefaultLoc(),
6443 E->getRParenLoc(),
6444 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006445 AssocTypes,
6446 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006447}
6448
6449template<typename Derived>
6450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006452 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall9ae2f072010-08-23 23:25:46 +00006459 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 E->getRParen());
6461}
6462
Richard Smithefeeccf2012-10-21 03:28:35 +00006463/// \brief The operand of a unary address-of operator has special rules: it's
6464/// allowed to refer to a non-static member of a class even if there's no 'this'
6465/// object available.
6466template<typename Derived>
6467ExprResult
6468TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6469 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6470 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6471 else
6472 return getDerived().TransformExpr(E);
6473}
6474
Mike Stump1eb44332009-09-09 15:08:12 +00006475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006476ExprResult
John McCall454feb92009-12-08 09:21:05 +00006477TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006478 ExprResult SubExpr;
6479 if (E->getOpcode() == UO_AddrOf)
6480 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6481 else
6482 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6490 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006491 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492}
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006496TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6497 // Transform the type.
6498 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6499 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006500 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006501
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006502 // Transform all of the components into components similar to what the
6503 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006504 // FIXME: It would be slightly more efficient in the non-dependent case to
6505 // just map FieldDecls, rather than requiring the rebuilder to look for
6506 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006507 // template code that we don't care.
6508 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006509 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006510 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006511 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006512 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6513 const Node &ON = E->getComponent(I);
6514 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006515 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006516 Comp.LocStart = ON.getSourceRange().getBegin();
6517 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006518 switch (ON.getKind()) {
6519 case Node::Array: {
6520 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006521 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006522 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006524
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006525 ExprChanged = ExprChanged || Index.get() != FromIndex;
6526 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006527 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006528 break;
6529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006530
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006531 case Node::Field:
6532 case Node::Identifier:
6533 Comp.isBrackets = false;
6534 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006535 if (!Comp.U.IdentInfo)
6536 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006537
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006538 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006539
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006540 case Node::Base:
6541 // Will be recomputed during the rebuild.
6542 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006543 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006544
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006545 Components.push_back(Comp);
6546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006547
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006548 // If nothing changed, retain the existing expression.
6549 if (!getDerived().AlwaysRebuild() &&
6550 Type == E->getTypeSourceInfo() &&
6551 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006552 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006553
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006554 // Build a new offsetof expression.
6555 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6556 Components.data(), Components.size(),
6557 E->getRParenLoc());
6558}
6559
6560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006561ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006562TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6563 assert(getDerived().AlreadyTransformed(E->getType()) &&
6564 "opaque value expression requires transformation");
6565 return SemaRef.Owned(E);
6566}
6567
6568template<typename Derived>
6569ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006570TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006571 // Rebuild the syntactic form. The original syntactic form has
6572 // opaque-value expressions in it, so strip those away and rebuild
6573 // the result. This is a really awful way of doing this, but the
6574 // better solution (rebuilding the semantic expressions and
6575 // rebinding OVEs as necessary) doesn't work; we'd need
6576 // TreeTransform to not strip away implicit conversions.
6577 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6578 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006579 if (result.isInvalid()) return ExprError();
6580
6581 // If that gives us a pseudo-object result back, the pseudo-object
6582 // expression must have been an lvalue-to-rvalue conversion which we
6583 // should reapply.
6584 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6585 result = SemaRef.checkPseudoObjectRValue(result.take());
6586
6587 return result;
6588}
6589
6590template<typename Derived>
6591ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006592TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6593 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006595 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006596
John McCalla93c9342009-12-07 02:54:59 +00006597 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006598 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
John McCall5ab75172009-11-04 07:28:41 +00006601 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006602 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006603
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006604 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6605 E->getKind(),
6606 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 }
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006609 // C++0x [expr.sizeof]p1:
6610 // The operand is either an expression, which is an unevaluated operand
6611 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006612 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6613 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006615 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6616 if (SubExpr.isInvalid())
6617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006619 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6620 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006622 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6623 E->getOperatorLoc(),
6624 E->getKind(),
6625 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626}
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006629ExprResult
John McCall454feb92009-12-08 09:21:05 +00006630TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
John McCall60d7b3a2010-08-24 06:29:42 +00006635 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
6639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() &&
6641 LHS.get() == E->getLHS() &&
6642 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006643 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006644
John McCall9ae2f072010-08-23 23:25:46 +00006645 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006647 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 E->getRBracketLoc());
6649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
6651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006655 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006657 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658
6659 // Transform arguments.
6660 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006661 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006662 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006663 &ArgChanged))
6664 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (!getDerived().AlwaysRebuild() &&
6667 Callee.get() == E->getCallee() &&
6668 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006669 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006672 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006674 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006675 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 E->getRParenLoc());
6677}
Mike Stump1eb44332009-09-09 15:08:12 +00006678
6679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006680ExprResult
John McCall454feb92009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregor40d96a62011-02-28 21:54:11 +00006686 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006687 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006688 QualifierLoc
6689 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006690
Douglas Gregor40d96a62011-02-28 21:54:11 +00006691 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006692 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006693 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006694 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Eli Friedmanf595cc42009-12-04 06:40:45 +00006696 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006697 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6698 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCall6bb80172010-03-30 21:47:33 +00006702 NamedDecl *FoundDecl = E->getFoundDecl();
6703 if (FoundDecl == E->getMemberDecl()) {
6704 FoundDecl = Member;
6705 } else {
6706 FoundDecl = cast_or_null<NamedDecl>(
6707 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6708 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006710 }
6711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
6713 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006714 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006715 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006716 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006717 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006718
Anders Carlsson1f240322009-12-22 05:24:09 +00006719 // Mark it referenced in the new context regardless.
6720 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006721 SemaRef.MarkMemberReferenced(E);
6722
John McCall3fa5cae2010-10-26 07:05:15 +00006723 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006724 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725
John McCalld5532b62009-11-23 01:53:49 +00006726 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006727 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006728 TransArgs.setLAngleLoc(E->getLAngleLoc());
6729 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006730 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6731 E->getNumTemplateArgs(),
6732 TransArgs))
6733 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006734 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 // FIXME: Bogus source location for the operator
6737 SourceLocation FakeOperatorLoc
6738 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6739
John McCallc2233c52010-01-15 08:34:02 +00006740 // FIXME: to do this check properly, we will need to preserve the
6741 // first-qualifier-in-scope here, just in case we had a dependent
6742 // base (and therefore couldn't do the check) and a
6743 // nested-name-qualifier (and therefore could do the lookup).
6744 NamedDecl *FirstQualifierInScope = 0;
6745
John McCall9ae2f072010-08-23 23:25:46 +00006746 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006748 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006749 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006750 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006751 Member,
John McCall6bb80172010-03-30 21:47:33 +00006752 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006753 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006754 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006755 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756}
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006759ExprResult
John McCall454feb92009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006761 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() &&
6770 LHS.get() == E->getLHS() &&
6771 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Lang Hamesbe9af122012-10-02 04:45:10 +00006774 Sema::FPContractStateRAII FPContractState(getSema());
6775 getSema().FPFeatures.fp_contract = E->isFPContractable();
6776
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006778 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779}
6780
Mike Stump1eb44332009-09-09 15:08:12 +00006781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006782ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006784 CompoundAssignOperator *E) {
6785 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786}
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006789ExprResult TreeTransform<Derived>::
6790TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6791 // Just rebuild the common and RHS expressions and see whether we
6792 // get any changes.
6793
6794 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6795 if (commonExpr.isInvalid())
6796 return ExprError();
6797
6798 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6799 if (rhs.isInvalid())
6800 return ExprError();
6801
6802 if (!getDerived().AlwaysRebuild() &&
6803 commonExpr.get() == e->getCommon() &&
6804 rhs.get() == e->getFalseExpr())
6805 return SemaRef.Owned(e);
6806
6807 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6808 e->getQuestionLoc(),
6809 0,
6810 e->getColonLoc(),
6811 rhs.get());
6812}
6813
6814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006815ExprResult
John McCall454feb92009-12-08 09:21:05 +00006816TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006817 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
John McCall60d7b3a2010-08-24 06:29:42 +00006825 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (!getDerived().AlwaysRebuild() &&
6830 Cond.get() == E->getCond() &&
6831 LHS.get() == E->getLHS() &&
6832 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006833 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006834
John McCall9ae2f072010-08-23 23:25:46 +00006835 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006836 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006837 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006838 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006839 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840}
Mike Stump1eb44332009-09-09 15:08:12 +00006841
6842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006843ExprResult
John McCall454feb92009-12-08 09:21:05 +00006844TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006845 // Implicit casts are eliminated during transformation, since they
6846 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006847 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848}
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006851ExprResult
John McCall454feb92009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006853 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6854 if (!Type)
6855 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006856
John McCall60d7b3a2010-08-24 06:29:42 +00006857 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006858 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006860 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006863 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006866
John McCall9d125032010-01-15 18:39:57 +00006867 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006868 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006870 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871}
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006874ExprResult
John McCall454feb92009-12-08 09:21:05 +00006875TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006876 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6877 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6878 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
John McCall60d7b3a2010-08-24 06:29:42 +00006881 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006886 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006888 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889
John McCall1d7d8d62010-01-19 22:33:45 +00006890 // Note: the expression type doesn't necessarily match the
6891 // type-as-written, but that's okay, because it should always be
6892 // derivable from the initializer.
6893
John McCall42f56b52010-01-18 19:35:47 +00006894 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006896 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897}
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006900ExprResult
John McCall454feb92009-12-08 09:21:05 +00006901TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006902 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906 if (!getDerived().AlwaysRebuild() &&
6907 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006908 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006909
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006911 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006913 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 E->getAccessorLoc(),
6915 E->getAccessor());
6916}
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006919ExprResult
John McCall454feb92009-12-08 09:21:05 +00006920TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006923 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006924 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006925 Inits, &InitChanged))
6926 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006931 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006932 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933}
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006936ExprResult
John McCall454feb92009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregor43959a92009-08-20 07:17:43 +00006940 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006941 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregor43959a92009-08-20 07:17:43 +00006945 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006946 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 bool ExprChanged = false;
6948 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6949 DEnd = E->designators_end();
6950 D != DEnd; ++D) {
6951 if (D->isFieldDesignator()) {
6952 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6953 D->getDotLoc(),
6954 D->getFieldLoc()));
6955 continue;
6956 }
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006959 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006962
6963 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6967 ArrayExprs.push_back(Index.release());
6968 continue;
6969 }
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006972 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6974 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
John McCall60d7b3a2010-08-24 06:29:42 +00006977 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006980
6981 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 End.get(),
6983 D->getLBracketLoc(),
6984 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6987 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 ArrayExprs.push_back(Start.release());
6990 ArrayExprs.push_back(End.release());
6991 }
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 if (!getDerived().AlwaysRebuild() &&
6994 Init.get() == E->getInit() &&
6995 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006998 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007000 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001}
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007004ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007006 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007007 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007008
Douglas Gregor5557b252009-10-28 00:29:27 +00007009 // FIXME: Will we ever have proper type location here? Will we actually
7010 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 QualType T = getDerived().TransformType(E->getType());
7012 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (!getDerived().AlwaysRebuild() &&
7016 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007018
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 return getDerived().RebuildImplicitValueInitExpr(T);
7020}
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007023ExprResult
John McCall454feb92009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007025 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7026 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
John McCall60d7b3a2010-08-24 06:29:42 +00007029 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007031 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007034 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007036 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007037
John McCall9ae2f072010-08-23 23:25:46 +00007038 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007039 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
7041
7042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
John McCall454feb92009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007046 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007047 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7048 &ArgumentChanged))
7049 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007052 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 E->getRParenLoc());
7054}
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056/// \brief Transform an address-of-label expression.
7057///
7058/// By default, the transformation of an address-of-label expression always
7059/// rebuilds the expression, so that the label identifier can be resolved to
7060/// the corresponding label statement by semantic analysis.
7061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
John McCall454feb92009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007064 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7065 E->getLabel());
7066 if (!LD)
7067 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007070 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071}
Mike Stump1eb44332009-09-09 15:08:12 +00007072
7073template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007074ExprResult
John McCall454feb92009-12-08 09:21:05 +00007075TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007076 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007077 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007079 if (SubStmt.isInvalid()) {
7080 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007081 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007082 }
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007085 SubStmt.get() == E->getSubStmt()) {
7086 // Calling this an 'error' is unintuitive, but it does the right thing.
7087 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007088 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007089 }
Mike Stump1eb44332009-09-09 15:08:12 +00007090
7091 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007092 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 E->getRParenLoc());
7094}
Mike Stump1eb44332009-09-09 15:08:12 +00007095
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007097ExprResult
John McCall454feb92009-12-08 09:21:05 +00007098TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007099 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007106
John McCall60d7b3a2010-08-24 06:29:42 +00007107 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007109 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007110
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111 if (!getDerived().AlwaysRebuild() &&
7112 Cond.get() == E->getCond() &&
7113 LHS.get() == E->getLHS() &&
7114 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007115 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007118 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 E->getRParenLoc());
7120}
Mike Stump1eb44332009-09-09 15:08:12 +00007121
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007123ExprResult
John McCall454feb92009-12-08 09:21:05 +00007124TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126}
7127
7128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007131 switch (E->getOperator()) {
7132 case OO_New:
7133 case OO_Delete:
7134 case OO_Array_New:
7135 case OO_Array_Delete:
7136 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007137
Douglas Gregor668d6d92009-12-13 20:44:55 +00007138 case OO_Call: {
7139 // This is a call to an object's operator().
7140 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7141
7142 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007143 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007144 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007145 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007146
7147 // FIXME: Poor location information
7148 SourceLocation FakeLParenLoc
7149 = SemaRef.PP.getLocForEndOfToken(
7150 static_cast<Expr *>(Object.get())->getLocEnd());
7151
7152 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007153 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007154 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007155 Args))
7156 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007157
John McCall9ae2f072010-08-23 23:25:46 +00007158 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007159 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007160 E->getLocEnd());
7161 }
7162
7163#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7164 case OO_##Name:
7165#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7166#include "clang/Basic/OperatorKinds.def"
7167 case OO_Subscript:
7168 // Handled below.
7169 break;
7170
7171 case OO_Conditional:
7172 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007173
7174 case OO_None:
7175 case NUM_OVERLOADED_OPERATORS:
7176 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007177 }
7178
John McCall60d7b3a2010-08-24 06:29:42 +00007179 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Richard Smithefeeccf2012-10-21 03:28:35 +00007183 ExprResult First;
7184 if (E->getOperator() == OO_Amp)
7185 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7186 else
7187 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007189 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190
John McCall60d7b3a2010-08-24 06:29:42 +00007191 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 if (E->getNumArgs() == 2) {
7193 Second = getDerived().TransformExpr(E->getArg(1));
7194 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196 }
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!getDerived().AlwaysRebuild() &&
7199 Callee.get() == E->getCallee() &&
7200 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007201 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007202 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Lang Hamesbe9af122012-10-02 04:45:10 +00007204 Sema::FPContractStateRAII FPContractState(getSema());
7205 getSema().FPFeatures.fp_contract = E->isFPContractable();
7206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7208 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007209 Callee.get(),
7210 First.get(),
7211 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212}
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007215ExprResult
John McCall454feb92009-12-08 09:21:05 +00007216TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7217 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218}
Mike Stump1eb44332009-09-09 15:08:12 +00007219
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007221ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007222TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7223 // Transform the callee.
7224 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7225 if (Callee.isInvalid())
7226 return ExprError();
7227
7228 // Transform exec config.
7229 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7230 if (EC.isInvalid())
7231 return ExprError();
7232
7233 // Transform arguments.
7234 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007235 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007236 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007237 &ArgChanged))
7238 return ExprError();
7239
7240 if (!getDerived().AlwaysRebuild() &&
7241 Callee.get() == E->getCallee() &&
7242 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007243 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007244
7245 // FIXME: Wrong source location information for the '('.
7246 SourceLocation FakeLParenLoc
7247 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7248 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007249 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007250 E->getRParenLoc(), EC.get());
7251}
7252
7253template<typename Derived>
7254ExprResult
John McCall454feb92009-12-08 09:21:05 +00007255TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007256 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7257 if (!Type)
7258 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007259
John McCall60d7b3a2010-08-24 06:29:42 +00007260 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007261 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007264
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007266 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007268 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007270 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007271 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007272 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007273 E->getAngleBrackets().getEnd(),
7274 // FIXME. this should be '(' location
7275 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007276 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007277 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278}
Mike Stump1eb44332009-09-09 15:08:12 +00007279
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007281ExprResult
John McCall454feb92009-12-08 09:21:05 +00007282TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7283 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284}
Mike Stump1eb44332009-09-09 15:08:12 +00007285
7286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007287ExprResult
John McCall454feb92009-12-08 09:21:05 +00007288TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7289 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007290}
7291
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007293ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007295 CXXReinterpretCastExpr *E) {
7296 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297}
Mike Stump1eb44332009-09-09 15:08:12 +00007298
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007300ExprResult
John McCall454feb92009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7302 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303}
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007306ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007308 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007309 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7310 if (!Type)
7311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007312
John McCall60d7b3a2010-08-24 06:29:42 +00007313 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007314 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007319 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007321 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007323 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007324 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007325 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326 E->getRParenLoc());
7327}
Mike Stump1eb44332009-09-09 15:08:12 +00007328
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007330ExprResult
John McCall454feb92009-12-08 09:21:05 +00007331TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007333 TypeSourceInfo *TInfo
7334 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7335 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007339 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007340 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007342 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7343 E->getLocStart(),
7344 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345 E->getLocEnd());
7346 }
Mike Stump1eb44332009-09-09 15:08:12 +00007347
Eli Friedmanef331b72012-01-20 01:26:23 +00007348 // We don't know whether the subexpression is potentially evaluated until
7349 // after we perform semantic analysis. We speculatively assume it is
7350 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007352 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7353 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007354
John McCall60d7b3a2010-08-24 06:29:42 +00007355 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359 if (!getDerived().AlwaysRebuild() &&
7360 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007361 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007363 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7364 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007365 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366 E->getLocEnd());
7367}
7368
7369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007370ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007371TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7372 if (E->isTypeOperand()) {
7373 TypeSourceInfo *TInfo
7374 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7375 if (!TInfo)
7376 return ExprError();
7377
7378 if (!getDerived().AlwaysRebuild() &&
7379 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007380 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007381
Douglas Gregor3c52a212011-03-06 17:40:41 +00007382 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007383 E->getLocStart(),
7384 TInfo,
7385 E->getLocEnd());
7386 }
7387
Francois Pichet01b7c302010-09-08 12:20:18 +00007388 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7389
7390 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7391 if (SubExpr.isInvalid())
7392 return ExprError();
7393
7394 if (!getDerived().AlwaysRebuild() &&
7395 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007396 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007397
7398 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7399 E->getLocStart(),
7400 SubExpr.get(),
7401 E->getLocEnd());
7402}
7403
7404template<typename Derived>
7405ExprResult
John McCall454feb92009-12-08 09:21:05 +00007406TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007407 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007408}
Mike Stump1eb44332009-09-09 15:08:12 +00007409
Douglas Gregorb98b1992009-08-11 05:31:07 +00007410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007411ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007413 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007414 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007415}
Mike Stump1eb44332009-09-09 15:08:12 +00007416
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007418ExprResult
John McCall454feb92009-12-08 09:21:05 +00007419TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007420 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007421
Douglas Gregorec79d872012-02-24 17:41:38 +00007422 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7423 // Make sure that we capture 'this'.
7424 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007425 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007427
Douglas Gregor828a1972010-01-07 23:12:05 +00007428 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429}
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007432ExprResult
John McCall454feb92009-12-08 09:21:05 +00007433TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007434 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007435 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007437
Douglas Gregorb98b1992009-08-11 05:31:07 +00007438 if (!getDerived().AlwaysRebuild() &&
7439 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007440 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441
Douglas Gregorbca01b42011-07-06 22:04:06 +00007442 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7443 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444}
Mike Stump1eb44332009-09-09 15:08:12 +00007445
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007447ExprResult
John McCall454feb92009-12-08 09:21:05 +00007448TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007449 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007450 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7451 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007452 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007454
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007455 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007458
Douglas Gregor036aed12009-12-23 23:03:06 +00007459 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007460}
Mike Stump1eb44332009-09-09 15:08:12 +00007461
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007463ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007464TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7465 FieldDecl *Field
7466 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7467 E->getField()));
7468 if (!Field)
7469 return ExprError();
7470
7471 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7472 return SemaRef.Owned(E);
7473
7474 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7475}
7476
7477template<typename Derived>
7478ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007479TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7480 CXXScalarValueInitExpr *E) {
7481 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7482 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007483 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007484
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007486 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007488
Chad Rosier4a9d7952012-08-08 18:46:20 +00007489 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007490 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007491 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492}
Mike Stump1eb44332009-09-09 15:08:12 +00007493
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007495ExprResult
John McCall454feb92009-12-08 09:21:05 +00007496TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007498 TypeSourceInfo *AllocTypeInfo
7499 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7500 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007504 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007506 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508 // Transform the placement arguments (if any).
7509 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007510 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007511 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007512 E->getNumPlacementArgs(), true,
7513 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007516 // Transform the initializer (if any).
7517 Expr *OldInit = E->getInitializer();
7518 ExprResult NewInit;
7519 if (OldInit)
7520 NewInit = getDerived().TransformExpr(OldInit);
7521 if (NewInit.isInvalid())
7522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007523
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007524 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007525 FunctionDecl *OperatorNew = 0;
7526 if (E->getOperatorNew()) {
7527 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007528 getDerived().TransformDecl(E->getLocStart(),
7529 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007530 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007532 }
7533
7534 FunctionDecl *OperatorDelete = 0;
7535 if (E->getOperatorDelete()) {
7536 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007537 getDerived().TransformDecl(E->getLocStart(),
7538 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007539 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007540 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007541 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007542
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007544 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007546 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007547 OperatorNew == E->getOperatorNew() &&
7548 OperatorDelete == E->getOperatorDelete() &&
7549 !ArgumentChanged) {
7550 // Mark any declarations we need as referenced.
7551 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007552 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007553 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007554 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007555 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007556
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007557 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007558 QualType ElementType
7559 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7560 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7561 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7562 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007563 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007564 }
7565 }
7566 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007567
John McCall3fa5cae2010-10-26 07:05:15 +00007568 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007569 }
Mike Stump1eb44332009-09-09 15:08:12 +00007570
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007571 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007572 if (!ArraySize.get()) {
7573 // If no array size was specified, but the new expression was
7574 // instantiated with an array type (e.g., "new T" where T is
7575 // instantiated with "int[4]"), extract the outer bound from the
7576 // array type as our array size. We do this with constant and
7577 // dependently-sized array types.
7578 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7579 if (!ArrayT) {
7580 // Do nothing
7581 } else if (const ConstantArrayType *ConsArrayT
7582 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007584 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007586 SemaRef.Context.getSizeType(),
7587 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007588 AllocType = ConsArrayT->getElementType();
7589 } else if (const DependentSizedArrayType *DepArrayT
7590 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7591 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007592 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007593 AllocType = DepArrayT->getElementType();
7594 }
7595 }
7596 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007597
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7599 E->isGlobalNew(),
7600 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007601 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007603 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007604 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007605 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007606 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007607 E->getDirectInitRange(),
7608 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007609}
Mike Stump1eb44332009-09-09 15:08:12 +00007610
Douglas Gregorb98b1992009-08-11 05:31:07 +00007611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007612ExprResult
John McCall454feb92009-12-08 09:21:05 +00007613TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007614 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007615 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007617
Douglas Gregor1af74512010-02-26 00:38:10 +00007618 // Transform the delete operator, if known.
7619 FunctionDecl *OperatorDelete = 0;
7620 if (E->getOperatorDelete()) {
7621 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007622 getDerived().TransformDecl(E->getLocStart(),
7623 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007624 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007625 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007626 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627
Douglas Gregorb98b1992009-08-11 05:31:07 +00007628 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007629 Operand.get() == E->getArgument() &&
7630 OperatorDelete == E->getOperatorDelete()) {
7631 // Mark any declarations we need as referenced.
7632 // FIXME: instantiation-specific.
7633 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007634 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007635
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007636 if (!E->getArgument()->isTypeDependent()) {
7637 QualType Destroyed = SemaRef.Context.getBaseElementType(
7638 E->getDestroyedType());
7639 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7640 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007641 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007642 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007643 }
7644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
John McCall3fa5cae2010-10-26 07:05:15 +00007646 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007647 }
Mike Stump1eb44332009-09-09 15:08:12 +00007648
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7650 E->isGlobalDelete(),
7651 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007652 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007653}
Mike Stump1eb44332009-09-09 15:08:12 +00007654
Douglas Gregorb98b1992009-08-11 05:31:07 +00007655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007656ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007657TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007658 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007659 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007660 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007662
John McCallb3d87482010-08-24 05:47:05 +00007663 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007664 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007665 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007666 E->getOperatorLoc(),
7667 E->isArrow()? tok::arrow : tok::period,
7668 ObjectTypePtr,
7669 MayBePseudoDestructor);
7670 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007671 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007672
John McCallb3d87482010-08-24 05:47:05 +00007673 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007674 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7675 if (QualifierLoc) {
7676 QualifierLoc
7677 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7678 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007679 return ExprError();
7680 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007681 CXXScopeSpec SS;
7682 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007683
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007684 PseudoDestructorTypeStorage Destroyed;
7685 if (E->getDestroyedTypeInfo()) {
7686 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007687 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007688 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007689 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007690 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007691 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007692 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007693 // We aren't likely to be able to resolve the identifier down to a type
7694 // now anyway, so just retain the identifier.
7695 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7696 E->getDestroyedTypeLoc());
7697 } else {
7698 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007699 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007700 *E->getDestroyedTypeIdentifier(),
7701 E->getDestroyedTypeLoc(),
7702 /*Scope=*/0,
7703 SS, ObjectTypePtr,
7704 false);
7705 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007706 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007708 Destroyed
7709 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7710 E->getDestroyedTypeLoc());
7711 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007712
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007713 TypeSourceInfo *ScopeTypeInfo = 0;
7714 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007715 CXXScopeSpec EmptySS;
7716 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7717 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007718 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007719 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007721
John McCall9ae2f072010-08-23 23:25:46 +00007722 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007723 E->getOperatorLoc(),
7724 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007725 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007726 ScopeTypeInfo,
7727 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007728 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007729 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007730}
Mike Stump1eb44332009-09-09 15:08:12 +00007731
Douglas Gregora71d8192009-09-04 17:36:40 +00007732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007733ExprResult
John McCallba135432009-11-21 08:51:07 +00007734TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007735 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007736 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7737 Sema::LookupOrdinaryName);
7738
7739 // Transform all the decls.
7740 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7741 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007742 NamedDecl *InstD = static_cast<NamedDecl*>(
7743 getDerived().TransformDecl(Old->getNameLoc(),
7744 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007745 if (!InstD) {
7746 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7747 // This can happen because of dependent hiding.
7748 if (isa<UsingShadowDecl>(*I))
7749 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007750 else {
7751 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007753 }
John McCall9f54ad42009-12-10 09:41:52 +00007754 }
John McCallf7a1a742009-11-24 19:00:30 +00007755
7756 // Expand using declarations.
7757 if (isa<UsingDecl>(InstD)) {
7758 UsingDecl *UD = cast<UsingDecl>(InstD);
7759 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7760 E = UD->shadow_end(); I != E; ++I)
7761 R.addDecl(*I);
7762 continue;
7763 }
7764
7765 R.addDecl(InstD);
7766 }
7767
7768 // Resolve a kind, but don't do any further analysis. If it's
7769 // ambiguous, the callee needs to deal with it.
7770 R.resolveKind();
7771
7772 // Rebuild the nested-name qualifier, if present.
7773 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007774 if (Old->getQualifierLoc()) {
7775 NestedNameSpecifierLoc QualifierLoc
7776 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7777 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007778 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007779
Douglas Gregor4c9be892011-02-28 20:01:57 +00007780 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007781 }
7782
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007783 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007784 CXXRecordDecl *NamingClass
7785 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7786 Old->getNameLoc(),
7787 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007788 if (!NamingClass) {
7789 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007790 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007792
Douglas Gregor66c45152010-04-27 16:10:10 +00007793 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007794 }
7795
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007796 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7797
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007798 // If we have neither explicit template arguments, nor the template keyword,
7799 // it's a normal declaration name.
7800 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007801 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7802
7803 // If we have template arguments, rebuild them, then rebuild the
7804 // templateid expression.
7805 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007806 if (Old->hasExplicitTemplateArgs() &&
7807 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007808 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007809 TransArgs)) {
7810 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007811 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007812 }
John McCallf7a1a742009-11-24 19:00:30 +00007813
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007814 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007815 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816}
Mike Stump1eb44332009-09-09 15:08:12 +00007817
Douglas Gregorb98b1992009-08-11 05:31:07 +00007818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007819ExprResult
John McCall454feb92009-12-08 09:21:05 +00007820TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007821 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7822 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007824
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007826 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007827 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007828
Mike Stump1eb44332009-09-09 15:08:12 +00007829 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 T,
7832 E->getLocEnd());
7833}
Mike Stump1eb44332009-09-09 15:08:12 +00007834
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007836ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007837TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7838 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7839 if (!LhsT)
7840 return ExprError();
7841
7842 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7843 if (!RhsT)
7844 return ExprError();
7845
7846 if (!getDerived().AlwaysRebuild() &&
7847 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7848 return SemaRef.Owned(E);
7849
7850 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7851 E->getLocStart(),
7852 LhsT, RhsT,
7853 E->getLocEnd());
7854}
7855
7856template<typename Derived>
7857ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007858TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7859 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007860 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007861 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7862 TypeSourceInfo *From = E->getArg(I);
7863 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007864 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007865 TypeLocBuilder TLB;
7866 TLB.reserve(FromTL.getFullDataSize());
7867 QualType To = getDerived().TransformType(TLB, FromTL);
7868 if (To.isNull())
7869 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007870
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007871 if (To == From->getType())
7872 Args.push_back(From);
7873 else {
7874 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7875 ArgChanged = true;
7876 }
7877 continue;
7878 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007879
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007880 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007881
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007882 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007883 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007884 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7885 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7886 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007887
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007888 // Determine whether the set of unexpanded parameter packs can and should
7889 // be expanded.
7890 bool Expand = true;
7891 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007892 Optional<unsigned> OrigNumExpansions =
7893 ExpansionTL.getTypePtr()->getNumExpansions();
7894 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007895 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7896 PatternTL.getSourceRange(),
7897 Unexpanded,
7898 Expand, RetainExpansion,
7899 NumExpansions))
7900 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007901
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007902 if (!Expand) {
7903 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007904 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007905 // expansion.
7906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007907
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007908 TypeLocBuilder TLB;
7909 TLB.reserve(From->getTypeLoc().getFullDataSize());
7910
7911 QualType To = getDerived().TransformType(TLB, PatternTL);
7912 if (To.isNull())
7913 return ExprError();
7914
Chad Rosier4a9d7952012-08-08 18:46:20 +00007915 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007916 PatternTL.getSourceRange(),
7917 ExpansionTL.getEllipsisLoc(),
7918 NumExpansions);
7919 if (To.isNull())
7920 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007921
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007922 PackExpansionTypeLoc ToExpansionTL
7923 = TLB.push<PackExpansionTypeLoc>(To);
7924 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7925 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7926 continue;
7927 }
7928
7929 // Expand the pack expansion by substituting for each argument in the
7930 // pack(s).
7931 for (unsigned I = 0; I != *NumExpansions; ++I) {
7932 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7933 TypeLocBuilder TLB;
7934 TLB.reserve(PatternTL.getFullDataSize());
7935 QualType To = getDerived().TransformType(TLB, PatternTL);
7936 if (To.isNull())
7937 return ExprError();
7938
Eli Friedman20cfeca2013-07-19 21:49:32 +00007939 if (To->containsUnexpandedParameterPack()) {
7940 To = getDerived().RebuildPackExpansionType(To,
7941 PatternTL.getSourceRange(),
7942 ExpansionTL.getEllipsisLoc(),
7943 NumExpansions);
7944 if (To.isNull())
7945 return ExprError();
7946
7947 PackExpansionTypeLoc ToExpansionTL
7948 = TLB.push<PackExpansionTypeLoc>(To);
7949 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7950 }
7951
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007952 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7953 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007955 if (!RetainExpansion)
7956 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007957
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007958 // If we're supposed to retain a pack expansion, do so by temporarily
7959 // forgetting the partially-substituted parameter pack.
7960 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7961
7962 TypeLocBuilder TLB;
7963 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007964
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007965 QualType To = getDerived().TransformType(TLB, PatternTL);
7966 if (To.isNull())
7967 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968
7969 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007970 PatternTL.getSourceRange(),
7971 ExpansionTL.getEllipsisLoc(),
7972 NumExpansions);
7973 if (To.isNull())
7974 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007975
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007976 PackExpansionTypeLoc ToExpansionTL
7977 = TLB.push<PackExpansionTypeLoc>(To);
7978 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7979 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7980 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007981
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007982 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7983 return SemaRef.Owned(E);
7984
7985 return getDerived().RebuildTypeTrait(E->getTrait(),
7986 E->getLocStart(),
7987 Args,
7988 E->getLocEnd());
7989}
7990
7991template<typename Derived>
7992ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007993TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7994 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7995 if (!T)
7996 return ExprError();
7997
7998 if (!getDerived().AlwaysRebuild() &&
7999 T == E->getQueriedTypeSourceInfo())
8000 return SemaRef.Owned(E);
8001
8002 ExprResult SubExpr;
8003 {
8004 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8005 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8006 if (SubExpr.isInvalid())
8007 return ExprError();
8008
8009 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8010 return SemaRef.Owned(E);
8011 }
8012
8013 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8014 E->getLocStart(),
8015 T,
8016 SubExpr.get(),
8017 E->getLocEnd());
8018}
8019
8020template<typename Derived>
8021ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008022TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8023 ExprResult SubExpr;
8024 {
8025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8026 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8027 if (SubExpr.isInvalid())
8028 return ExprError();
8029
8030 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8031 return SemaRef.Owned(E);
8032 }
8033
8034 return getDerived().RebuildExpressionTrait(
8035 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8036}
8037
8038template<typename Derived>
8039ExprResult
John McCall865d4472009-11-19 22:55:06 +00008040TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008041 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008042 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8043}
8044
8045template<typename Derived>
8046ExprResult
8047TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8048 DependentScopeDeclRefExpr *E,
8049 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008050 NestedNameSpecifierLoc QualifierLoc
8051 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8052 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008053 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008054 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008055
John McCall43fed0d2010-11-12 08:19:04 +00008056 // TODO: If this is a conversion-function-id, verify that the
8057 // destination type name (if present) resolves the same way after
8058 // instantiation as it did in the local scope.
8059
Abramo Bagnara25777432010-08-11 22:01:17 +00008060 DeclarationNameInfo NameInfo
8061 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8062 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008063 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008064
John McCallf7a1a742009-11-24 19:00:30 +00008065 if (!E->hasExplicitTemplateArgs()) {
8066 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008067 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008068 // Note: it is sufficient to compare the Name component of NameInfo:
8069 // if name has not changed, DNLoc has not changed either.
8070 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008071 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008072
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008073 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008074 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008075 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008076 /*TemplateArgs*/ 0,
8077 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008078 }
John McCalld5532b62009-11-23 01:53:49 +00008079
8080 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008081 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8082 E->getNumTemplateArgs(),
8083 TransArgs))
8084 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008085
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008086 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008087 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008088 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008089 &TransArgs,
8090 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008091}
8092
8093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008094ExprResult
John McCall454feb92009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008096 // CXXConstructExprs other than for list-initialization and
8097 // CXXTemporaryObjectExpr are always implicit, so when we have
8098 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008099 if ((E->getNumArgs() == 1 ||
8100 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008101 (!getDerived().DropCallArgument(E->getArg(0))) &&
8102 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008103 return getDerived().TransformExpr(E->getArg(0));
8104
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8106
8107 QualType T = getDerived().TransformType(E->getType());
8108 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008109 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008110
8111 CXXConstructorDecl *Constructor
8112 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008113 getDerived().TransformDecl(E->getLocStart(),
8114 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008115 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008117
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008119 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008120 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008121 &ArgumentChanged))
8122 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008123
Douglas Gregorb98b1992009-08-11 05:31:07 +00008124 if (!getDerived().AlwaysRebuild() &&
8125 T == E->getType() &&
8126 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008127 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008128 // Mark the constructor as referenced.
8129 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008130 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008131 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008132 }
Mike Stump1eb44332009-09-09 15:08:12 +00008133
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008134 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8135 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008136 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008137 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008138 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008139 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008140 E->getConstructionKind(),
8141 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008142}
Mike Stump1eb44332009-09-09 15:08:12 +00008143
Douglas Gregorb98b1992009-08-11 05:31:07 +00008144/// \brief Transform a C++ temporary-binding expression.
8145///
Douglas Gregor51326552009-12-24 18:51:59 +00008146/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8147/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008149ExprResult
John McCall454feb92009-12-08 09:21:05 +00008150TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008151 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008152}
Mike Stump1eb44332009-09-09 15:08:12 +00008153
John McCall4765fa02010-12-06 08:20:24 +00008154/// \brief Transform a C++ expression that contains cleanups that should
8155/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008156///
John McCall4765fa02010-12-06 08:20:24 +00008157/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008158/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008160ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008161TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008162 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163}
Mike Stump1eb44332009-09-09 15:08:12 +00008164
Douglas Gregorb98b1992009-08-11 05:31:07 +00008165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008166ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008167TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008168 CXXTemporaryObjectExpr *E) {
8169 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8170 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008172
Douglas Gregorb98b1992009-08-11 05:31:07 +00008173 CXXConstructorDecl *Constructor
8174 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008175 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008176 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008177 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008179
Douglas Gregorb98b1992009-08-11 05:31:07 +00008180 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008181 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008182 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008183 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008184 &ArgumentChanged))
8185 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008186
Douglas Gregorb98b1992009-08-11 05:31:07 +00008187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008188 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008189 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008190 !ArgumentChanged) {
8191 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008192 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008193 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195
Richard Smithc83c2302012-12-19 01:39:02 +00008196 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008197 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8198 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008199 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200 E->getLocEnd());
8201}
Mike Stump1eb44332009-09-09 15:08:12 +00008202
Douglas Gregorb98b1992009-08-11 05:31:07 +00008203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008204ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008205TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008206 // Transform the type of the lambda parameters and start the definition of
8207 // the lambda itself.
8208 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008209 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008210 if (!MethodTy)
8211 return ExprError();
8212
Eli Friedman8da8a662012-09-19 01:18:11 +00008213 // Create the local class that will describe the lambda.
8214 CXXRecordDecl *Class
8215 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8216 MethodTy,
8217 /*KnownDependent=*/false);
8218 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8219
Douglas Gregorc6889e72012-02-14 22:28:59 +00008220 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008221 SmallVector<QualType, 4> ParamTypes;
8222 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008223 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8224 E->getCallOperator()->param_begin(),
8225 E->getCallOperator()->param_size(),
8226 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008227 return ExprError();
Manuel Klimek152b4e42013-08-22 12:12:24 +00008228
Douglas Gregordfca6f52012-02-13 22:00:16 +00008229 // Build the call operator.
8230 CXXMethodDecl *CallOperator
8231 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008232 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008233 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008234 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008235 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008236
Richard Smith612409e2012-07-25 03:56:55 +00008237 return getDerived().TransformLambdaScope(E, CallOperator);
8238}
8239
8240template<typename Derived>
8241ExprResult
8242TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8243 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008244 bool Invalid = false;
8245
8246 // Transform any init-capture expressions before entering the scope of the
8247 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008248 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008249 InitCaptureExprs.resize(E->explicit_capture_end() -
8250 E->explicit_capture_begin());
8251 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8252 CEnd = E->capture_end();
8253 C != CEnd; ++C) {
8254 if (!C->isInitCapture())
8255 continue;
8256 InitCaptureExprs[C - E->capture_begin()] =
8257 getDerived().TransformExpr(E->getInitCaptureInit(C));
8258 }
8259
Douglas Gregord5387e82012-02-14 00:00:48 +00008260 // Introduce the context of the call operator.
8261 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8262
Douglas Gregordfca6f52012-02-13 22:00:16 +00008263 // Enter the scope of the lambda.
Manuel Klimek152b4e42013-08-22 12:12:24 +00008264 sema::LambdaScopeInfo *LSI
8265 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008266 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008267 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008268 E->hasExplicitParameters(),
8269 E->hasExplicitResultType(),
8270 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008271
Douglas Gregordfca6f52012-02-13 22:00:16 +00008272 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008273 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008274 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008275 CEnd = E->capture_end();
8276 C != CEnd; ++C) {
8277 // When we hit the first implicit capture, tell Sema that we've finished
8278 // the list of explicit captures.
8279 if (!FinishedExplicitCaptures && C->isImplicit()) {
8280 getSema().finishLambdaExplicitCaptures(LSI);
8281 FinishedExplicitCaptures = true;
8282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008283
Douglas Gregordfca6f52012-02-13 22:00:16 +00008284 // Capturing 'this' is trivial.
8285 if (C->capturesThis()) {
8286 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8287 continue;
8288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008289
Richard Smith0d8e9642013-05-16 06:20:58 +00008290 // Rebuild init-captures, including the implied field declaration.
8291 if (C->isInitCapture()) {
8292 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8293 if (Init.isInvalid()) {
8294 Invalid = true;
8295 continue;
8296 }
8297 FieldDecl *OldFD = C->getInitCaptureField();
8298 FieldDecl *NewFD = getSema().checkInitCapture(
8299 C->getLocation(), OldFD->getType()->isReferenceType(),
8300 OldFD->getIdentifier(), Init.take());
8301 if (!NewFD)
8302 Invalid = true;
8303 else
8304 getDerived().transformedLocalDecl(OldFD, NewFD);
8305 continue;
8306 }
8307
8308 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8309
Douglas Gregora7365242012-02-14 19:27:52 +00008310 // Determine the capture kind for Sema.
8311 Sema::TryCaptureKind Kind
8312 = C->isImplicit()? Sema::TryCapture_Implicit
8313 : C->getCaptureKind() == LCK_ByCopy
8314 ? Sema::TryCapture_ExplicitByVal
8315 : Sema::TryCapture_ExplicitByRef;
8316 SourceLocation EllipsisLoc;
8317 if (C->isPackExpansion()) {
8318 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8319 bool ShouldExpand = false;
8320 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008321 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008322 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8323 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008324 Unexpanded,
8325 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008326 NumExpansions)) {
8327 Invalid = true;
8328 continue;
8329 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008330
Douglas Gregora7365242012-02-14 19:27:52 +00008331 if (ShouldExpand) {
8332 // The transform has determined that we should perform an expansion;
8333 // transform and capture each of the arguments.
8334 // expansion of the pattern. Do so.
8335 VarDecl *Pack = C->getCapturedVar();
8336 for (unsigned I = 0; I != *NumExpansions; ++I) {
8337 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8338 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008339 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008340 Pack));
8341 if (!CapturedVar) {
8342 Invalid = true;
8343 continue;
8344 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008345
Douglas Gregora7365242012-02-14 19:27:52 +00008346 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8348 }
Douglas Gregora7365242012-02-14 19:27:52 +00008349 continue;
8350 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351
Douglas Gregora7365242012-02-14 19:27:52 +00008352 EllipsisLoc = C->getEllipsisLoc();
8353 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354
Douglas Gregordfca6f52012-02-13 22:00:16 +00008355 // Transform the captured variable.
8356 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008358 C->getCapturedVar()));
8359 if (!CapturedVar) {
8360 Invalid = true;
8361 continue;
8362 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363
Douglas Gregordfca6f52012-02-13 22:00:16 +00008364 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008365 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008366 }
8367 if (!FinishedExplicitCaptures)
8368 getSema().finishLambdaExplicitCaptures(LSI);
8369
Douglas Gregordfca6f52012-02-13 22:00:16 +00008370
8371 // Enter a new evaluation context to insulate the lambda from any
8372 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008373 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008374
8375 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008376 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008377 /*IsInstantiation=*/true);
8378 return ExprError();
8379 }
8380
8381 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008382 StmtResult Body = getDerived().TransformStmt(E->getBody());
8383 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008384 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008385 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008386 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008387 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008388
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008390 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008391}
8392
8393template<typename Derived>
8394ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008395TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008396 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008397 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8398 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008400
Douglas Gregorb98b1992009-08-11 05:31:07 +00008401 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008402 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008403 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008404 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008405 &ArgumentChanged))
8406 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008407
Douglas Gregorb98b1992009-08-11 05:31:07 +00008408 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008409 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008410 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008411 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008412
Douglas Gregorb98b1992009-08-11 05:31:07 +00008413 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008414 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008415 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008416 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008417 E->getRParenLoc());
8418}
Mike Stump1eb44332009-09-09 15:08:12 +00008419
Douglas Gregorb98b1992009-08-11 05:31:07 +00008420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008421ExprResult
John McCall865d4472009-11-19 22:55:06 +00008422TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008423 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008424 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008425 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008426 Expr *OldBase;
8427 QualType BaseType;
8428 QualType ObjectType;
8429 if (!E->isImplicitAccess()) {
8430 OldBase = E->getBase();
8431 Base = getDerived().TransformExpr(OldBase);
8432 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008434
John McCallaa81e162009-12-01 22:10:20 +00008435 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008436 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008437 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008438 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008439 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008440 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008441 ObjectTy,
8442 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008443 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008444 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008445
John McCallb3d87482010-08-24 05:47:05 +00008446 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008447 BaseType = ((Expr*) Base.get())->getType();
8448 } else {
8449 OldBase = 0;
8450 BaseType = getDerived().TransformType(E->getBaseType());
8451 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8452 }
Mike Stump1eb44332009-09-09 15:08:12 +00008453
Douglas Gregor6cd21982009-10-20 05:58:46 +00008454 // Transform the first part of the nested-name-specifier that qualifies
8455 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008456 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008457 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008458 E->getFirstQualifierFoundInScope(),
8459 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008460
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008461 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008462 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008463 QualifierLoc
8464 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8465 ObjectType,
8466 FirstQualifierInScope);
8467 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008468 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008469 }
Mike Stump1eb44332009-09-09 15:08:12 +00008470
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008471 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8472
John McCall43fed0d2010-11-12 08:19:04 +00008473 // TODO: If this is a conversion-function-id, verify that the
8474 // destination type name (if present) resolves the same way after
8475 // instantiation as it did in the local scope.
8476
Abramo Bagnara25777432010-08-11 22:01:17 +00008477 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008478 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008479 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008481
John McCallaa81e162009-12-01 22:10:20 +00008482 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008483 // This is a reference to a member without an explicitly-specified
8484 // template argument list. Optimize for this common case.
8485 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008486 Base.get() == OldBase &&
8487 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008488 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008489 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008490 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008491 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008492
John McCall9ae2f072010-08-23 23:25:46 +00008493 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008494 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008495 E->isArrow(),
8496 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008497 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008498 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008499 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008500 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008501 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008502 }
8503
John McCalld5532b62009-11-23 01:53:49 +00008504 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008505 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8506 E->getNumTemplateArgs(),
8507 TransArgs))
8508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008509
John McCall9ae2f072010-08-23 23:25:46 +00008510 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008511 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008512 E->isArrow(),
8513 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008514 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008515 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008516 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008517 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008518 &TransArgs);
8519}
8520
8521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008522ExprResult
John McCall454feb92009-12-08 09:21:05 +00008523TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008524 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008525 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008526 QualType BaseType;
8527 if (!Old->isImplicitAccess()) {
8528 Base = getDerived().TransformExpr(Old->getBase());
8529 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008530 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008531 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8532 Old->isArrow());
8533 if (Base.isInvalid())
8534 return ExprError();
8535 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008536 } else {
8537 BaseType = getDerived().TransformType(Old->getBaseType());
8538 }
John McCall129e2df2009-11-30 22:42:35 +00008539
Douglas Gregor4c9be892011-02-28 20:01:57 +00008540 NestedNameSpecifierLoc QualifierLoc;
8541 if (Old->getQualifierLoc()) {
8542 QualifierLoc
8543 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8544 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008545 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008546 }
8547
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008548 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8549
Abramo Bagnara25777432010-08-11 22:01:17 +00008550 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008551 Sema::LookupOrdinaryName);
8552
8553 // Transform all the decls.
8554 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8555 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008556 NamedDecl *InstD = static_cast<NamedDecl*>(
8557 getDerived().TransformDecl(Old->getMemberLoc(),
8558 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008559 if (!InstD) {
8560 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8561 // This can happen because of dependent hiding.
8562 if (isa<UsingShadowDecl>(*I))
8563 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008564 else {
8565 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008566 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008567 }
John McCall9f54ad42009-12-10 09:41:52 +00008568 }
John McCall129e2df2009-11-30 22:42:35 +00008569
8570 // Expand using declarations.
8571 if (isa<UsingDecl>(InstD)) {
8572 UsingDecl *UD = cast<UsingDecl>(InstD);
8573 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8574 E = UD->shadow_end(); I != E; ++I)
8575 R.addDecl(*I);
8576 continue;
8577 }
8578
8579 R.addDecl(InstD);
8580 }
8581
8582 R.resolveKind();
8583
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008584 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008585 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008586 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008587 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008588 Old->getMemberLoc(),
8589 Old->getNamingClass()));
8590 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008591 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008592
Douglas Gregor66c45152010-04-27 16:10:10 +00008593 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008594 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008595
John McCall129e2df2009-11-30 22:42:35 +00008596 TemplateArgumentListInfo TransArgs;
8597 if (Old->hasExplicitTemplateArgs()) {
8598 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8599 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008600 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8601 Old->getNumTemplateArgs(),
8602 TransArgs))
8603 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008604 }
John McCallc2233c52010-01-15 08:34:02 +00008605
8606 // FIXME: to do this check properly, we will need to preserve the
8607 // first-qualifier-in-scope here, just in case we had a dependent
8608 // base (and therefore couldn't do the check) and a
8609 // nested-name-qualifier (and therefore could do the lookup).
8610 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008611
John McCall9ae2f072010-08-23 23:25:46 +00008612 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008613 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008614 Old->getOperatorLoc(),
8615 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008616 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008617 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008618 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008619 R,
8620 (Old->hasExplicitTemplateArgs()
8621 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008622}
8623
8624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008625ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008626TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008627 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008628 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8629 if (SubExpr.isInvalid())
8630 return ExprError();
8631
8632 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008633 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008634
8635 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8636}
8637
8638template<typename Derived>
8639ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008640TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008641 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8642 if (Pattern.isInvalid())
8643 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008644
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008645 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8646 return SemaRef.Owned(E);
8647
Douglas Gregor67fd1252011-01-14 21:20:45 +00008648 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8649 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008650}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008651
8652template<typename Derived>
8653ExprResult
8654TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8655 // If E is not value-dependent, then nothing will change when we transform it.
8656 // Note: This is an instantiation-centric view.
8657 if (!E->isValueDependent())
8658 return SemaRef.Owned(E);
8659
8660 // Note: None of the implementations of TryExpandParameterPacks can ever
8661 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008662 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008663 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8664 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008665 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008666 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008667 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008668 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008669 ShouldExpand, RetainExpansion,
8670 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008671 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008672
Douglas Gregor089e8932011-10-10 18:59:29 +00008673 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008674 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008675
Douglas Gregor089e8932011-10-10 18:59:29 +00008676 NamedDecl *Pack = E->getPack();
8677 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008678 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008679 Pack));
8680 if (!Pack)
8681 return ExprError();
8682 }
8683
Chad Rosier4a9d7952012-08-08 18:46:20 +00008684
Douglas Gregoree8aff02011-01-04 17:33:58 +00008685 // We now know the length of the parameter pack, so build a new expression
8686 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008687 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8688 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008689 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008690}
8691
Douglas Gregorbe230c32011-01-03 17:17:50 +00008692template<typename Derived>
8693ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008694TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8695 SubstNonTypeTemplateParmPackExpr *E) {
8696 // Default behavior is to do nothing with this transformation.
8697 return SemaRef.Owned(E);
8698}
8699
8700template<typename Derived>
8701ExprResult
John McCall91a57552011-07-15 05:09:51 +00008702TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8703 SubstNonTypeTemplateParmExpr *E) {
8704 // Default behavior is to do nothing with this transformation.
8705 return SemaRef.Owned(E);
8706}
8707
8708template<typename Derived>
8709ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008710TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8711 // Default behavior is to do nothing with this transformation.
8712 return SemaRef.Owned(E);
8713}
8714
8715template<typename Derived>
8716ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008717TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8718 MaterializeTemporaryExpr *E) {
8719 return getDerived().TransformExpr(E->GetTemporaryExpr());
8720}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008721
Douglas Gregor03e80032011-06-21 17:03:29 +00008722template<typename Derived>
8723ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008724TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8725 CXXStdInitializerListExpr *E) {
8726 return getDerived().TransformExpr(E->getSubExpr());
8727}
8728
8729template<typename Derived>
8730ExprResult
John McCall454feb92009-12-08 09:21:05 +00008731TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008732 return SemaRef.MaybeBindToTemporary(E);
8733}
8734
8735template<typename Derived>
8736ExprResult
8737TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008738 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008739}
8740
8741template<typename Derived>
8742ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008743TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8744 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8745 if (SubExpr.isInvalid())
8746 return ExprError();
8747
8748 if (!getDerived().AlwaysRebuild() &&
8749 SubExpr.get() == E->getSubExpr())
8750 return SemaRef.Owned(E);
8751
8752 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008753}
8754
8755template<typename Derived>
8756ExprResult
8757TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8758 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008759 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008760 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008761 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008762 /*IsCall=*/false, Elements, &ArgChanged))
8763 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008764
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008765 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8766 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008767
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008768 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8769 Elements.data(),
8770 Elements.size());
8771}
8772
8773template<typename Derived>
8774ExprResult
8775TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008776 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008777 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008778 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008779 bool ArgChanged = false;
8780 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8781 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008783 if (OrigElement.isPackExpansion()) {
8784 // This key/value element is a pack expansion.
8785 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8786 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8787 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8788 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8789
8790 // Determine whether the set of unexpanded parameter packs can
8791 // and should be expanded.
8792 bool Expand = true;
8793 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008794 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8795 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008796 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8797 OrigElement.Value->getLocEnd());
8798 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8799 PatternRange,
8800 Unexpanded,
8801 Expand, RetainExpansion,
8802 NumExpansions))
8803 return ExprError();
8804
8805 if (!Expand) {
8806 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008807 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008808 // expansion.
8809 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8810 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8811 if (Key.isInvalid())
8812 return ExprError();
8813
8814 if (Key.get() != OrigElement.Key)
8815 ArgChanged = true;
8816
8817 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8818 if (Value.isInvalid())
8819 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008821 if (Value.get() != OrigElement.Value)
8822 ArgChanged = true;
8823
Chad Rosier4a9d7952012-08-08 18:46:20 +00008824 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008825 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8826 };
8827 Elements.push_back(Expansion);
8828 continue;
8829 }
8830
8831 // Record right away that the argument was changed. This needs
8832 // to happen even if the array expands to nothing.
8833 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008834
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008835 // The transform has determined that we should perform an elementwise
8836 // expansion of the pattern. Do so.
8837 for (unsigned I = 0; I != *NumExpansions; ++I) {
8838 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8839 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8840 if (Key.isInvalid())
8841 return ExprError();
8842
8843 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8844 if (Value.isInvalid())
8845 return ExprError();
8846
Chad Rosier4a9d7952012-08-08 18:46:20 +00008847 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008848 Key.get(), Value.get(), SourceLocation(), NumExpansions
8849 };
8850
8851 // If any unexpanded parameter packs remain, we still have a
8852 // pack expansion.
8853 if (Key.get()->containsUnexpandedParameterPack() ||
8854 Value.get()->containsUnexpandedParameterPack())
8855 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008856
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008857 Elements.push_back(Element);
8858 }
8859
8860 // We've finished with this pack expansion.
8861 continue;
8862 }
8863
8864 // Transform and check key.
8865 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8866 if (Key.isInvalid())
8867 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008868
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008869 if (Key.get() != OrigElement.Key)
8870 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008871
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008872 // Transform and check value.
8873 ExprResult Value
8874 = getDerived().TransformExpr(OrigElement.Value);
8875 if (Value.isInvalid())
8876 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008877
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878 if (Value.get() != OrigElement.Value)
8879 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008880
8881 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008882 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008883 };
8884 Elements.push_back(Element);
8885 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008886
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008887 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8888 return SemaRef.MaybeBindToTemporary(E);
8889
8890 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8891 Elements.data(),
8892 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008893}
8894
Mike Stump1eb44332009-09-09 15:08:12 +00008895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008896ExprResult
John McCall454feb92009-12-08 09:21:05 +00008897TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008898 TypeSourceInfo *EncodedTypeInfo
8899 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8900 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008902
Douglas Gregorb98b1992009-08-11 05:31:07 +00008903 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008904 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008905 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008906
8907 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008908 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008909 E->getRParenLoc());
8910}
Mike Stump1eb44332009-09-09 15:08:12 +00008911
Douglas Gregorb98b1992009-08-11 05:31:07 +00008912template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008913ExprResult TreeTransform<Derived>::
8914TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008915 // This is a kind of implicit conversion, and it needs to get dropped
8916 // and recomputed for the same general reasons that ImplicitCastExprs
8917 // do, as well a more specific one: this expression is only valid when
8918 // it appears *immediately* as an argument expression.
8919 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008920}
8921
8922template<typename Derived>
8923ExprResult TreeTransform<Derived>::
8924TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008925 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008926 = getDerived().TransformType(E->getTypeInfoAsWritten());
8927 if (!TSInfo)
8928 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008929
John McCallf85e1932011-06-15 23:02:42 +00008930 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008932 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008933
John McCallf85e1932011-06-15 23:02:42 +00008934 if (!getDerived().AlwaysRebuild() &&
8935 TSInfo == E->getTypeInfoAsWritten() &&
8936 Result.get() == E->getSubExpr())
8937 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008938
John McCallf85e1932011-06-15 23:02:42 +00008939 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008940 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008941 Result.get());
8942}
8943
8944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008945ExprResult
John McCall454feb92009-12-08 09:21:05 +00008946TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008947 // Transform arguments.
8948 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008949 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008950 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008951 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008952 &ArgChanged))
8953 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008954
Douglas Gregor92e986e2010-04-22 16:44:27 +00008955 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8956 // Class message: transform the receiver type.
8957 TypeSourceInfo *ReceiverTypeInfo
8958 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8959 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008960 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008961
Douglas Gregor92e986e2010-04-22 16:44:27 +00008962 // If nothing changed, just retain the existing message send.
8963 if (!getDerived().AlwaysRebuild() &&
8964 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008965 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008966
8967 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008968 SmallVector<SourceLocation, 16> SelLocs;
8969 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008970 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8971 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008972 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008973 E->getMethodDecl(),
8974 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008975 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008976 E->getRightLoc());
8977 }
8978
8979 // Instance message: transform the receiver
8980 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8981 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008982 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008983 = getDerived().TransformExpr(E->getInstanceReceiver());
8984 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008985 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008986
8987 // If nothing changed, just retain the existing message send.
8988 if (!getDerived().AlwaysRebuild() &&
8989 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008990 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008991
Douglas Gregor92e986e2010-04-22 16:44:27 +00008992 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008993 SmallVector<SourceLocation, 16> SelLocs;
8994 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008995 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008996 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008997 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008998 E->getMethodDecl(),
8999 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009000 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009001 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009002}
9003
Mike Stump1eb44332009-09-09 15:08:12 +00009004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009005ExprResult
John McCall454feb92009-12-08 09:21:05 +00009006TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009007 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009008}
9009
Mike Stump1eb44332009-09-09 15:08:12 +00009010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009011ExprResult
John McCall454feb92009-12-08 09:21:05 +00009012TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009013 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009014}
9015
Mike Stump1eb44332009-09-09 15:08:12 +00009016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009017ExprResult
John McCall454feb92009-12-08 09:21:05 +00009018TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009019 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009020 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009021 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009022 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009023
9024 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009025
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009026 // If nothing changed, just retain the existing expression.
9027 if (!getDerived().AlwaysRebuild() &&
9028 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009029 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009030
John McCall9ae2f072010-08-23 23:25:46 +00009031 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009032 E->getLocation(),
9033 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009034}
9035
Mike Stump1eb44332009-09-09 15:08:12 +00009036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009037ExprResult
John McCall454feb92009-12-08 09:21:05 +00009038TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009039 // 'super' and types never change. Property never changes. Just
9040 // retain the existing expression.
9041 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009042 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009043
Douglas Gregore3303542010-04-26 20:47:02 +00009044 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009045 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009046 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009047 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009048
Douglas Gregore3303542010-04-26 20:47:02 +00009049 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009050
Douglas Gregore3303542010-04-26 20:47:02 +00009051 // If nothing changed, just retain the existing expression.
9052 if (!getDerived().AlwaysRebuild() &&
9053 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009054 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009055
John McCall12f78a62010-12-02 01:19:52 +00009056 if (E->isExplicitProperty())
9057 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9058 E->getExplicitProperty(),
9059 E->getLocation());
9060
9061 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009062 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009063 E->getImplicitPropertyGetter(),
9064 E->getImplicitPropertySetter(),
9065 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009066}
9067
Mike Stump1eb44332009-09-09 15:08:12 +00009068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009069ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009070TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9071 // Transform the base expression.
9072 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9073 if (Base.isInvalid())
9074 return ExprError();
9075
9076 // Transform the key expression.
9077 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9078 if (Key.isInvalid())
9079 return ExprError();
9080
9081 // If nothing changed, just retain the existing expression.
9082 if (!getDerived().AlwaysRebuild() &&
9083 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9084 return SemaRef.Owned(E);
9085
Chad Rosier4a9d7952012-08-08 18:46:20 +00009086 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009087 Base.get(), Key.get(),
9088 E->getAtIndexMethodDecl(),
9089 E->setAtIndexMethodDecl());
9090}
9091
9092template<typename Derived>
9093ExprResult
John McCall454feb92009-12-08 09:21:05 +00009094TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009095 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009096 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009097 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009098 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009099
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009100 // If nothing changed, just retain the existing expression.
9101 if (!getDerived().AlwaysRebuild() &&
9102 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009103 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009104
John McCall9ae2f072010-08-23 23:25:46 +00009105 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009106 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009107 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009108}
9109
Mike Stump1eb44332009-09-09 15:08:12 +00009110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009111ExprResult
John McCall454feb92009-12-08 09:21:05 +00009112TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009113 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009114 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009115 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009116 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009117 SubExprs, &ArgumentChanged))
9118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009119
Douglas Gregorb98b1992009-08-11 05:31:07 +00009120 if (!getDerived().AlwaysRebuild() &&
9121 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009122 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009123
Douglas Gregorb98b1992009-08-11 05:31:07 +00009124 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009125 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126 E->getRParenLoc());
9127}
9128
Mike Stump1eb44332009-09-09 15:08:12 +00009129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009130ExprResult
John McCall454feb92009-12-08 09:21:05 +00009131TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009132 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009133
John McCallc6ac9c32011-02-04 18:33:18 +00009134 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9135 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9136
9137 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009138 blockScope->TheDecl->setBlockMissingReturnType(
9139 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009140
Chris Lattner686775d2011-07-20 06:58:45 +00009141 SmallVector<ParmVarDecl*, 4> params;
9142 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009143
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009144 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009145 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9146 oldBlock->param_begin(),
9147 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009148 0, paramTypes, &params)) {
9149 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009150 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009151 }
John McCallc6ac9c32011-02-04 18:33:18 +00009152
Jordan Rose09189892013-03-08 22:25:36 +00009153 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009154 QualType exprResultType =
9155 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009156
Jordan Rosebea522f2013-03-08 21:51:21 +00009157 QualType functionType =
9158 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009159 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009160 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009161
9162 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009163 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009164 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009165
9166 if (!oldBlock->blockMissingReturnType()) {
9167 blockScope->HasImplicitReturnType = false;
9168 blockScope->ReturnType = exprResultType;
9169 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009170
John McCall711c52b2011-01-05 12:14:39 +00009171 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009172 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009173 if (body.isInvalid()) {
9174 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009175 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009176 }
John McCall711c52b2011-01-05 12:14:39 +00009177
John McCallc6ac9c32011-02-04 18:33:18 +00009178#ifndef NDEBUG
9179 // In builds with assertions, make sure that we captured everything we
9180 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009181 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9182 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9183 e = oldBlock->capture_end(); i != e; ++i) {
9184 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009185
Douglas Gregorfc921372011-05-20 15:32:55 +00009186 // Ignore parameter packs.
9187 if (isa<ParmVarDecl>(oldCapture) &&
9188 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9189 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009190
Douglas Gregorfc921372011-05-20 15:32:55 +00009191 VarDecl *newCapture =
9192 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9193 oldCapture));
9194 assert(blockScope->CaptureMap.count(newCapture));
9195 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009196 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009197 }
9198#endif
9199
9200 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9201 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009202}
9203
Mike Stump1eb44332009-09-09 15:08:12 +00009204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009205ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009206TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009207 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009208}
Eli Friedman276b0612011-10-11 02:20:01 +00009209
9210template<typename Derived>
9211ExprResult
9212TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009213 QualType RetTy = getDerived().TransformType(E->getType());
9214 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009215 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009216 SubExprs.reserve(E->getNumSubExprs());
9217 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9218 SubExprs, &ArgumentChanged))
9219 return ExprError();
9220
9221 if (!getDerived().AlwaysRebuild() &&
9222 !ArgumentChanged)
9223 return SemaRef.Owned(E);
9224
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009225 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009226 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009227}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009228
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009230// Type reconstruction
9231//===----------------------------------------------------------------------===//
9232
Mike Stump1eb44332009-09-09 15:08:12 +00009233template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009234QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9235 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009236 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009237 getDerived().getBaseEntity());
9238}
9239
Mike Stump1eb44332009-09-09 15:08:12 +00009240template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009241QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9242 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009243 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009244 getDerived().getBaseEntity());
9245}
9246
Mike Stump1eb44332009-09-09 15:08:12 +00009247template<typename Derived>
9248QualType
John McCall85737a72009-10-30 00:06:24 +00009249TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9250 bool WrittenAsLValue,
9251 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009252 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009253 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009254}
9255
9256template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009257QualType
John McCall85737a72009-10-30 00:06:24 +00009258TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9259 QualType ClassType,
9260 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009261 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009262 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009263}
9264
9265template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009266QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009267TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9268 ArrayType::ArraySizeModifier SizeMod,
9269 const llvm::APInt *Size,
9270 Expr *SizeExpr,
9271 unsigned IndexTypeQuals,
9272 SourceRange BracketsRange) {
9273 if (SizeExpr || !Size)
9274 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9275 IndexTypeQuals, BracketsRange,
9276 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009277
9278 QualType Types[] = {
9279 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9280 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9281 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009282 };
Craig Topperb9602322013-07-15 03:38:40 +00009283 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009284 QualType SizeType;
9285 for (unsigned I = 0; I != NumTypes; ++I)
9286 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9287 SizeType = Types[I];
9288 break;
9289 }
Mike Stump1eb44332009-09-09 15:08:12 +00009290
Eli Friedman01f276d2012-01-25 23:20:27 +00009291 // Note that we can return a VariableArrayType here in the case where
9292 // the element type was a dependent VariableArrayType.
9293 IntegerLiteral *ArraySize
9294 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9295 /*FIXME*/BracketsRange.getBegin());
9296 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009297 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009298 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009299}
Mike Stump1eb44332009-09-09 15:08:12 +00009300
Douglas Gregor577f75a2009-08-04 16:50:30 +00009301template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009302QualType
9303TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009304 ArrayType::ArraySizeModifier SizeMod,
9305 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009306 unsigned IndexTypeQuals,
9307 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009308 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009309 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009310}
9311
9312template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009313QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009314TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009315 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009316 unsigned IndexTypeQuals,
9317 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009318 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009319 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009320}
Mike Stump1eb44332009-09-09 15:08:12 +00009321
Douglas Gregor577f75a2009-08-04 16:50:30 +00009322template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009323QualType
9324TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009325 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009326 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009327 unsigned IndexTypeQuals,
9328 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009329 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009330 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009331 IndexTypeQuals, BracketsRange);
9332}
9333
9334template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009335QualType
9336TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009337 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009338 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009339 unsigned IndexTypeQuals,
9340 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009341 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009342 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009343 IndexTypeQuals, BracketsRange);
9344}
9345
9346template<typename Derived>
9347QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009348 unsigned NumElements,
9349 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009350 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009351 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009352}
Mike Stump1eb44332009-09-09 15:08:12 +00009353
Douglas Gregor577f75a2009-08-04 16:50:30 +00009354template<typename Derived>
9355QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9356 unsigned NumElements,
9357 SourceLocation AttributeLoc) {
9358 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9359 NumElements, true);
9360 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009361 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9362 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009363 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009364}
Mike Stump1eb44332009-09-09 15:08:12 +00009365
Douglas Gregor577f75a2009-08-04 16:50:30 +00009366template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009367QualType
9368TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009369 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009370 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009371 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
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>
Jordan Rosebea522f2013-03-08 21:51:21 +00009375QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9376 QualType T,
9377 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009378 const FunctionProtoType::ExtProtoInfo &EPI) {
9379 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009380 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009381 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009382 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009383}
Mike Stump1eb44332009-09-09 15:08:12 +00009384
Douglas Gregor577f75a2009-08-04 16:50:30 +00009385template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009386QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9387 return SemaRef.Context.getFunctionNoProtoType(T);
9388}
9389
9390template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009391QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9392 assert(D && "no decl found");
9393 if (D->isInvalidDecl()) return QualType();
9394
Douglas Gregor92e986e2010-04-22 16:44:27 +00009395 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009396 TypeDecl *Ty;
9397 if (isa<UsingDecl>(D)) {
9398 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009399 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009400 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9401
9402 // A valid resolved using typename decl points to exactly one type decl.
9403 assert(++Using->shadow_begin() == Using->shadow_end());
9404 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009405
John McCalled976492009-12-04 22:46:56 +00009406 } else {
9407 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9408 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9409 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9410 }
9411
9412 return SemaRef.Context.getTypeDeclType(Ty);
9413}
9414
9415template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009416QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9417 SourceLocation Loc) {
9418 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009419}
9420
9421template<typename Derived>
9422QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9423 return SemaRef.Context.getTypeOfType(Underlying);
9424}
9425
9426template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009427QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9428 SourceLocation Loc) {
9429 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009430}
9431
9432template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009433QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9434 UnaryTransformType::UTTKind UKind,
9435 SourceLocation Loc) {
9436 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9437}
9438
9439template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009440QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009441 TemplateName Template,
9442 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009443 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009444 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009445}
Mike Stump1eb44332009-09-09 15:08:12 +00009446
Douglas Gregordcee1a12009-08-06 05:28:30 +00009447template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009448QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9449 SourceLocation KWLoc) {
9450 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9451}
9452
9453template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009454TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009455TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009456 bool TemplateKW,
9457 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009458 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009459 Template);
9460}
9461
9462template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009463TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009464TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9465 const IdentifierInfo &Name,
9466 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009467 QualType ObjectType,
9468 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009469 UnqualifiedId TemplateName;
9470 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009471 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009472 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009473 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009474 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009475 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009476 /*EnteringContext=*/false,
9477 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009478 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009479}
Mike Stump1eb44332009-09-09 15:08:12 +00009480
Douglas Gregorb98b1992009-08-11 05:31:07 +00009481template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009482TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009483TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009484 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009485 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009486 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009487 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009488 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009489 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009490 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009491 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009492 Sema::TemplateTy Template;
9493 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009494 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009495 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009496 /*EnteringContext=*/false,
9497 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009498 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009499}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009500
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009502ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009503TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9504 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009505 Expr *OrigCallee,
9506 Expr *First,
9507 Expr *Second) {
9508 Expr *Callee = OrigCallee->IgnoreParenCasts();
9509 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009510
Douglas Gregorb98b1992009-08-11 05:31:07 +00009511 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009512 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009513 if (!First->getType()->isOverloadableType() &&
9514 !Second->getType()->isOverloadableType())
9515 return getSema().CreateBuiltinArraySubscriptExpr(First,
9516 Callee->getLocStart(),
9517 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009518 } else if (Op == OO_Arrow) {
9519 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009520 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9521 } else if (Second == 0 || isPostIncDec) {
9522 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009523 // The argument is not of overloadable type, so try to create a
9524 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009525 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009526 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009527
John McCall9ae2f072010-08-23 23:25:46 +00009528 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009529 }
9530 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009531 if (!First->getType()->isOverloadableType() &&
9532 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009533 // Neither of the arguments is an overloadable type, so try to
9534 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009535 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009536 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009537 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009538 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009540
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009541 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009542 }
9543 }
Mike Stump1eb44332009-09-09 15:08:12 +00009544
9545 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009546 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009547 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009548
John McCall9ae2f072010-08-23 23:25:46 +00009549 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009550 assert(ULE->requiresADL());
9551
9552 // FIXME: Do we have to check
9553 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009554 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009555 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009556 // If we've resolved this to a particular non-member function, just call
9557 // that function. If we resolved it to a member function,
9558 // CreateOverloaded* will find that function for us.
9559 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9560 if (!isa<CXXMethodDecl>(ND))
9561 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009562 }
Mike Stump1eb44332009-09-09 15:08:12 +00009563
Douglas Gregorb98b1992009-08-11 05:31:07 +00009564 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009565 Expr *Args[2] = { First, Second };
9566 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009567
Douglas Gregorb98b1992009-08-11 05:31:07 +00009568 // Create the overloaded operator invocation for unary operators.
9569 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009570 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009571 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009572 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009573 }
Mike Stump1eb44332009-09-09 15:08:12 +00009574
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009575 if (Op == OO_Subscript) {
9576 SourceLocation LBrace;
9577 SourceLocation RBrace;
9578
9579 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9580 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9581 LBrace = SourceLocation::getFromRawEncoding(
9582 NameLoc.CXXOperatorName.BeginOpNameLoc);
9583 RBrace = SourceLocation::getFromRawEncoding(
9584 NameLoc.CXXOperatorName.EndOpNameLoc);
9585 } else {
9586 LBrace = Callee->getLocStart();
9587 RBrace = OpLoc;
9588 }
9589
9590 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9591 First, Second);
9592 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009593
Douglas Gregorb98b1992009-08-11 05:31:07 +00009594 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009595 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009596 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009597 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9598 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009600
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009601 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009602}
Mike Stump1eb44332009-09-09 15:08:12 +00009603
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009604template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009605ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009606TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009607 SourceLocation OperatorLoc,
9608 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009609 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009610 TypeSourceInfo *ScopeType,
9611 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009612 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009613 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009614 QualType BaseType = Base->getType();
9615 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009616 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009617 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009618 !BaseType->getAs<PointerType>()->getPointeeType()
9619 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009620 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009621 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009622 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009623 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009624 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009625 /*FIXME?*/true);
9626 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009627
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009628 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009629 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9630 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9631 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9632 NameInfo.setNamedTypeInfo(DestroyedType);
9633
Richard Smith6314db92012-05-15 06:15:11 +00009634 // The scope type is now known to be a valid nested name specifier
9635 // component. Tack it on to the end of the nested name specifier.
9636 if (ScopeType)
9637 SS.Extend(SemaRef.Context, SourceLocation(),
9638 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009639
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009640 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009641 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009642 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009643 SS, TemplateKWLoc,
9644 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009645 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009646 /*TemplateArgs*/ 0);
9647}
9648
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009649template<typename Derived>
9650StmtResult
9651TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009652 SourceLocation Loc = S->getLocStart();
9653 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9654 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9655 S->getCapturedRegionKind(), NumParams);
9656 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9657
9658 if (Body.isInvalid()) {
9659 getSema().ActOnCapturedRegionError();
9660 return StmtError();
9661 }
9662
9663 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009664}
9665
Douglas Gregor577f75a2009-08-04 16:50:30 +00009666} // end namespace clang
9667
9668#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H