blob: 008e1eafe44e8f361b5dda8dea96f44bd1accd41 [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
Alexey Bataev0c018352013-09-06 18:03:48 +00001315 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1316 SourceLocation StartLoc,
1317 SourceLocation LParenLoc,
1318 SourceLocation EndLoc) {
1319 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1320 EndLoc);
1321 }
1322
James Dennett699c9042012-06-15 07:13:21 +00001323 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001324 ///
1325 /// By default, performs semantic analysis to build the new statement.
1326 /// Subclasses may override this routine to provide different behavior.
1327 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1328 Expr *object) {
1329 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1330 }
1331
James Dennett699c9042012-06-15 07:13:21 +00001332 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001333 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001337 Expr *Object, Stmt *Body) {
1338 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001339 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001340
James Dennett699c9042012-06-15 07:13:21 +00001341 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1346 Stmt *Body) {
1347 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1348 }
John McCall990567c2011-07-27 01:07:15 +00001349
Douglas Gregorc3203e72010-04-22 23:10:45 +00001350 /// \brief Build a new Objective-C fast enumeration statement.
1351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001354 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001355 Stmt *Element,
1356 Expr *Collection,
1357 SourceLocation RParenLoc,
1358 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001359 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001360 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001362 RParenLoc);
1363 if (ForEachStmt.isInvalid())
1364 return StmtError();
1365
1366 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001368
Douglas Gregor43959a92009-08-20 07:17:43 +00001369 /// \brief Build a new C++ exception declaration.
1370 ///
1371 /// By default, performs semantic analysis to build the new decaration.
1372 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001373 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001374 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001375 SourceLocation StartLoc,
1376 SourceLocation IdLoc,
1377 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001378 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1379 StartLoc, IdLoc, Id);
1380 if (Var)
1381 getSema().CurContext->addDecl(Var);
1382 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001383 }
1384
1385 /// \brief Build a new C++ catch statement.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001389 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001390 VarDecl *ExceptionDecl,
1391 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001392 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1393 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001394 }
Mike Stump1eb44332009-09-09 15:08:12 +00001395
Douglas Gregor43959a92009-08-20 07:17:43 +00001396 /// \brief Build a new C++ try statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001400 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1401 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001402 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001403 }
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Richard Smithad762fc2011-04-14 22:09:26 +00001405 /// \brief Build a new C++0x range-based for statement.
1406 ///
1407 /// By default, performs semantic analysis to build the new statement.
1408 /// Subclasses may override this routine to provide different behavior.
1409 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1410 SourceLocation ColonLoc,
1411 Stmt *Range, Stmt *BeginEnd,
1412 Expr *Cond, Expr *Inc,
1413 Stmt *LoopVar,
1414 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001415 // If we've just learned that the range is actually an Objective-C
1416 // collection, treat this as an Objective-C fast enumeration loop.
1417 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1418 if (RangeStmt->isSingleDecl()) {
1419 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001420 if (RangeVar->isInvalidDecl())
1421 return StmtError();
1422
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001423 Expr *RangeExpr = RangeVar->getInit();
1424 if (!RangeExpr->isTypeDependent() &&
1425 RangeExpr->getType()->isObjCObjectPointerType())
1426 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1427 RParenLoc);
1428 }
1429 }
1430 }
1431
Richard Smithad762fc2011-04-14 22:09:26 +00001432 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001433 Cond, Inc, LoopVar, RParenLoc,
1434 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001435 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001436
1437 /// \brief Build a new C++0x range-based for statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001441 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001442 bool IsIfExists,
1443 NestedNameSpecifierLoc QualifierLoc,
1444 DeclarationNameInfo NameInfo,
1445 Stmt *Nested) {
1446 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1447 QualifierLoc, NameInfo, Nested);
1448 }
1449
Richard Smithad762fc2011-04-14 22:09:26 +00001450 /// \brief Attach body to a C++0x range-based for statement.
1451 ///
1452 /// By default, performs semantic analysis to finish the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
1454 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1455 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1456 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001457
John Wiegley28bbe4b2011-04-28 01:08:34 +00001458 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1459 SourceLocation TryLoc,
1460 Stmt *TryBlock,
1461 Stmt *Handler) {
1462 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1463 }
1464
1465 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1466 Expr *FilterExpr,
1467 Stmt *Block) {
1468 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1469 }
1470
1471 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1472 Stmt *Block) {
1473 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1474 }
1475
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 /// \brief Build a new expression that references a declaration.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001480 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001481 LookupResult &R,
1482 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001483 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1484 }
1485
1486
1487 /// \brief Build a new expression that references a declaration.
1488 ///
1489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001491 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001492 ValueDecl *VD,
1493 const DeclarationNameInfo &NameInfo,
1494 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001495 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001496 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001497
1498 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001499
1500 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
Mike Stump1eb44332009-09-09 15:08:12 +00001502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001509 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
1511
Douglas Gregora71d8192009-09-04 17:36:40 +00001512 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001517 SourceLocation OperatorLoc,
1518 bool isArrow,
1519 CXXScopeSpec &SS,
1520 TypeSourceInfo *ScopeType,
1521 SourceLocation CCLoc,
1522 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001523 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001524
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001530 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001531 Expr *SubExpr) {
1532 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001535 /// \brief Build a new builtin offsetof expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001539 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001540 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001541 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001542 unsigned NumComponents,
1543 SourceLocation RParenLoc) {
1544 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1545 NumComponents, RParenLoc);
1546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001547
1548 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001549 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001553 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1554 SourceLocation OpLoc,
1555 UnaryExprOrTypeTrait ExprKind,
1556 SourceRange R) {
1557 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 }
1559
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001560 /// \brief Build a new sizeof, alignof or vec step expression with an
1561 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001565 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1566 UnaryExprOrTypeTrait ExprKind,
1567 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001569 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001572
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001573 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 }
Mike Stump1eb44332009-09-09 15:08:12 +00001575
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001577 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001582 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1585 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 RBracketLoc);
1587 }
1588
1589 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001590 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001593 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001595 SourceLocation RParenLoc,
1596 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001597 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001598 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 }
1600
1601 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001602 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// By default, performs semantic analysis to build the new expression.
1604 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001605 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001606 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001607 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001608 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001609 const DeclarationNameInfo &MemberNameInfo,
1610 ValueDecl *Member,
1611 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001612 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001613 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001614 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1615 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001616 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001617 // We have a reference to an unnamed field. This is always the
1618 // base of an anonymous struct/union member access, i.e. the
1619 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001620 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001621 assert(Member->getType()->isRecordType() &&
1622 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Richard Smith9138b4e2011-10-26 19:06:56 +00001624 BaseResult =
1625 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001626 QualifierLoc.getNestedNameSpecifier(),
1627 FoundDecl, Member);
1628 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001629 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001630 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001631 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001632 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001633 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001634 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001635 cast<FieldDecl>(Member)->getType(),
1636 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001637 return getSema().Owned(ME);
1638 }
Mike Stump1eb44332009-09-09 15:08:12 +00001639
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001640 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001641 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001642
John Wiegley429bb272011-04-08 18:41:53 +00001643 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001644 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001645
John McCall6bb80172010-03-30 21:47:33 +00001646 // FIXME: this involves duplicating earlier analysis in a lot of
1647 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001648 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001649 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001650 R.resolveKind();
1651
John McCall9ae2f072010-08-23 23:25:46 +00001652 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001653 SS, TemplateKWLoc,
1654 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001655 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001659 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001663 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Expr *LHS, Expr *RHS) {
1665 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001669 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001673 SourceLocation QuestionLoc,
1674 Expr *LHS,
1675 SourceLocation ColonLoc,
1676 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001677 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1678 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001686 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001689 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001698 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001700 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001701 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001702 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001706 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001709 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation OpLoc,
1711 SourceLocation AccessorLoc,
1712 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001713
John McCall129e2df2009-11-30 22:42:35 +00001714 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001715 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001716 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001717 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001718 SS, SourceLocation(),
1719 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001720 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001721 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 }
Mike Stump1eb44332009-09-09 15:08:12 +00001723
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001725 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001728 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001729 MultiExprArg Inits,
1730 SourceLocation RBraceLoc,
1731 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001732 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001733 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001734 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001735 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001736
Douglas Gregore48319a2009-11-09 17:16:50 +00001737 // Patch in the result type we were given, which may have been computed
1738 // when the initial InitListExpr was built.
1739 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1740 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001741 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 }
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001745 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001748 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 MultiExprArg ArrayExprs,
1750 SourceLocation EqualOrColonLoc,
1751 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001752 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001759 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001763 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// By default, builds the implicit value initialization without performing
1765 /// any semantic analysis. Subclasses may override this routine to provide
1766 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1769 }
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001772 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001776 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001777 SourceLocation RParenLoc) {
1778 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001779 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001780 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 }
1782
1783 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001784 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001787 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001788 MultiExprArg SubExprs,
1789 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001790 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 }
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001794 ///
1795 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 /// rather than attempting to map the label statement itself.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001799 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001800 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001804 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001810 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 }
Mike Stump1eb44332009-09-09 15:08:12 +00001812
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 /// \brief Build a new __builtin_choose_expr expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RParenLoc) {
1820 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001821 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 RParenLoc);
1823 }
Mike Stump1eb44332009-09-09 15:08:12 +00001824
Peter Collingbournef111d932011-04-15 00:35:48 +00001825 /// \brief Build a new generic selection expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
1829 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1830 SourceLocation DefaultLoc,
1831 SourceLocation RParenLoc,
1832 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001833 ArrayRef<TypeSourceInfo *> Types,
1834 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001835 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001836 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001837 }
1838
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 /// \brief Build a new overloaded operator call expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// The semantic analysis provides the behavior of template instantiation,
1843 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001844 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 /// argument-dependent lookup, etc. Subclasses may override this routine to
1846 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001849 Expr *Callee,
1850 Expr *First,
1851 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001852
1853 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 /// reinterpret_cast.
1855 ///
1856 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001857 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001859 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 Stmt::StmtClass Class,
1861 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001862 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RAngleLoc,
1864 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001865 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RParenLoc) {
1867 switch (Class) {
1868 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001869 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001870 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001871 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872
1873 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001874 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001875 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001876 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001877
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001879 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001880 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001881 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001885 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001886 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001890 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 /// \brief Build a new C++ static_cast expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001898 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001900 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 SourceLocation RAngleLoc,
1902 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001903 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001905 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001906 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001907 SourceRange(LAngleLoc, RAngleLoc),
1908 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
1910
1911 /// \brief Build a new C++ dynamic_cast expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001915 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001917 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 SourceLocation RAngleLoc,
1919 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001920 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001922 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001923 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001924 SourceRange(LAngleLoc, RAngleLoc),
1925 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 }
1927
1928 /// \brief Build a new C++ reinterpret_cast expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001932 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 SourceLocation RAngleLoc,
1936 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001937 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001939 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001940 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001941 SourceRange(LAngleLoc, RAngleLoc),
1942 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ const_cast expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001949 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001951 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 SourceLocation RAngleLoc,
1953 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001954 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001956 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001957 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001958 SourceRange(LAngleLoc, RAngleLoc),
1959 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 }
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 /// \brief Build a new C++ functional-style cast expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001966 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1967 SourceLocation LParenLoc,
1968 Expr *Sub,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001971 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 RParenLoc);
1973 }
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 /// \brief Build a new C++ typeid(type) expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001979 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001980 SourceLocation TypeidLoc,
1981 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001983 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001984 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 }
Mike Stump1eb44332009-09-09 15:08:12 +00001986
Francois Pichet01b7c302010-09-08 12:20:18 +00001987
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 /// \brief Build a new C++ typeid(expr) expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001992 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001993 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001994 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001996 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001997 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001998 }
1999
Francois Pichet01b7c302010-09-08 12:20:18 +00002000 /// \brief Build a new C++ __uuidof(type) expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2005 SourceLocation TypeidLoc,
2006 TypeSourceInfo *Operand,
2007 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002008 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002009 RParenLoc);
2010 }
2011
2012 /// \brief Build a new C++ __uuidof(expr) expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2017 SourceLocation TypeidLoc,
2018 Expr *Operand,
2019 SourceLocation RParenLoc) {
2020 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2021 RParenLoc);
2022 }
2023
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 /// \brief Build a new C++ "this" expression.
2025 ///
2026 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002027 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002029 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002030 QualType ThisType,
2031 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002032 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002034 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2035 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 }
2037
2038 /// \brief Build a new C++ throw expression.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002042 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2043 bool IsThrownVariableInScope) {
2044 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 }
2046
2047 /// \brief Build a new C++ default-argument expression.
2048 ///
2049 /// By default, builds a new default-argument expression, which does not
2050 /// require any semantic analysis. Subclasses may override this routine to
2051 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002052 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002053 ParmVarDecl *Param) {
2054 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2055 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 }
2057
Richard Smithc3bf52c2013-04-20 22:23:05 +00002058 /// \brief Build a new C++11 default-initialization expression.
2059 ///
2060 /// By default, builds a new default field initialization expression, which
2061 /// does not require any semantic analysis. Subclasses may override this
2062 /// routine to provide different behavior.
2063 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2064 FieldDecl *Field) {
2065 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2066 Field));
2067 }
2068
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 /// \brief Build a new C++ zero-initialization expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002073 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2074 SourceLocation LParenLoc,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002077 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 }
Mike Stump1eb44332009-09-09 15:08:12 +00002079
Douglas Gregorb98b1992009-08-11 05:31:07 +00002080 /// \brief Build a new C++ "new" expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002084 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002085 bool UseGlobal,
2086 SourceLocation PlacementLParen,
2087 MultiExprArg PlacementArgs,
2088 SourceLocation PlacementRParen,
2089 SourceRange TypeIdParens,
2090 QualType AllocatedType,
2091 TypeSourceInfo *AllocatedTypeInfo,
2092 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002093 SourceRange DirectInitRange,
2094 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002095 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002097 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002099 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002100 AllocatedType,
2101 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002102 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002103 DirectInitRange,
2104 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
Mike Stump1eb44332009-09-09 15:08:12 +00002106
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 /// \brief Build a new C++ "delete" expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 bool IsGlobalDelete,
2113 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002114 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002116 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002117 }
Mike Stump1eb44332009-09-09 15:08:12 +00002118
Douglas Gregorb98b1992009-08-11 05:31:07 +00002119 /// \brief Build a new unary type trait expression.
2120 ///
2121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002123 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002124 SourceLocation StartLoc,
2125 TypeSourceInfo *T,
2126 SourceLocation RParenLoc) {
2127 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 }
2129
Francois Pichet6ad6f282010-12-07 00:08:36 +00002130 /// \brief Build a new binary type trait expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
2134 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2135 SourceLocation StartLoc,
2136 TypeSourceInfo *LhsT,
2137 TypeSourceInfo *RhsT,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2140 }
2141
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002142 /// \brief Build a new type trait expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
2146 ExprResult RebuildTypeTrait(TypeTrait Trait,
2147 SourceLocation StartLoc,
2148 ArrayRef<TypeSourceInfo *> Args,
2149 SourceLocation RParenLoc) {
2150 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002152
John Wiegley21ff2e52011-04-28 00:16:57 +00002153 /// \brief Build a new array type trait expression.
2154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
2157 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2158 SourceLocation StartLoc,
2159 TypeSourceInfo *TSInfo,
2160 Expr *DimExpr,
2161 SourceLocation RParenLoc) {
2162 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2163 }
2164
John Wiegley55262202011-04-25 06:54:41 +00002165 /// \brief Build a new expression trait expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
2169 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2170 SourceLocation StartLoc,
2171 Expr *Queried,
2172 SourceLocation RParenLoc) {
2173 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2174 }
2175
Mike Stump1eb44332009-09-09 15:08:12 +00002176 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 /// expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002181 ExprResult RebuildDependentScopeDeclRefExpr(
2182 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002183 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002184 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002185 const TemplateArgumentListInfo *TemplateArgs,
2186 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002187 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002188 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002189
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002190 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002192 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002193
Richard Smithefeeccf2012-10-21 03:28:35 +00002194 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2195 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 }
2197
2198 /// \brief Build a new template-id expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002202 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002203 SourceLocation TemplateKWLoc,
2204 LookupResult &R,
2205 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002206 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002207 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2208 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002209 }
2210
2211 /// \brief Build a new object-construction expression.
2212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002215 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002216 SourceLocation Loc,
2217 CXXConstructorDecl *Constructor,
2218 bool IsElidable,
2219 MultiExprArg Args,
2220 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002221 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002222 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002223 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002224 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002225 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002226 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002227 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002228 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002229
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002230 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002231 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002232 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002233 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002234 RequiresZeroInit, ConstructKind,
2235 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002236 }
2237
2238 /// \brief Build a new object-construction expression.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002242 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2243 SourceLocation LParenLoc,
2244 MultiExprArg Args,
2245 SourceLocation RParenLoc) {
2246 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002247 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002248 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002249 RParenLoc);
2250 }
2251
2252 /// \brief Build a new object-construction expression.
2253 ///
2254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002256 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2257 SourceLocation LParenLoc,
2258 MultiExprArg Args,
2259 SourceLocation RParenLoc) {
2260 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002261 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002262 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263 RParenLoc);
2264 }
Mike Stump1eb44332009-09-09 15:08:12 +00002265
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 /// \brief Build a new member reference expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002271 QualType BaseType,
2272 bool IsArrow,
2273 SourceLocation OperatorLoc,
2274 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002275 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002276 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002277 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002278 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002280 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002281
John McCall9ae2f072010-08-23 23:25:46 +00002282 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002283 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002284 SS, TemplateKWLoc,
2285 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002286 MemberNameInfo,
2287 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002288 }
2289
John McCall129e2df2009-11-30 22:42:35 +00002290 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002291 ///
2292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002294 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2295 SourceLocation OperatorLoc,
2296 bool IsArrow,
2297 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002298 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002299 NamedDecl *FirstQualifierInScope,
2300 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002301 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002302 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002303 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002304
John McCall9ae2f072010-08-23 23:25:46 +00002305 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002306 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002307 SS, TemplateKWLoc,
2308 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002309 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002310 }
Mike Stump1eb44332009-09-09 15:08:12 +00002311
Sebastian Redl2e156222010-09-10 20:55:43 +00002312 /// \brief Build a new noexcept expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
2316 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2317 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2318 }
2319
Douglas Gregoree8aff02011-01-04 17:33:58 +00002320 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002321 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2322 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002323 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002324 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002325 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002326 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2327 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002328 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329
2330 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2331 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002332 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002333 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002334
Patrick Beardeb382ec2012-04-19 00:25:12 +00002335 /// \brief Build a new Objective-C boxed expression.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
2339 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2340 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002343 /// \brief Build a new Objective-C array literal.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2348 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002349 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002350 MultiExprArg(Elements, NumElements));
2351 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002352
2353 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002354 Expr *Base, Expr *Key,
2355 ObjCMethodDecl *getterMethod,
2356 ObjCMethodDecl *setterMethod) {
2357 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2358 getterMethod, setterMethod);
2359 }
2360
2361 /// \brief Build a new Objective-C dictionary literal.
2362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
2365 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2366 ObjCDictionaryElement *Elements,
2367 unsigned NumElements) {
2368 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
James Dennett699c9042012-06-15 07:13:21 +00002371 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002375 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002376 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002377 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002378 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002379 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002380 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002381
Douglas Gregor92e986e2010-04-22 16:44:27 +00002382 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002384 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002385 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002386 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002387 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002388 MultiExprArg Args,
2389 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2391 ReceiverTypeInfo->getType(),
2392 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002393 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002394 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002395 }
2396
2397 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002398 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002399 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002400 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002402 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 MultiExprArg Args,
2404 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002405 return SemaRef.BuildInstanceMessage(Receiver,
2406 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002408 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002409 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002410 }
2411
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /// \brief Build a new Objective-C ivar reference expression.
2413 ///
2414 /// By default, performs semantic analysis to build the new expression.
2415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002417 SourceLocation IvarLoc,
2418 bool IsArrow, bool IsFreeIvar) {
2419 // FIXME: We lose track of the IsFreeIvar bit.
2420 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002421 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002422 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2423 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002424 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002426 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002427 false);
John Wiegley429bb272011-04-08 18:41:53 +00002428 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002429 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002430
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002431 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002432 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002433
John Wiegley429bb272011-04-08 18:41:53 +00002434 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002435 /*FIXME:*/IvarLoc, IsArrow,
2436 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002437 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002439 /*TemplateArgs=*/0);
2440 }
Douglas Gregore3303542010-04-26 20:47:02 +00002441
2442 /// \brief Build a new Objective-C property reference expression.
2443 ///
2444 /// By default, performs semantic analysis to build the new expression.
2445 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002447 ObjCPropertyDecl *Property,
2448 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002449 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002450 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002451 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2452 Sema::LookupMemberName);
2453 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002454 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002455 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002456 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002457 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002458 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002459
Douglas Gregore3303542010-04-26 20:47:02 +00002460 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002461 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002462
John Wiegley429bb272011-04-08 18:41:53 +00002463 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002465 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002466 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002468 /*TemplateArgs=*/0);
2469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
John McCall12f78a62010-12-02 01:19:52 +00002471 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002472 ///
2473 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002474 /// Subclasses may override this routine to provide different behavior.
2475 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2476 ObjCMethodDecl *Getter,
2477 ObjCMethodDecl *Setter,
2478 SourceLocation PropertyLoc) {
2479 // Since these expressions can only be value-dependent, we do not
2480 // need to perform semantic analysis again.
2481 return Owned(
2482 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2483 VK_LValue, OK_ObjCProperty,
2484 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002485 }
2486
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002487 /// \brief Build a new Objective-C "isa" expression.
2488 ///
2489 /// By default, performs semantic analysis to build the new expression.
2490 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002491 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002492 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002493 bool IsArrow) {
2494 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002495 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002496 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2497 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002498 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002499 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002500 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002501 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002502 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002505 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002506
John Wiegley429bb272011-04-08 18:41:53 +00002507 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002508 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002509 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002510 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002512 /*TemplateArgs=*/0);
2513 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
Douglas Gregorb98b1992009-08-11 05:31:07 +00002515 /// \brief Build a new shuffle vector expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002519 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002520 MultiExprArg SubExprs,
2521 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002522 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002523 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002524 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2525 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2526 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002527 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002528
Douglas Gregorb98b1992009-08-11 05:31:07 +00002529 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002530 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002531 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2532 SemaRef.Context.BuiltinFnTy,
2533 VK_RValue, BuiltinLoc);
2534 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2535 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2536 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002537
2538 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002539 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002540 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002541 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002542 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002543 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002544
Douglas Gregorb98b1992009-08-11 05:31:07 +00002545 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002546 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002547 }
John McCall43fed0d2010-11-12 08:19:04 +00002548
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002549 /// \brief Build a new template argument pack expansion.
2550 ///
2551 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002552 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002553 /// different behavior.
2554 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002555 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002556 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002557 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002558 case TemplateArgument::Expression: {
2559 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002560 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2561 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002562 if (Result.isInvalid())
2563 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002564
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002565 return TemplateArgumentLoc(Result.get(), Result.get());
2566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002567
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002568 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002569 return TemplateArgumentLoc(TemplateArgument(
2570 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002571 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002572 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002573 Pattern.getTemplateNameLoc(),
2574 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002575
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 case TemplateArgument::Null:
2577 case TemplateArgument::Integral:
2578 case TemplateArgument::Declaration:
2579 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002580 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002581 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002582 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002585 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002586 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002587 EllipsisLoc,
2588 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002589 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2590 Expansion);
2591 break;
2592 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002593
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002594 return TemplateArgumentLoc();
2595 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002596
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002597 /// \brief Build a new expression pack expansion.
2598 ///
2599 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002600 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002601 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002602 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002603 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002604 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002606
2607 /// \brief Build a new atomic operation expression.
2608 ///
2609 /// By default, performs semantic analysis to build the new expression.
2610 /// Subclasses may override this routine to provide different behavior.
2611 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2612 MultiExprArg SubExprs,
2613 QualType RetTy,
2614 AtomicExpr::AtomicOp Op,
2615 SourceLocation RParenLoc) {
2616 // Just create the expression; there is not any interesting semantic
2617 // analysis here because we can't actually build an AtomicExpr until
2618 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002619 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002620 RParenLoc);
2621 }
2622
John McCall43fed0d2010-11-12 08:19:04 +00002623private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002624 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2625 QualType ObjectType,
2626 NamedDecl *FirstQualifierInScope,
2627 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002628
2629 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2630 QualType ObjectType,
2631 NamedDecl *FirstQualifierInScope,
2632 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002633};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002634
Douglas Gregor43959a92009-08-20 07:17:43 +00002635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002636StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002637 if (!S)
2638 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002639
Douglas Gregor43959a92009-08-20 07:17:43 +00002640 switch (S->getStmtClass()) {
2641 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002642
Douglas Gregor43959a92009-08-20 07:17:43 +00002643 // Transform individual statement nodes
2644#define STMT(Node, Parent) \
2645 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002646#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002647#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002648#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002649
Douglas Gregor43959a92009-08-20 07:17:43 +00002650 // Transform expressions by calling TransformExpr.
2651#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002652#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002653#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002654#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002655 {
John McCall60d7b3a2010-08-24 06:29:42 +00002656 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002657 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002658 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002659
Richard Smith41956372013-01-14 22:39:08 +00002660 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002661 }
Mike Stump1eb44332009-09-09 15:08:12 +00002662 }
2663
John McCall3fa5cae2010-10-26 07:05:15 +00002664 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002665}
Mike Stump1eb44332009-09-09 15:08:12 +00002666
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002667template<typename Derived>
2668OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2669 if (!S)
2670 return S;
2671
2672 switch (S->getClauseKind()) {
2673 default: break;
2674 // Transform individual clause nodes
2675#define OPENMP_CLAUSE(Name, Class) \
2676 case OMPC_ ## Name : \
2677 return getDerived().Transform ## Class(cast<Class>(S));
2678#include "clang/Basic/OpenMPKinds.def"
2679 }
2680
2681 return S;
2682}
2683
Mike Stump1eb44332009-09-09 15:08:12 +00002684
Douglas Gregor670444e2009-08-04 22:27:00 +00002685template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002686ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002687 if (!E)
2688 return SemaRef.Owned(E);
2689
2690 switch (E->getStmtClass()) {
2691 case Stmt::NoStmtClass: break;
2692#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002693#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002694#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002695 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002696#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002697 }
2698
John McCall3fa5cae2010-10-26 07:05:15 +00002699 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002700}
2701
2702template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002703ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2704 bool CXXDirectInit) {
2705 // Initializers are instantiated like expressions, except that various outer
2706 // layers are stripped.
2707 if (!Init)
2708 return SemaRef.Owned(Init);
2709
2710 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2711 Init = ExprTemp->getSubExpr();
2712
Richard Smith858c2c32013-05-30 22:40:16 +00002713 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2714 Init = MTE->GetTemporaryExpr();
2715
Richard Smithc83c2302012-12-19 01:39:02 +00002716 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2717 Init = Binder->getSubExpr();
2718
2719 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2720 Init = ICE->getSubExprAsWritten();
2721
Richard Smith7c3e6152013-06-12 22:31:48 +00002722 if (CXXStdInitializerListExpr *ILE =
2723 dyn_cast<CXXStdInitializerListExpr>(Init))
2724 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2725
Richard Smith5cf15892012-12-21 08:13:35 +00002726 // If this is not a direct-initializer, we only need to reconstruct
2727 // InitListExprs. Other forms of copy-initialization will be a no-op if
2728 // the initializer is already the right type.
2729 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2730 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2731 return getDerived().TransformExpr(Init);
2732
2733 // Revert value-initialization back to empty parens.
2734 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2735 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002736 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002737 Parens.getEnd());
2738 }
2739
2740 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2741 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002742 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002743 SourceLocation());
2744
2745 // Revert initialization by constructor back to a parenthesized or braced list
2746 // of expressions. Any other form of initializer can just be reused directly.
2747 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002748 return getDerived().TransformExpr(Init);
2749
2750 SmallVector<Expr*, 8> NewArgs;
2751 bool ArgChanged = false;
2752 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2753 /*IsCall*/true, NewArgs, &ArgChanged))
2754 return ExprError();
2755
2756 // If this was list initialization, revert to list form.
2757 if (Construct->isListInitialization())
2758 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2759 Construct->getLocEnd(),
2760 Construct->getType());
2761
Richard Smithc83c2302012-12-19 01:39:02 +00002762 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002763 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002764 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2765 Parens.getEnd());
2766}
2767
2768template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2770 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002771 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002772 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002773 bool *ArgChanged) {
2774 for (unsigned I = 0; I != NumInputs; ++I) {
2775 // If requested, drop call arguments that need to be dropped.
2776 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2777 if (ArgChanged)
2778 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregoraa165f82011-01-03 19:04:46 +00002780 break;
2781 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002782
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002783 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2784 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785
Chris Lattner686775d2011-07-20 06:58:45 +00002786 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002787 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2788 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002789
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002790 // Determine whether the set of unexpanded parameter packs can and should
2791 // be expanded.
2792 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002793 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002794 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2795 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002796 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2797 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002798 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002799 Expand, RetainExpansion,
2800 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002801 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002803 if (!Expand) {
2804 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002806 // expansion.
2807 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2808 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2809 if (OutPattern.isInvalid())
2810 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002811
2812 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002813 Expansion->getEllipsisLoc(),
2814 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002815 if (Out.isInvalid())
2816 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002817
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002818 if (ArgChanged)
2819 *ArgChanged = true;
2820 Outputs.push_back(Out.get());
2821 continue;
2822 }
John McCallc8fc90a2011-07-06 07:30:07 +00002823
2824 // Record right away that the argument was changed. This needs
2825 // to happen even if the array expands to nothing.
2826 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002828 // The transform has determined that we should perform an elementwise
2829 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002830 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002831 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2832 ExprResult Out = getDerived().TransformExpr(Pattern);
2833 if (Out.isInvalid())
2834 return true;
2835
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002836 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002837 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2838 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002839 if (Out.isInvalid())
2840 return true;
2841 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002843 Outputs.push_back(Out.get());
2844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002846 continue;
2847 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
Richard Smithc83c2302012-12-19 01:39:02 +00002849 ExprResult Result =
2850 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2851 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002852 if (Result.isInvalid())
2853 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002854
Douglas Gregoraa165f82011-01-03 19:04:46 +00002855 if (Result.get() != Inputs[I] && ArgChanged)
2856 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857
2858 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002860
Douglas Gregoraa165f82011-01-03 19:04:46 +00002861 return false;
2862}
2863
2864template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002865NestedNameSpecifierLoc
2866TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2867 NestedNameSpecifierLoc NNS,
2868 QualType ObjectType,
2869 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002870 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002872 Qualifier = Qualifier.getPrefix())
2873 Qualifiers.push_back(Qualifier);
2874
2875 CXXScopeSpec SS;
2876 while (!Qualifiers.empty()) {
2877 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2878 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002880 switch (QNNS->getKind()) {
2881 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002882 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002883 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002885 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002886 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002887 FirstQualifierInScope, false))
2888 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002889
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002890 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002892 case NestedNameSpecifier::Namespace: {
2893 NamespaceDecl *NS
2894 = cast_or_null<NamespaceDecl>(
2895 getDerived().TransformDecl(
2896 Q.getLocalBeginLoc(),
2897 QNNS->getAsNamespace()));
2898 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2899 break;
2900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002901
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002902 case NestedNameSpecifier::NamespaceAlias: {
2903 NamespaceAliasDecl *Alias
2904 = cast_or_null<NamespaceAliasDecl>(
2905 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2906 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 Q.getLocalEndLoc());
2909 break;
2910 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002912 case NestedNameSpecifier::Global:
2913 // There is no meaningful transformation that one could perform on the
2914 // global scope.
2915 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2916 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 case NestedNameSpecifier::TypeSpecWithTemplate:
2919 case NestedNameSpecifier::TypeSpec: {
2920 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2921 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002922
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002923 if (!TL)
2924 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002925
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002926 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002927 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002928 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002929 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002930 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002931 if (TL.getType()->isEnumeralType())
2932 SemaRef.Diag(TL.getBeginLoc(),
2933 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002934 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2935 Q.getLocalEndLoc());
2936 break;
2937 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002938 // If the nested-name-specifier is an invalid type def, don't emit an
2939 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002940 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2941 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002942 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002943 << TL.getType() << SS.getRange();
2944 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002945 return NestedNameSpecifierLoc();
2946 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002949 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002950 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002951 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002952 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002953
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002954 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002956 !getDerived().AlwaysRebuild())
2957 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958
2959 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002960 // nested-name-specifier, do so.
2961 if (SS.location_size() == NNS.getDataLength() &&
2962 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2963 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2964
2965 // Allocate new nested-name-specifier location information.
2966 return SS.getWithLocInContext(SemaRef.Context);
2967}
2968
2969template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002970DeclarationNameInfo
2971TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002972::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002973 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002974 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002975 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002976
2977 switch (Name.getNameKind()) {
2978 case DeclarationName::Identifier:
2979 case DeclarationName::ObjCZeroArgSelector:
2980 case DeclarationName::ObjCOneArgSelector:
2981 case DeclarationName::ObjCMultiArgSelector:
2982 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002983 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002984 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002985 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002986
Douglas Gregor81499bb2009-09-03 22:13:48 +00002987 case DeclarationName::CXXConstructorName:
2988 case DeclarationName::CXXDestructorName:
2989 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002990 TypeSourceInfo *NewTInfo;
2991 CanQualType NewCanTy;
2992 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002993 NewTInfo = getDerived().TransformType(OldTInfo);
2994 if (!NewTInfo)
2995 return DeclarationNameInfo();
2996 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002997 }
2998 else {
2999 NewTInfo = 0;
3000 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003001 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003002 if (NewT.isNull())
3003 return DeclarationNameInfo();
3004 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3005 }
Mike Stump1eb44332009-09-09 15:08:12 +00003006
Abramo Bagnara25777432010-08-11 22:01:17 +00003007 DeclarationName NewName
3008 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3009 NewCanTy);
3010 DeclarationNameInfo NewNameInfo(NameInfo);
3011 NewNameInfo.setName(NewName);
3012 NewNameInfo.setNamedTypeInfo(NewTInfo);
3013 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003014 }
Mike Stump1eb44332009-09-09 15:08:12 +00003015 }
3016
David Blaikieb219cfc2011-09-23 05:06:16 +00003017 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003018}
3019
3020template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003021TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003022TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3023 TemplateName Name,
3024 SourceLocation NameLoc,
3025 QualType ObjectType,
3026 NamedDecl *FirstQualifierInScope) {
3027 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3028 TemplateDecl *Template = QTN->getTemplateDecl();
3029 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003030
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003031 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003033 Template));
3034 if (!TransTemplate)
3035 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003036
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003037 if (!getDerived().AlwaysRebuild() &&
3038 SS.getScopeRep() == QTN->getQualifier() &&
3039 TransTemplate == Template)
3040 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003042 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3043 TransTemplate);
3044 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003045
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003046 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3047 if (SS.getScopeRep()) {
3048 // These apply to the scope specifier, not the template.
3049 ObjectType = QualType();
3050 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003051 }
3052
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003053 if (!getDerived().AlwaysRebuild() &&
3054 SS.getScopeRep() == DTN->getQualifier() &&
3055 ObjectType.isNull())
3056 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 if (DTN->isIdentifier()) {
3059 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003060 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003061 NameLoc,
3062 ObjectType,
3063 FirstQualifierInScope);
3064 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003065
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003066 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3067 ObjectType);
3068 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003069
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003070 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3071 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003073 Template));
3074 if (!TransTemplate)
3075 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003077 if (!getDerived().AlwaysRebuild() &&
3078 TransTemplate == Template)
3079 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003080
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003081 return TemplateName(TransTemplate);
3082 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003083
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003084 if (SubstTemplateTemplateParmPackStorage *SubstPack
3085 = Name.getAsSubstTemplateTemplateParmPack()) {
3086 TemplateTemplateParmDecl *TransParam
3087 = cast_or_null<TemplateTemplateParmDecl>(
3088 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3089 if (!TransParam)
3090 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003091
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003092 if (!getDerived().AlwaysRebuild() &&
3093 TransParam == SubstPack->getParameterPack())
3094 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003095
3096 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003097 SubstPack->getArgumentPack());
3098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003100 // These should be getting filtered out before they reach the AST.
3101 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003102}
3103
3104template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003105void TreeTransform<Derived>::InventTemplateArgumentLoc(
3106 const TemplateArgument &Arg,
3107 TemplateArgumentLoc &Output) {
3108 SourceLocation Loc = getDerived().getBaseLocation();
3109 switch (Arg.getKind()) {
3110 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003111 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003112 break;
3113
3114 case TemplateArgument::Type:
3115 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003116 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
John McCall833ca992009-10-29 08:12:44 +00003118 break;
3119
Douglas Gregor788cd062009-11-11 01:00:40 +00003120 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003121 case TemplateArgument::TemplateExpansion: {
3122 NestedNameSpecifierLocBuilder Builder;
3123 TemplateName Template = Arg.getAsTemplate();
3124 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3125 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3126 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3127 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003128
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003129 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003131 Builder.getWithLocInContext(SemaRef.Context),
3132 Loc);
3133 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003134 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003135 Builder.getWithLocInContext(SemaRef.Context),
3136 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor788cd062009-11-11 01:00:40 +00003138 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003139 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003140
John McCall833ca992009-10-29 08:12:44 +00003141 case TemplateArgument::Expression:
3142 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3143 break;
3144
3145 case TemplateArgument::Declaration:
3146 case TemplateArgument::Integral:
3147 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003148 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003149 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003150 break;
3151 }
3152}
3153
3154template<typename Derived>
3155bool TreeTransform<Derived>::TransformTemplateArgument(
3156 const TemplateArgumentLoc &Input,
3157 TemplateArgumentLoc &Output) {
3158 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003159 switch (Arg.getKind()) {
3160 case TemplateArgument::Null:
3161 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003162 case TemplateArgument::Pack:
3163 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003164 case TemplateArgument::NullPtr:
3165 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003166
Douglas Gregor670444e2009-08-04 22:27:00 +00003167 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003168 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003169 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003170 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003171
3172 DI = getDerived().TransformType(DI);
3173 if (!DI) return true;
3174
3175 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3176 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003177 }
Mike Stump1eb44332009-09-09 15:08:12 +00003178
Douglas Gregor788cd062009-11-11 01:00:40 +00003179 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003180 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3181 if (QualifierLoc) {
3182 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3183 if (!QualifierLoc)
3184 return true;
3185 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor1d752d72011-03-02 18:46:51 +00003187 CXXScopeSpec SS;
3188 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003189 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003190 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3191 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003192 if (Template.isNull())
3193 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003195 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003196 Input.getTemplateNameLoc());
3197 return false;
3198 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003199
3200 case TemplateArgument::TemplateExpansion:
3201 llvm_unreachable("Caller should expand pack expansions");
3202
Douglas Gregor670444e2009-08-04 22:27:00 +00003203 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003204 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003205 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003206 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003207
John McCall833ca992009-10-29 08:12:44 +00003208 Expr *InputExpr = Input.getSourceExpression();
3209 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3210
Chris Lattner223de242011-04-25 20:37:58 +00003211 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003212 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003213 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003214 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003215 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003216 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003217 }
Mike Stump1eb44332009-09-09 15:08:12 +00003218
Douglas Gregor670444e2009-08-04 22:27:00 +00003219 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003220 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003221}
3222
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003223/// \brief Iterator adaptor that invents template argument location information
3224/// for each of the template arguments in its underlying iterator.
3225template<typename Derived, typename InputIterator>
3226class TemplateArgumentLocInventIterator {
3227 TreeTransform<Derived> &Self;
3228 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003230public:
3231 typedef TemplateArgumentLoc value_type;
3232 typedef TemplateArgumentLoc reference;
3233 typedef typename std::iterator_traits<InputIterator>::difference_type
3234 difference_type;
3235 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003237 class pointer {
3238 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003240 public:
3241 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003243 const TemplateArgumentLoc *operator->() const { return &Arg; }
3244 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003246 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003248 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3249 InputIterator Iter)
3250 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003252 TemplateArgumentLocInventIterator &operator++() {
3253 ++Iter;
3254 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003257 TemplateArgumentLocInventIterator operator++(int) {
3258 TemplateArgumentLocInventIterator Old(*this);
3259 ++(*this);
3260 return Old;
3261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003263 reference operator*() const {
3264 TemplateArgumentLoc Result;
3265 Self.InventTemplateArgumentLoc(*Iter, Result);
3266 return Result;
3267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003269 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003270
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003271 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3272 const TemplateArgumentLocInventIterator &Y) {
3273 return X.Iter == Y.Iter;
3274 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003275
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003276 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3277 const TemplateArgumentLocInventIterator &Y) {
3278 return X.Iter != Y.Iter;
3279 }
3280};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003282template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003283template<typename InputIterator>
3284bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3285 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003286 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003287 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003288 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003289 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003291 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3292 // Unpack argument packs, which we translate them into separate
3293 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003294 // FIXME: We could do much better if we could guarantee that the
3295 // TemplateArgumentLocInfo for the pack expansion would be usable for
3296 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003298 TemplateArgument::pack_iterator>
3299 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003300 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003301 In.getArgument().pack_begin()),
3302 PackLocIterator(*this,
3303 In.getArgument().pack_end()),
3304 Outputs))
3305 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 continue;
3308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003310 if (In.getArgument().isPackExpansion()) {
3311 // We have a pack expansion, for which we will be substituting into
3312 // the pattern.
3313 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003314 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003315 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003316 = getSema().getTemplateArgumentPackExpansionPattern(
3317 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003318
Chris Lattner686775d2011-07-20 06:58:45 +00003319 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003320 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3321 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003323 // Determine whether the set of unexpanded parameter packs can and should
3324 // be expanded.
3325 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003326 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003327 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003328 if (getDerived().TryExpandParameterPacks(Ellipsis,
3329 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003330 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003332 RetainExpansion,
3333 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003334 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003335
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 if (!Expand) {
3337 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003338 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003339 // expansion.
3340 TemplateArgumentLoc OutPattern;
3341 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3342 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3343 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344
Douglas Gregorcded4f62011-01-14 17:04:44 +00003345 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3346 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003347 if (Out.getArgument().isNull())
3348 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003350 Outputs.addArgument(Out);
3351 continue;
3352 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003353
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003354 // The transform has determined that we should perform an elementwise
3355 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003356 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3358
3359 if (getDerived().TransformTemplateArgument(Pattern, Out))
3360 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003362 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003363 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3364 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003365 if (Out.getArgument().isNull())
3366 return true;
3367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003368
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003369 Outputs.addArgument(Out);
3370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003372 // If we're supposed to retain a pack expansion, do so by temporarily
3373 // forgetting the partially-substituted parameter pack.
3374 if (RetainExpansion) {
3375 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003376
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003377 if (getDerived().TransformTemplateArgument(Pattern, Out))
3378 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003379
Douglas Gregorcded4f62011-01-14 17:04:44 +00003380 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3381 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003382 if (Out.getArgument().isNull())
3383 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003385 Outputs.addArgument(Out);
3386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003388 continue;
3389 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003390
3391 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003392 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003393 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003394
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003395 Outputs.addArgument(Out);
3396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003398 return false;
3399
3400}
3401
Douglas Gregor577f75a2009-08-04 16:50:30 +00003402//===----------------------------------------------------------------------===//
3403// Type transformation
3404//===----------------------------------------------------------------------===//
3405
3406template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003407QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003408 if (getDerived().AlreadyTransformed(T))
3409 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003410
John McCalla2becad2009-10-21 00:40:46 +00003411 // Temporary workaround. All of these transformations should
3412 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003413 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3414 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
John McCall43fed0d2010-11-12 08:19:04 +00003416 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003417
John McCalla2becad2009-10-21 00:40:46 +00003418 if (!NewDI)
3419 return QualType();
3420
3421 return NewDI->getType();
3422}
3423
3424template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003425TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003426 // Refine the base location to the type's location.
3427 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3428 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003429 if (getDerived().AlreadyTransformed(DI->getType()))
3430 return DI;
3431
3432 TypeLocBuilder TLB;
3433
3434 TypeLoc TL = DI->getTypeLoc();
3435 TLB.reserve(TL.getFullDataSize());
3436
John McCall43fed0d2010-11-12 08:19:04 +00003437 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003438 if (Result.isNull())
3439 return 0;
3440
John McCalla93c9342009-12-07 02:54:59 +00003441 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003442}
3443
3444template<typename Derived>
3445QualType
John McCall43fed0d2010-11-12 08:19:04 +00003446TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003447 switch (T.getTypeLocClass()) {
3448#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003449#define TYPELOC(CLASS, PARENT) \
3450 case TypeLoc::CLASS: \
3451 return getDerived().Transform##CLASS##Type(TLB, \
3452 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003453#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003454 }
Mike Stump1eb44332009-09-09 15:08:12 +00003455
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003456 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003457}
3458
3459/// FIXME: By default, this routine adds type qualifiers only to types
3460/// that can have qualifiers, and silently suppresses those qualifiers
3461/// that are not permitted (e.g., qualifiers on reference or function
3462/// types). This is the right thing for template instantiation, but
3463/// probably not for other clients.
3464template<typename Derived>
3465QualType
3466TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003467 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003468 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003469
John McCall43fed0d2010-11-12 08:19:04 +00003470 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003471 if (Result.isNull())
3472 return QualType();
3473
3474 // Silently suppress qualifiers if the result type can't be qualified.
3475 // FIXME: this is the right thing for template instantiation, but
3476 // probably not for other clients.
3477 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003478 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003479
John McCallf85e1932011-06-15 23:02:42 +00003480 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003481 // resulting type.
3482 if (Quals.hasObjCLifetime()) {
3483 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3484 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003485 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003486 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003487 // A lifetime qualifier applied to a substituted template parameter
3488 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003489 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003491 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3492 QualType Replacement = SubstTypeParam->getReplacementType();
3493 Qualifiers Qs = Replacement.getQualifiers();
3494 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003496 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3497 Qs);
3498 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003500 Replacement);
3501 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003502 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3503 // 'auto' types behave the same way as template parameters.
3504 QualType Deduced = AutoTy->getDeducedType();
3505 Qualifiers Qs = Deduced.getQualifiers();
3506 Qs.removeObjCLifetime();
3507 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3508 Qs);
Manuel Klimek152b4e42013-08-22 12:12:24 +00003509 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003510 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003511 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003512 // Otherwise, complain about the addition of a qualifier to an
3513 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003514 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003515 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003516 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003517
Douglas Gregore559ca12011-06-17 22:11:49 +00003518 Quals.removeObjCLifetime();
3519 }
3520 }
3521 }
John McCall28654742010-06-05 06:41:15 +00003522 if (!Quals.empty()) {
3523 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003524 // BuildQualifiedType might not add qualifiers if they are invalid.
3525 if (Result.hasLocalQualifiers())
3526 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003527 // No location information to preserve.
3528 }
John McCalla2becad2009-10-21 00:40:46 +00003529
3530 return Result;
3531}
3532
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003533template<typename Derived>
3534TypeLoc
3535TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3536 QualType ObjectType,
3537 NamedDecl *UnqualLookup,
3538 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003539 QualType T = TL.getType();
3540 if (getDerived().AlreadyTransformed(T))
3541 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003542
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003543 TypeLocBuilder TLB;
3544 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003545
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003546 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003547 TemplateSpecializationTypeLoc SpecTL =
3548 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003549
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003550 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003551 getDerived().TransformTemplateName(SS,
3552 SpecTL.getTypePtr()->getTemplateName(),
3553 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003554 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003556 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557
3558 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003559 Template);
3560 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003561 DependentTemplateSpecializationTypeLoc SpecTL =
3562 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003563
Douglas Gregora88f09f2011-02-28 17:23:35 +00003564 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003565 = getDerived().RebuildTemplateName(SS,
3566 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003567 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003568 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003569 if (Template.isNull())
3570 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
3572 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003573 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003574 Template,
3575 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 } else {
3577 // Nothing special needs to be done for these.
3578 Result = getDerived().TransformType(TLB, TL);
3579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003580
3581 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003582 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003583
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003584 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3585}
3586
Douglas Gregorb71d8212011-03-02 18:32:08 +00003587template<typename Derived>
3588TypeSourceInfo *
3589TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3590 QualType ObjectType,
3591 NamedDecl *UnqualLookup,
3592 CXXScopeSpec &SS) {
3593 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003594
Douglas Gregorb71d8212011-03-02 18:32:08 +00003595 QualType T = TSInfo->getType();
3596 if (getDerived().AlreadyTransformed(T))
3597 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003598
Douglas Gregorb71d8212011-03-02 18:32:08 +00003599 TypeLocBuilder TLB;
3600 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003601
Douglas Gregorb71d8212011-03-02 18:32:08 +00003602 TypeLoc TL = TSInfo->getTypeLoc();
3603 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003604 TemplateSpecializationTypeLoc SpecTL =
3605 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
Douglas Gregorb71d8212011-03-02 18:32:08 +00003607 TemplateName Template
3608 = getDerived().TransformTemplateName(SS,
3609 SpecTL.getTypePtr()->getTemplateName(),
3610 SpecTL.getTemplateNameLoc(),
3611 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003612 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003613 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614
3615 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003616 Template);
3617 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003618 DependentTemplateSpecializationTypeLoc SpecTL =
3619 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620
Douglas Gregorb71d8212011-03-02 18:32:08 +00003621 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003622 = getDerived().RebuildTemplateName(SS,
3623 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003624 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003625 ObjectType, UnqualLookup);
3626 if (Template.isNull())
3627 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003628
3629 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003630 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003631 Template,
3632 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 } else {
3634 // Nothing special needs to be done for these.
3635 Result = getDerived().TransformType(TLB, TL);
3636 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003637
3638 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003639 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003640
Douglas Gregorb71d8212011-03-02 18:32:08 +00003641 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3642}
3643
John McCalla2becad2009-10-21 00:40:46 +00003644template <class TyLoc> static inline
3645QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3646 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3647 NewT.setNameLoc(T.getNameLoc());
3648 return T.getType();
3649}
3650
John McCalla2becad2009-10-21 00:40:46 +00003651template<typename Derived>
3652QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003653 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003654 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3655 NewT.setBuiltinLoc(T.getBuiltinLoc());
3656 if (T.needsExtraLocalData())
3657 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3658 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659}
Mike Stump1eb44332009-09-09 15:08:12 +00003660
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003662QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003663 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003664 // FIXME: recurse?
3665 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003666}
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Douglas Gregor577f75a2009-08-04 16:50:30 +00003668template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003669QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3670 DecayedTypeLoc TL) {
3671 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3672 if (OriginalType.isNull())
3673 return QualType();
3674
3675 QualType Result = TL.getType();
3676 if (getDerived().AlwaysRebuild() ||
3677 OriginalType != TL.getOriginalLoc().getType())
3678 Result = SemaRef.Context.getDecayedType(OriginalType);
3679 TLB.push<DecayedTypeLoc>(Result);
3680 // Nothing to set for DecayedTypeLoc.
3681 return Result;
3682}
3683
3684template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003685QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003686 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003687 QualType PointeeType
3688 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003689 if (PointeeType.isNull())
3690 return QualType();
3691
3692 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003693 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003694 // A dependent pointer type 'T *' has is being transformed such
3695 // that an Objective-C class type is being replaced for 'T'. The
3696 // resulting pointer type is an ObjCObjectPointerType, not a
3697 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003698 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003699
John McCallc12c5bb2010-05-15 11:32:37 +00003700 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3701 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003702 return Result;
3703 }
John McCall43fed0d2010-11-12 08:19:04 +00003704
Douglas Gregor92e986e2010-04-22 16:44:27 +00003705 if (getDerived().AlwaysRebuild() ||
3706 PointeeType != TL.getPointeeLoc().getType()) {
3707 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3708 if (Result.isNull())
3709 return QualType();
3710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003711
John McCallf85e1932011-06-15 23:02:42 +00003712 // Objective-C ARC can add lifetime qualifiers to the type that we're
3713 // pointing to.
3714 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003715
Douglas Gregor92e986e2010-04-22 16:44:27 +00003716 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3717 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003718 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719}
Mike Stump1eb44332009-09-09 15:08:12 +00003720
3721template<typename Derived>
3722QualType
John McCalla2becad2009-10-21 00:40:46 +00003723TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003724 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003725 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003726 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3727 if (PointeeType.isNull())
3728 return QualType();
3729
3730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 PointeeType != TL.getPointeeLoc().getType()) {
3733 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003734 TL.getSigilLoc());
3735 if (Result.isNull())
3736 return QualType();
3737 }
3738
Douglas Gregor39968ad2010-04-22 16:50:51 +00003739 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003740 NewT.setSigilLoc(TL.getSigilLoc());
3741 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742}
3743
John McCall85737a72009-10-30 00:06:24 +00003744/// Transforms a reference type. Note that somewhat paradoxically we
3745/// don't care whether the type itself is an l-value type or an r-value
3746/// type; we only care if the type was *written* as an l-value type
3747/// or an r-value type.
3748template<typename Derived>
3749QualType
3750TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003751 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003752 const ReferenceType *T = TL.getTypePtr();
3753
3754 // Note that this works with the pointee-as-written.
3755 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3756 if (PointeeType.isNull())
3757 return QualType();
3758
3759 QualType Result = TL.getType();
3760 if (getDerived().AlwaysRebuild() ||
3761 PointeeType != T->getPointeeTypeAsWritten()) {
3762 Result = getDerived().RebuildReferenceType(PointeeType,
3763 T->isSpelledAsLValue(),
3764 TL.getSigilLoc());
3765 if (Result.isNull())
3766 return QualType();
3767 }
3768
John McCallf85e1932011-06-15 23:02:42 +00003769 // Objective-C ARC can add lifetime qualifiers to the type that we're
3770 // referring to.
3771 TLB.TypeWasModifiedSafely(
3772 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3773
John McCall85737a72009-10-30 00:06:24 +00003774 // r-value references can be rebuilt as l-value references.
3775 ReferenceTypeLoc NewTL;
3776 if (isa<LValueReferenceType>(Result))
3777 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3778 else
3779 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3780 NewTL.setSigilLoc(TL.getSigilLoc());
3781
3782 return Result;
3783}
3784
Mike Stump1eb44332009-09-09 15:08:12 +00003785template<typename Derived>
3786QualType
John McCalla2becad2009-10-21 00:40:46 +00003787TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003788 LValueReferenceTypeLoc TL) {
3789 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003790}
3791
Mike Stump1eb44332009-09-09 15:08:12 +00003792template<typename Derived>
3793QualType
John McCalla2becad2009-10-21 00:40:46 +00003794TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003795 RValueReferenceTypeLoc TL) {
3796 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003797}
Mike Stump1eb44332009-09-09 15:08:12 +00003798
Douglas Gregor577f75a2009-08-04 16:50:30 +00003799template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003800QualType
John McCalla2becad2009-10-21 00:40:46 +00003801TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003802 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003803 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003804 if (PointeeType.isNull())
3805 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003806
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003807 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3808 TypeSourceInfo* NewClsTInfo = 0;
3809 if (OldClsTInfo) {
3810 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3811 if (!NewClsTInfo)
3812 return QualType();
3813 }
3814
3815 const MemberPointerType *T = TL.getTypePtr();
3816 QualType OldClsType = QualType(T->getClass(), 0);
3817 QualType NewClsType;
3818 if (NewClsTInfo)
3819 NewClsType = NewClsTInfo->getType();
3820 else {
3821 NewClsType = getDerived().TransformType(OldClsType);
3822 if (NewClsType.isNull())
3823 return QualType();
3824 }
Mike Stump1eb44332009-09-09 15:08:12 +00003825
John McCalla2becad2009-10-21 00:40:46 +00003826 QualType Result = TL.getType();
3827 if (getDerived().AlwaysRebuild() ||
3828 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003829 NewClsType != OldClsType) {
3830 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003831 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003832 if (Result.isNull())
3833 return QualType();
3834 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003835
John McCalla2becad2009-10-21 00:40:46 +00003836 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3837 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003838 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003839
3840 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003841}
3842
Mike Stump1eb44332009-09-09 15:08:12 +00003843template<typename Derived>
3844QualType
John McCalla2becad2009-10-21 00:40:46 +00003845TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003846 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003847 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003848 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849 if (ElementType.isNull())
3850 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003851
John McCalla2becad2009-10-21 00:40:46 +00003852 QualType Result = TL.getType();
3853 if (getDerived().AlwaysRebuild() ||
3854 ElementType != T->getElementType()) {
3855 Result = getDerived().RebuildConstantArrayType(ElementType,
3856 T->getSizeModifier(),
3857 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003858 T->getIndexTypeCVRQualifiers(),
3859 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003860 if (Result.isNull())
3861 return QualType();
3862 }
Eli Friedman457a3772012-01-25 22:19:07 +00003863
3864 // We might have either a ConstantArrayType or a VariableArrayType now:
3865 // a ConstantArrayType is allowed to have an element type which is a
3866 // VariableArrayType if the type is dependent. Fortunately, all array
3867 // types have the same location layout.
3868 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003869 NewTL.setLBracketLoc(TL.getLBracketLoc());
3870 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003871
John McCalla2becad2009-10-21 00:40:46 +00003872 Expr *Size = TL.getSizeExpr();
3873 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003874 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3875 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003876 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003877 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003878 }
3879 NewTL.setSizeExpr(Size);
3880
3881 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003882}
Mike Stump1eb44332009-09-09 15:08:12 +00003883
Douglas Gregor577f75a2009-08-04 16:50:30 +00003884template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003885QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003886 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003887 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003888 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003889 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003890 if (ElementType.isNull())
3891 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003892
John McCalla2becad2009-10-21 00:40:46 +00003893 QualType Result = TL.getType();
3894 if (getDerived().AlwaysRebuild() ||
3895 ElementType != T->getElementType()) {
3896 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003897 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003898 T->getIndexTypeCVRQualifiers(),
3899 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003900 if (Result.isNull())
3901 return QualType();
3902 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003903
John McCalla2becad2009-10-21 00:40:46 +00003904 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3905 NewTL.setLBracketLoc(TL.getLBracketLoc());
3906 NewTL.setRBracketLoc(TL.getRBracketLoc());
3907 NewTL.setSizeExpr(0);
3908
3909 return Result;
3910}
3911
3912template<typename Derived>
3913QualType
3914TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003915 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003916 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003917 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3918 if (ElementType.isNull())
3919 return QualType();
3920
John McCall60d7b3a2010-08-24 06:29:42 +00003921 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003922 = getDerived().TransformExpr(T->getSizeExpr());
3923 if (SizeResult.isInvalid())
3924 return QualType();
3925
John McCall9ae2f072010-08-23 23:25:46 +00003926 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003927
3928 QualType Result = TL.getType();
3929 if (getDerived().AlwaysRebuild() ||
3930 ElementType != T->getElementType() ||
3931 Size != T->getSizeExpr()) {
3932 Result = getDerived().RebuildVariableArrayType(ElementType,
3933 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003934 Size,
John McCalla2becad2009-10-21 00:40:46 +00003935 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003936 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003937 if (Result.isNull())
3938 return QualType();
3939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003940
John McCalla2becad2009-10-21 00:40:46 +00003941 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3942 NewTL.setLBracketLoc(TL.getLBracketLoc());
3943 NewTL.setRBracketLoc(TL.getRBracketLoc());
3944 NewTL.setSizeExpr(Size);
3945
3946 return Result;
3947}
3948
3949template<typename Derived>
3950QualType
3951TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003952 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003953 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003954 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3955 if (ElementType.isNull())
3956 return QualType();
3957
Richard Smithf6702a32011-12-20 02:08:33 +00003958 // Array bounds are constant expressions.
3959 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3960 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003961
John McCall3b657512011-01-19 10:06:00 +00003962 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3963 Expr *origSize = TL.getSizeExpr();
3964 if (!origSize) origSize = T->getSizeExpr();
3965
3966 ExprResult sizeResult
3967 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003968 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003969 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003970 return QualType();
3971
John McCall3b657512011-01-19 10:06:00 +00003972 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003973
3974 QualType Result = TL.getType();
3975 if (getDerived().AlwaysRebuild() ||
3976 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003977 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003978 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3979 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003980 size,
John McCalla2becad2009-10-21 00:40:46 +00003981 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003982 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003983 if (Result.isNull())
3984 return QualType();
3985 }
John McCalla2becad2009-10-21 00:40:46 +00003986
3987 // We might have any sort of array type now, but fortunately they
3988 // all have the same location layout.
3989 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3990 NewTL.setLBracketLoc(TL.getLBracketLoc());
3991 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003992 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003993
3994 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003995}
Mike Stump1eb44332009-09-09 15:08:12 +00003996
3997template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003998QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003999 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004000 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004001 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004002
4003 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004004 QualType ElementType = getDerived().TransformType(T->getElementType());
4005 if (ElementType.isNull())
4006 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004007
Richard Smithf6702a32011-12-20 02:08:33 +00004008 // Vector sizes are constant expressions.
4009 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4010 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004011
John McCall60d7b3a2010-08-24 06:29:42 +00004012 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004013 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004014 if (Size.isInvalid())
4015 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004016
John McCalla2becad2009-10-21 00:40:46 +00004017 QualType Result = TL.getType();
4018 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004019 ElementType != T->getElementType() ||
4020 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004021 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004022 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004023 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004024 if (Result.isNull())
4025 return QualType();
4026 }
John McCalla2becad2009-10-21 00:40:46 +00004027
4028 // Result might be dependent or not.
4029 if (isa<DependentSizedExtVectorType>(Result)) {
4030 DependentSizedExtVectorTypeLoc NewTL
4031 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4032 NewTL.setNameLoc(TL.getNameLoc());
4033 } else {
4034 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4035 NewTL.setNameLoc(TL.getNameLoc());
4036 }
4037
4038 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004039}
Mike Stump1eb44332009-09-09 15:08:12 +00004040
4041template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004042QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004043 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004044 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004045 QualType ElementType = getDerived().TransformType(T->getElementType());
4046 if (ElementType.isNull())
4047 return QualType();
4048
John McCalla2becad2009-10-21 00:40:46 +00004049 QualType Result = TL.getType();
4050 if (getDerived().AlwaysRebuild() ||
4051 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004052 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004053 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004054 if (Result.isNull())
4055 return QualType();
4056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004057
John McCalla2becad2009-10-21 00:40:46 +00004058 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4059 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004060
John McCalla2becad2009-10-21 00:40:46 +00004061 return Result;
4062}
4063
4064template<typename Derived>
4065QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004066 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004067 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004068 QualType ElementType = getDerived().TransformType(T->getElementType());
4069 if (ElementType.isNull())
4070 return QualType();
4071
4072 QualType Result = TL.getType();
4073 if (getDerived().AlwaysRebuild() ||
4074 ElementType != T->getElementType()) {
4075 Result = getDerived().RebuildExtVectorType(ElementType,
4076 T->getNumElements(),
4077 /*FIXME*/ SourceLocation());
4078 if (Result.isNull())
4079 return QualType();
4080 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081
John McCalla2becad2009-10-21 00:40:46 +00004082 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4083 NewTL.setNameLoc(TL.getNameLoc());
4084
4085 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004086}
Mike Stump1eb44332009-09-09 15:08:12 +00004087
David Blaikiedc84cd52013-02-20 22:23:23 +00004088template <typename Derived>
4089ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4090 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4091 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004092 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004094
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004095 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004097 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004098 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004099 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004100
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004101 TypeLocBuilder TLB;
4102 TypeLoc NewTL = OldDI->getTypeLoc();
4103 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104
4105 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004106 OldExpansionTL.getPatternLoc());
4107 if (Result.isNull())
4108 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004109
4110 Result = RebuildPackExpansionType(Result,
4111 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004112 OldExpansionTL.getEllipsisLoc(),
4113 NumExpansions);
4114 if (Result.isNull())
4115 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004117 PackExpansionTypeLoc NewExpansionTL
4118 = TLB.push<PackExpansionTypeLoc>(Result);
4119 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4120 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4121 } else
4122 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004123 if (!NewDI)
4124 return 0;
4125
John McCallfb44de92011-05-01 22:35:37 +00004126 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004127 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004128
4129 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4130 OldParm->getDeclContext(),
4131 OldParm->getInnerLocStart(),
4132 OldParm->getLocation(),
4133 OldParm->getIdentifier(),
4134 NewDI->getType(),
4135 NewDI,
4136 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004137 /* DefArg */ NULL);
4138 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4139 OldParm->getFunctionScopeIndex() + indexAdjustment);
4140 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004141}
4142
4143template<typename Derived>
4144bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004145 TransformFunctionTypeParams(SourceLocation Loc,
4146 ParmVarDecl **Params, unsigned NumParams,
4147 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004148 SmallVectorImpl<QualType> &OutParamTypes,
4149 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004150 int indexAdjustment = 0;
4151
Douglas Gregora009b592011-01-07 00:20:55 +00004152 for (unsigned i = 0; i != NumParams; ++i) {
4153 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004154 assert(OldParm->getFunctionScopeIndex() == i);
4155
David Blaikiedc84cd52013-02-20 22:23:23 +00004156 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004157 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 if (OldParm->isParameterPack()) {
4159 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004160 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004161
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004163 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004164 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004165 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4166 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004167 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4168
Douglas Gregor603cfb42011-01-05 23:12:31 +00004169 // Determine whether we should expand the parameter packs.
4170 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004171 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004172 Optional<unsigned> OrigNumExpansions =
4173 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004174 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004175 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4176 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004177 Unexpanded,
4178 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004179 RetainExpansion,
4180 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 return true;
4182 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004183
Douglas Gregor603cfb42011-01-05 23:12:31 +00004184 if (ShouldExpand) {
4185 // Expand the function parameter pack into multiple, separate
4186 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004187 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004188 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004190 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004191 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004192 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004193 OrigNumExpansions,
4194 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004195 if (!NewParm)
4196 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004197
Douglas Gregora009b592011-01-07 00:20:55 +00004198 OutParamTypes.push_back(NewParm->getType());
4199 if (PVars)
4200 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004201 }
Douglas Gregord3731192011-01-10 07:32:04 +00004202
4203 // If we're supposed to retain a pack expansion, do so by temporarily
4204 // forgetting the partially-substituted parameter pack.
4205 if (RetainExpansion) {
4206 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004208 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004209 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004210 OrigNumExpansions,
4211 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004212 if (!NewParm)
4213 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004214
Douglas Gregord3731192011-01-10 07:32:04 +00004215 OutParamTypes.push_back(NewParm->getType());
4216 if (PVars)
4217 PVars->push_back(NewParm);
4218 }
4219
John McCallfb44de92011-05-01 22:35:37 +00004220 // The next parameter should have the same adjustment as the
4221 // last thing we pushed, but we post-incremented indexAdjustment
4222 // on every push. Also, if we push nothing, the adjustment should
4223 // go down by one.
4224 indexAdjustment--;
4225
Douglas Gregor603cfb42011-01-05 23:12:31 +00004226 // We're done with the pack expansion.
4227 continue;
4228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004229
4230 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004231 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004232 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4233 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004234 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004235 NumExpansions,
4236 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004237 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004238 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004239 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004240 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004241
John McCall21ef0fa2010-03-11 09:03:00 +00004242 if (!NewParm)
4243 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004244
Douglas Gregora009b592011-01-07 00:20:55 +00004245 OutParamTypes.push_back(NewParm->getType());
4246 if (PVars)
4247 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004248 continue;
4249 }
John McCall21ef0fa2010-03-11 09:03:00 +00004250
4251 // Deal with the possibility that we don't have a parameter
4252 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004253 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004254 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004255 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004256 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004257 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004258 = dyn_cast<PackExpansionType>(OldType)) {
4259 // We have a function parameter pack that may need to be expanded.
4260 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004261 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004262 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004263
Douglas Gregor603cfb42011-01-05 23:12:31 +00004264 // Determine whether we should expand the parameter packs.
4265 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004266 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004267 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004268 Unexpanded,
4269 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004270 RetainExpansion,
4271 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004272 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004273 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004274
Douglas Gregor603cfb42011-01-05 23:12:31 +00004275 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004276 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004277 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004278 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004279 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4280 QualType NewType = getDerived().TransformType(Pattern);
4281 if (NewType.isNull())
4282 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004283
Douglas Gregora009b592011-01-07 00:20:55 +00004284 OutParamTypes.push_back(NewType);
4285 if (PVars)
4286 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004288
Douglas Gregor603cfb42011-01-05 23:12:31 +00004289 // We're done with the pack expansion.
4290 continue;
4291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004292
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004293 // If we're supposed to retain a pack expansion, do so by temporarily
4294 // forgetting the partially-substituted parameter pack.
4295 if (RetainExpansion) {
4296 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4297 QualType NewType = getDerived().TransformType(Pattern);
4298 if (NewType.isNull())
4299 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004300
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004301 OutParamTypes.push_back(NewType);
4302 if (PVars)
4303 PVars->push_back(0);
4304 }
Douglas Gregord3731192011-01-10 07:32:04 +00004305
Chad Rosier4a9d7952012-08-08 18:46:20 +00004306 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004307 // expansion.
4308 OldType = Expansion->getPattern();
4309 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004310 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4311 NewType = getDerived().TransformType(OldType);
4312 } else {
4313 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004314 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004315
Douglas Gregor603cfb42011-01-05 23:12:31 +00004316 if (NewType.isNull())
4317 return true;
4318
4319 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004320 NewType = getSema().Context.getPackExpansionType(NewType,
4321 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004322
Douglas Gregora009b592011-01-07 00:20:55 +00004323 OutParamTypes.push_back(NewType);
4324 if (PVars)
4325 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004326 }
4327
John McCallfb44de92011-05-01 22:35:37 +00004328#ifndef NDEBUG
4329 if (PVars) {
4330 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4331 if (ParmVarDecl *parm = (*PVars)[i])
4332 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004333 }
John McCallfb44de92011-05-01 22:35:37 +00004334#endif
4335
4336 return false;
4337}
John McCall21ef0fa2010-03-11 09:03:00 +00004338
4339template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004340QualType
John McCalla2becad2009-10-21 00:40:46 +00004341TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004342 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004343 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4344}
4345
4346template<typename Derived>
4347QualType
4348TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4349 FunctionProtoTypeLoc TL,
4350 CXXRecordDecl *ThisContext,
4351 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004352 // Transform the parameters and return type.
4353 //
Richard Smithe6975e92012-04-17 00:58:00 +00004354 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004355 // When the function has a trailing return type, we instantiate the
4356 // parameters before the return type, since the return type can then refer
4357 // to the parameters themselves (via decltype, sizeof, etc.).
4358 //
Chris Lattner686775d2011-07-20 06:58:45 +00004359 SmallVector<QualType, 4> ParamTypes;
4360 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004361 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004362
Douglas Gregordab60ad2010-10-01 18:44:50 +00004363 QualType ResultType;
4364
Richard Smith9fbf3272012-08-14 22:51:13 +00004365 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004366 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004367 TL.getParmArray(),
4368 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004369 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004370 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004371 return QualType();
4372
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004373 {
4374 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004375 // If a declaration declares a member function or member function
4376 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004377 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004378 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004379 // declarator.
4380 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004381
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004382 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4383 if (ResultType.isNull())
4384 return QualType();
4385 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004386 }
4387 else {
4388 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4389 if (ResultType.isNull())
4390 return QualType();
4391
Chad Rosier4a9d7952012-08-08 18:46:20 +00004392 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004393 TL.getParmArray(),
4394 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004395 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004396 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004397 return QualType();
4398 }
4399
Richard Smithe6975e92012-04-17 00:58:00 +00004400 // FIXME: Need to transform the exception-specification too.
4401
John McCalla2becad2009-10-21 00:40:46 +00004402 QualType Result = TL.getType();
4403 if (getDerived().AlwaysRebuild() ||
4404 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004405 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004406 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004407 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004408 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004409 if (Result.isNull())
4410 return QualType();
4411 }
Mike Stump1eb44332009-09-09 15:08:12 +00004412
John McCalla2becad2009-10-21 00:40:46 +00004413 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004414 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004415 NewTL.setLParenLoc(TL.getLParenLoc());
4416 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004417 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004418 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4419 NewTL.setArg(i, ParamDecls[i]);
4420
4421 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422}
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424template<typename Derived>
4425QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004426 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004427 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004428 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004429 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4430 if (ResultType.isNull())
4431 return QualType();
4432
4433 QualType Result = TL.getType();
4434 if (getDerived().AlwaysRebuild() ||
4435 ResultType != T->getResultType())
4436 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4437
4438 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004439 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004440 NewTL.setLParenLoc(TL.getLParenLoc());
4441 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004442 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004443
4444 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445}
Mike Stump1eb44332009-09-09 15:08:12 +00004446
John McCalled976492009-12-04 22:46:56 +00004447template<typename Derived> QualType
4448TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004449 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004450 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004451 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004452 if (!D)
4453 return QualType();
4454
4455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4457 Result = getDerived().RebuildUnresolvedUsingType(D);
4458 if (Result.isNull())
4459 return QualType();
4460 }
4461
4462 // We might get an arbitrary type spec type back. We should at
4463 // least always get a type spec type, though.
4464 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4465 NewTL.setNameLoc(TL.getNameLoc());
4466
4467 return Result;
4468}
4469
Douglas Gregor577f75a2009-08-04 16:50:30 +00004470template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004471QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004472 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004473 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004474 TypedefNameDecl *Typedef
4475 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4476 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477 if (!Typedef)
4478 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004479
John McCalla2becad2009-10-21 00:40:46 +00004480 QualType Result = TL.getType();
4481 if (getDerived().AlwaysRebuild() ||
4482 Typedef != T->getDecl()) {
4483 Result = getDerived().RebuildTypedefType(Typedef);
4484 if (Result.isNull())
4485 return QualType();
4486 }
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCalla2becad2009-10-21 00:40:46 +00004488 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4489 NewTL.setNameLoc(TL.getNameLoc());
4490
4491 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492}
Mike Stump1eb44332009-09-09 15:08:12 +00004493
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004495QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004496 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004497 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004498 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4499 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004500
John McCall60d7b3a2010-08-24 06:29:42 +00004501 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 if (E.isInvalid())
4503 return QualType();
4504
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004505 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4506 if (E.isInvalid())
4507 return QualType();
4508
John McCalla2becad2009-10-21 00:40:46 +00004509 QualType Result = TL.getType();
4510 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004511 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004512 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004513 if (Result.isNull())
4514 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004515 }
John McCalla2becad2009-10-21 00:40:46 +00004516 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004517
John McCalla2becad2009-10-21 00:40:46 +00004518 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004519 NewTL.setTypeofLoc(TL.getTypeofLoc());
4520 NewTL.setLParenLoc(TL.getLParenLoc());
4521 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004522
4523 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524}
Mike Stump1eb44332009-09-09 15:08:12 +00004525
4526template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004527QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004528 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004529 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4530 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4531 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004533
John McCalla2becad2009-10-21 00:40:46 +00004534 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004535 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4536 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004537 if (Result.isNull())
4538 return QualType();
4539 }
Mike Stump1eb44332009-09-09 15:08:12 +00004540
John McCalla2becad2009-10-21 00:40:46 +00004541 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004542 NewTL.setTypeofLoc(TL.getTypeofLoc());
4543 NewTL.setLParenLoc(TL.getLParenLoc());
4544 NewTL.setRParenLoc(TL.getRParenLoc());
4545 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004546
4547 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004548}
Mike Stump1eb44332009-09-09 15:08:12 +00004549
4550template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004551QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004552 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004553 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004554
Douglas Gregor670444e2009-08-04 22:27:00 +00004555 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004556 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4557 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004558
John McCall60d7b3a2010-08-24 06:29:42 +00004559 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004560 if (E.isInvalid())
4561 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004562
Richard Smith76f3f692012-02-22 02:04:18 +00004563 E = getSema().ActOnDecltypeExpression(E.take());
4564 if (E.isInvalid())
4565 return QualType();
4566
John McCalla2becad2009-10-21 00:40:46 +00004567 QualType Result = TL.getType();
4568 if (getDerived().AlwaysRebuild() ||
4569 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004570 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004571 if (Result.isNull())
4572 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004573 }
John McCalla2becad2009-10-21 00:40:46 +00004574 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004575
John McCalla2becad2009-10-21 00:40:46 +00004576 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4577 NewTL.setNameLoc(TL.getNameLoc());
4578
4579 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004580}
4581
4582template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004583QualType TreeTransform<Derived>::TransformUnaryTransformType(
4584 TypeLocBuilder &TLB,
4585 UnaryTransformTypeLoc TL) {
4586 QualType Result = TL.getType();
4587 if (Result->isDependentType()) {
4588 const UnaryTransformType *T = TL.getTypePtr();
4589 QualType NewBase =
4590 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4591 Result = getDerived().RebuildUnaryTransformType(NewBase,
4592 T->getUTTKind(),
4593 TL.getKWLoc());
4594 if (Result.isNull())
4595 return QualType();
4596 }
4597
4598 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4599 NewTL.setKWLoc(TL.getKWLoc());
4600 NewTL.setParensRange(TL.getParensRange());
4601 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4602 return Result;
4603}
4604
4605template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004606QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4607 AutoTypeLoc TL) {
4608 const AutoType *T = TL.getTypePtr();
4609 QualType OldDeduced = T->getDeducedType();
4610 QualType NewDeduced;
4611 if (!OldDeduced.isNull()) {
4612 NewDeduced = getDerived().TransformType(OldDeduced);
4613 if (NewDeduced.isNull())
4614 return QualType();
4615 }
4616
4617 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004618 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4619 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004620 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004621 if (Result.isNull())
4622 return QualType();
4623 }
4624
4625 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4626 NewTL.setNameLoc(TL.getNameLoc());
4627
4628 return Result;
4629}
4630
4631template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004632QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004633 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004634 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004635 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004636 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4637 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004638 if (!Record)
4639 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004640
John McCalla2becad2009-10-21 00:40:46 +00004641 QualType Result = TL.getType();
4642 if (getDerived().AlwaysRebuild() ||
4643 Record != T->getDecl()) {
4644 Result = getDerived().RebuildRecordType(Record);
4645 if (Result.isNull())
4646 return QualType();
4647 }
Mike Stump1eb44332009-09-09 15:08:12 +00004648
John McCalla2becad2009-10-21 00:40:46 +00004649 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4650 NewTL.setNameLoc(TL.getNameLoc());
4651
4652 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004653}
Mike Stump1eb44332009-09-09 15:08:12 +00004654
4655template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004656QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004657 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004658 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004659 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004660 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4661 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004662 if (!Enum)
4663 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCalla2becad2009-10-21 00:40:46 +00004665 QualType Result = TL.getType();
4666 if (getDerived().AlwaysRebuild() ||
4667 Enum != T->getDecl()) {
4668 Result = getDerived().RebuildEnumType(Enum);
4669 if (Result.isNull())
4670 return QualType();
4671 }
Mike Stump1eb44332009-09-09 15:08:12 +00004672
John McCalla2becad2009-10-21 00:40:46 +00004673 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4674 NewTL.setNameLoc(TL.getNameLoc());
4675
4676 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004677}
John McCall7da24312009-09-05 00:15:47 +00004678
John McCall3cb0ebd2010-03-10 03:28:59 +00004679template<typename Derived>
4680QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4681 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004682 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004683 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4684 TL.getTypePtr()->getDecl());
4685 if (!D) return QualType();
4686
4687 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4688 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4689 return T;
4690}
4691
Douglas Gregor577f75a2009-08-04 16:50:30 +00004692template<typename Derived>
4693QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004694 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004695 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004696 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004697}
4698
Mike Stump1eb44332009-09-09 15:08:12 +00004699template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004700QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004701 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004702 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004703 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004705 // Substitute into the replacement type, which itself might involve something
4706 // that needs to be transformed. This only tends to occur with default
4707 // template arguments of template template parameters.
4708 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4709 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4710 if (Replacement.isNull())
4711 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004712
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004713 // Always canonicalize the replacement type.
4714 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4715 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004716 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004717 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004718
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004719 // Propagate type-source information.
4720 SubstTemplateTypeParmTypeLoc NewTL
4721 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4722 NewTL.setNameLoc(TL.getNameLoc());
4723 return Result;
4724
John McCall49a832b2009-10-18 09:09:24 +00004725}
4726
4727template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004728QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4729 TypeLocBuilder &TLB,
4730 SubstTemplateTypeParmPackTypeLoc TL) {
4731 return TransformTypeSpecType(TLB, TL);
4732}
4733
4734template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004735QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004736 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004737 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004738 const TemplateSpecializationType *T = TL.getTypePtr();
4739
Douglas Gregor1d752d72011-03-02 18:46:51 +00004740 // The nested-name-specifier never matters in a TemplateSpecializationType,
4741 // because we can't have a dependent nested-name-specifier anyway.
4742 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004743 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004744 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4745 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004746 if (Template.isNull())
4747 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004748
John McCall43fed0d2010-11-12 08:19:04 +00004749 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4750}
4751
Eli Friedmanb001de72011-10-06 23:00:33 +00004752template<typename Derived>
4753QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4754 AtomicTypeLoc TL) {
4755 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4756 if (ValueType.isNull())
4757 return QualType();
4758
4759 QualType Result = TL.getType();
4760 if (getDerived().AlwaysRebuild() ||
4761 ValueType != TL.getValueLoc().getType()) {
4762 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4763 if (Result.isNull())
4764 return QualType();
4765 }
4766
4767 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4768 NewTL.setKWLoc(TL.getKWLoc());
4769 NewTL.setLParenLoc(TL.getLParenLoc());
4770 NewTL.setRParenLoc(TL.getRParenLoc());
4771
4772 return Result;
4773}
4774
Chad Rosier4a9d7952012-08-08 18:46:20 +00004775 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004776 /// container that provides a \c getArgLoc() member function.
4777 ///
4778 /// This iterator is intended to be used with the iterator form of
4779 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4780 template<typename ArgLocContainer>
4781 class TemplateArgumentLocContainerIterator {
4782 ArgLocContainer *Container;
4783 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004785 public:
4786 typedef TemplateArgumentLoc value_type;
4787 typedef TemplateArgumentLoc reference;
4788 typedef int difference_type;
4789 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004790
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004791 class pointer {
4792 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004794 public:
4795 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004797 const TemplateArgumentLoc *operator->() const {
4798 return &Arg;
4799 }
4800 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
4802
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004803 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004804
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004805 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4806 unsigned Index)
4807 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004808
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004809 TemplateArgumentLocContainerIterator &operator++() {
4810 ++Index;
4811 return *this;
4812 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004814 TemplateArgumentLocContainerIterator operator++(int) {
4815 TemplateArgumentLocContainerIterator Old(*this);
4816 ++(*this);
4817 return Old;
4818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 TemplateArgumentLoc operator*() const {
4821 return Container->getArgLoc(Index);
4822 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004823
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004824 pointer operator->() const {
4825 return pointer(Container->getArgLoc(Index));
4826 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004827
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004828 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004829 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004830 return X.Container == Y.Container && X.Index == Y.Index;
4831 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004832
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004833 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004834 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004835 return !(X == Y);
4836 }
4837 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004838
4839
John McCall43fed0d2010-11-12 08:19:04 +00004840template <typename Derived>
4841QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4842 TypeLocBuilder &TLB,
4843 TemplateSpecializationTypeLoc TL,
4844 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004845 TemplateArgumentListInfo NewTemplateArgs;
4846 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4847 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004848 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4849 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004850 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004851 ArgIterator(TL, TL.getNumArgs()),
4852 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004853 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004854
John McCall833ca992009-10-29 08:12:44 +00004855 // FIXME: maybe don't rebuild if all the template arguments are the same.
4856
4857 QualType Result =
4858 getDerived().RebuildTemplateSpecializationType(Template,
4859 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004860 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004861
4862 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004863 // Specializations of template template parameters are represented as
4864 // TemplateSpecializationTypes, and substitution of type alias templates
4865 // within a dependent context can transform them into
4866 // DependentTemplateSpecializationTypes.
4867 if (isa<DependentTemplateSpecializationType>(Result)) {
4868 DependentTemplateSpecializationTypeLoc NewTL
4869 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004870 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004871 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004872 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004873 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004874 NewTL.setLAngleLoc(TL.getLAngleLoc());
4875 NewTL.setRAngleLoc(TL.getRAngleLoc());
4876 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4877 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4878 return Result;
4879 }
4880
John McCall833ca992009-10-29 08:12:44 +00004881 TemplateSpecializationTypeLoc NewTL
4882 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004883 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004884 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4885 NewTL.setLAngleLoc(TL.getLAngleLoc());
4886 NewTL.setRAngleLoc(TL.getRAngleLoc());
4887 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4888 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004889 }
Mike Stump1eb44332009-09-09 15:08:12 +00004890
John McCall833ca992009-10-29 08:12:44 +00004891 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004892}
Mike Stump1eb44332009-09-09 15:08:12 +00004893
Douglas Gregora88f09f2011-02-28 17:23:35 +00004894template <typename Derived>
4895QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4896 TypeLocBuilder &TLB,
4897 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004898 TemplateName Template,
4899 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004900 TemplateArgumentListInfo NewTemplateArgs;
4901 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4902 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4903 typedef TemplateArgumentLocContainerIterator<
4904 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004905 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004906 ArgIterator(TL, TL.getNumArgs()),
4907 NewTemplateArgs))
4908 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004909
Douglas Gregora88f09f2011-02-28 17:23:35 +00004910 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004911
Douglas Gregora88f09f2011-02-28 17:23:35 +00004912 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4913 QualType Result
4914 = getSema().Context.getDependentTemplateSpecializationType(
4915 TL.getTypePtr()->getKeyword(),
4916 DTN->getQualifier(),
4917 DTN->getIdentifier(),
4918 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004919
Douglas Gregora88f09f2011-02-28 17:23:35 +00004920 DependentTemplateSpecializationTypeLoc NewTL
4921 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004922 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004923 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004924 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004925 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004926 NewTL.setLAngleLoc(TL.getLAngleLoc());
4927 NewTL.setRAngleLoc(TL.getRAngleLoc());
4928 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4929 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4930 return Result;
4931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004932
4933 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004934 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004937
Douglas Gregora88f09f2011-02-28 17:23:35 +00004938 if (!Result.isNull()) {
4939 /// FIXME: Wrap this in an elaborated-type-specifier?
4940 TemplateSpecializationTypeLoc NewTL
4941 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004942 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004943 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004944 NewTL.setLAngleLoc(TL.getLAngleLoc());
4945 NewTL.setRAngleLoc(TL.getRAngleLoc());
4946 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4947 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949
Douglas Gregora88f09f2011-02-28 17:23:35 +00004950 return Result;
4951}
4952
Mike Stump1eb44332009-09-09 15:08:12 +00004953template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004954QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004955TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004956 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004957 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004958
Douglas Gregor9e876872011-03-01 18:12:44 +00004959 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004960 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004961 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004962 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004963 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4964 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004965 return QualType();
4966 }
Mike Stump1eb44332009-09-09 15:08:12 +00004967
John McCall43fed0d2010-11-12 08:19:04 +00004968 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4969 if (NamedT.isNull())
4970 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004971
Richard Smith3e4c6c42011-05-05 21:57:07 +00004972 // C++0x [dcl.type.elab]p2:
4973 // If the identifier resolves to a typedef-name or the simple-template-id
4974 // resolves to an alias template specialization, the
4975 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004976 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4977 if (const TemplateSpecializationType *TST =
4978 NamedT->getAs<TemplateSpecializationType>()) {
4979 TemplateName Template = TST->getTemplateName();
4980 if (TypeAliasTemplateDecl *TAT =
4981 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4982 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4983 diag::err_tag_reference_non_tag) << 4;
4984 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4985 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004986 }
4987 }
4988
John McCalla2becad2009-10-21 00:40:46 +00004989 QualType Result = TL.getType();
4990 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004991 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004992 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004994 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004995 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004996 if (Result.isNull())
4997 return QualType();
4998 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004999
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005000 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005001 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005002 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005003 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005004}
Mike Stump1eb44332009-09-09 15:08:12 +00005005
5006template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005007QualType TreeTransform<Derived>::TransformAttributedType(
5008 TypeLocBuilder &TLB,
5009 AttributedTypeLoc TL) {
5010 const AttributedType *oldType = TL.getTypePtr();
5011 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5012 if (modifiedType.isNull())
5013 return QualType();
5014
5015 QualType result = TL.getType();
5016
5017 // FIXME: dependent operand expressions?
5018 if (getDerived().AlwaysRebuild() ||
5019 modifiedType != oldType->getModifiedType()) {
5020 // TODO: this is really lame; we should really be rebuilding the
5021 // equivalent type from first principles.
5022 QualType equivalentType
5023 = getDerived().TransformType(oldType->getEquivalentType());
5024 if (equivalentType.isNull())
5025 return QualType();
5026 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5027 modifiedType,
5028 equivalentType);
5029 }
5030
5031 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5032 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5033 if (TL.hasAttrOperand())
5034 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5035 if (TL.hasAttrExprOperand())
5036 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5037 else if (TL.hasAttrEnumOperand())
5038 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5039
5040 return result;
5041}
5042
5043template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005044QualType
5045TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5046 ParenTypeLoc TL) {
5047 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5048 if (Inner.isNull())
5049 return QualType();
5050
5051 QualType Result = TL.getType();
5052 if (getDerived().AlwaysRebuild() ||
5053 Inner != TL.getInnerLoc().getType()) {
5054 Result = getDerived().RebuildParenType(Inner);
5055 if (Result.isNull())
5056 return QualType();
5057 }
5058
5059 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5060 NewTL.setLParenLoc(TL.getLParenLoc());
5061 NewTL.setRParenLoc(TL.getRParenLoc());
5062 return Result;
5063}
5064
5065template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005066QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005067 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005068 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005069
Douglas Gregor2494dd02011-03-01 01:34:45 +00005070 NestedNameSpecifierLoc QualifierLoc
5071 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5072 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005073 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005074
John McCall33500952010-06-11 00:33:02 +00005075 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005076 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005077 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005078 QualifierLoc,
5079 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005080 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005081 if (Result.isNull())
5082 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005083
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005084 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5085 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005086 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5087
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005088 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005090 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005091 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005092 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005093 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005094 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005095 NewTL.setNameLoc(TL.getNameLoc());
5096 }
John McCalla2becad2009-10-21 00:40:46 +00005097 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005098}
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor577f75a2009-08-04 16:50:30 +00005100template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005101QualType TreeTransform<Derived>::
5102 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005103 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005104 NestedNameSpecifierLoc QualifierLoc;
5105 if (TL.getQualifierLoc()) {
5106 QualifierLoc
5107 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5108 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005109 return QualType();
5110 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005111
John McCall43fed0d2010-11-12 08:19:04 +00005112 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005113 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005114}
5115
5116template<typename Derived>
5117QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005118TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5119 DependentTemplateSpecializationTypeLoc TL,
5120 NestedNameSpecifierLoc QualifierLoc) {
5121 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005122
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005123 TemplateArgumentListInfo NewTemplateArgs;
5124 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5125 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005126
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005127 typedef TemplateArgumentLocContainerIterator<
5128 DependentTemplateSpecializationTypeLoc> ArgIterator;
5129 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5130 ArgIterator(TL, TL.getNumArgs()),
5131 NewTemplateArgs))
5132 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005133
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005134 QualType Result
5135 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5136 QualifierLoc,
5137 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005138 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005139 NewTemplateArgs);
5140 if (Result.isNull())
5141 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005142
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005143 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5144 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005145
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005146 // Copy information relevant to the template specialization.
5147 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005148 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005149 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005150 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5152 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005153 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005154 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005155
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005156 // Copy information relevant to the elaborated type.
5157 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005158 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005159 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005160 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5161 DependentTemplateSpecializationTypeLoc SpecTL
5162 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005163 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005164 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005165 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005166 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005167 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5168 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005169 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005170 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005171 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005172 TemplateSpecializationTypeLoc SpecTL
5173 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005174 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005175 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005176 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5177 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005178 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005179 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005180 }
5181 return Result;
5182}
5183
5184template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005185QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5186 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005187 QualType Pattern
5188 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005189 if (Pattern.isNull())
5190 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005191
5192 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005193 if (getDerived().AlwaysRebuild() ||
5194 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005195 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005196 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005197 TL.getEllipsisLoc(),
5198 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005199 if (Result.isNull())
5200 return QualType();
5201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005202
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005203 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5204 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5205 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005206}
5207
5208template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005209QualType
5210TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005211 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005212 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005213 TLB.pushFullCopy(TL);
5214 return TL.getType();
5215}
5216
5217template<typename Derived>
5218QualType
5219TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005220 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005221 // ObjCObjectType is never dependent.
5222 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005223 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005224}
Mike Stump1eb44332009-09-09 15:08:12 +00005225
5226template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005227QualType
5228TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005229 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005230 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005231 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005232 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005233}
5234
Douglas Gregor577f75a2009-08-04 16:50:30 +00005235//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005236// Statement transformation
5237//===----------------------------------------------------------------------===//
5238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005239StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005240TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005241 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005242}
5243
5244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005245StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005246TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5247 return getDerived().TransformCompoundStmt(S, false);
5248}
5249
5250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005251StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005252TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005254 Sema::CompoundScopeRAII CompoundScope(getSema());
5255
John McCall7114cba2010-08-27 19:56:05 +00005256 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005258 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5260 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005261 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005262 if (Result.isInvalid()) {
5263 // Immediately fail if this was a DeclStmt, since it's very
5264 // likely that this will cause problems for future statements.
5265 if (isa<DeclStmt>(*B))
5266 return StmtError();
5267
5268 // Otherwise, just keep processing substatements and fail later.
5269 SubStmtInvalid = true;
5270 continue;
5271 }
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5274 Statements.push_back(Result.takeAs<Stmt>());
5275 }
Mike Stump1eb44332009-09-09 15:08:12 +00005276
John McCall7114cba2010-08-27 19:56:05 +00005277 if (SubStmtInvalid)
5278 return StmtError();
5279
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 if (!getDerived().AlwaysRebuild() &&
5281 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005283
5284 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005285 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 S->getRBracLoc(),
5287 IsStmtExpr);
5288}
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005291StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005292TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005293 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005294 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005295 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5296 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Eli Friedman264c1f82009-11-19 03:14:00 +00005298 // Transform the left-hand case value.
5299 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005300 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005301 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005302 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Eli Friedman264c1f82009-11-19 03:14:00 +00005304 // Transform the right-hand case value (for the GNU case-range extension).
5305 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005306 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005307 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005309 }
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Build the case statement.
5312 // Case statements are always rebuilt so that they will attached to their
5313 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005314 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005315 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005317 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 S->getColonLoc());
5319 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregor43959a92009-08-20 07:17:43 +00005322 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005323 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005326
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005328 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329}
5330
5331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Default statements are always rebuilt
5340 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005341 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005342}
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005345StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005346TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005347 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Chris Lattner57ad3782011-02-17 20:34:02 +00005351 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5352 S->getDecl());
5353 if (!LD)
5354 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005355
5356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005358 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005359 cast<LabelDecl>(LD), SourceLocation(),
5360 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005361}
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005364StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005365TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5366 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5367 if (SubStmt.isInvalid())
5368 return StmtError();
5369
5370 // TODO: transform attributes
5371 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5372 return S;
5373
5374 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5375 S->getAttrs(),
5376 SubStmt.get());
5377}
5378
5379template<typename Derived>
5380StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005381TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005383 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005384 VarDecl *ConditionVar = 0;
5385 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005386 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005387 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005388 getDerived().TransformDefinition(
5389 S->getConditionVariable()->getLocation(),
5390 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005391 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005392 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005393 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005394 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005395
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005396 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005398
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005399 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005400 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005402 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005403 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405
John McCall9ae2f072010-08-23 23:25:46 +00005406 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005407 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409
John McCall9ae2f072010-08-23 23:25:46 +00005410 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5411 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005413
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005415 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005417 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005420 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005421 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005422 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005425 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005426 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 Then.get() == S->getThen() &&
5428 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005430
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005431 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005432 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005433 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005434}
5435
5436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005438TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005440 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005441 VarDecl *ConditionVar = 0;
5442 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005443 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005444 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005445 getDerived().TransformDefinition(
5446 S->getConditionVariable()->getLocation(),
5447 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005448 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005450 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005451 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005452
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005453 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005455 }
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005458 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005459 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005460 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005465 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005466 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005467 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005468
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005470 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5471 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005472}
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005475StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005476TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005478 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005479 VarDecl *ConditionVar = 0;
5480 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005481 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005482 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005483 getDerived().TransformDefinition(
5484 S->getConditionVariable()->getLocation(),
5485 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005486 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005487 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005488 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005489 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005490
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005491 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005493
5494 if (S->getCond()) {
5495 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005496 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005497 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005498 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005500 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005501 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005502 }
Mike Stump1eb44332009-09-09 15:08:12 +00005503
John McCall9ae2f072010-08-23 23:25:46 +00005504 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5505 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005506 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005509 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005511 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005514 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005515 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005517 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005519 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005520 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005521}
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregor43959a92009-08-20 07:17:43 +00005523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005524StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005525TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005527 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005529 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005531 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005532 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005533 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005534 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005535
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 if (!getDerived().AlwaysRebuild() &&
5537 Cond.get() == S->getCond() &&
5538 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005539 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005540
John McCall9ae2f072010-08-23 23:25:46 +00005541 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5542 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 S->getRParenLoc());
5544}
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005547StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005548TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005549 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005550 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005551 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005552 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor43959a92009-08-20 07:17:43 +00005554 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005555 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005556 VarDecl *ConditionVar = 0;
5557 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005558 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005559 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005560 getDerived().TransformDefinition(
5561 S->getConditionVariable()->getLocation(),
5562 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005563 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005564 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005565 } else {
5566 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005567
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005568 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005570
5571 if (S->getCond()) {
5572 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005573 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005574 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005575 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005577
John McCall9ae2f072010-08-23 23:25:46 +00005578 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005579 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005580 }
Mike Stump1eb44332009-09-09 15:08:12 +00005581
Chad Rosier4a9d7952012-08-08 18:46:20 +00005582 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005583 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005584 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005585
Douglas Gregor43959a92009-08-20 07:17:43 +00005586 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005587 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005588 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005589 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005590
Richard Smith41956372013-01-14 22:39:08 +00005591 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005592 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005596 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005597 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005598 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005599
Douglas Gregor43959a92009-08-20 07:17:43 +00005600 if (!getDerived().AlwaysRebuild() &&
5601 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005602 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005603 Inc.get() == S->getInc() &&
5604 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005605 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005606
Douglas Gregor43959a92009-08-20 07:17:43 +00005607 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005608 Init.get(), FullCond, ConditionVar,
5609 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005610}
5611
5612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005613StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005614TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005615 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5616 S->getLabel());
5617 if (!LD)
5618 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005619
Douglas Gregor43959a92009-08-20 07:17:43 +00005620 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005621 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005622 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005623}
5624
5625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005626StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005628 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005629 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005631 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005632
Douglas Gregor43959a92009-08-20 07:17:43 +00005633 if (!getDerived().AlwaysRebuild() &&
5634 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005635 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005636
5637 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005638 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005639}
5640
5641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005642StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005643TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005644 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005645}
Mike Stump1eb44332009-09-09 15:08:12 +00005646
Douglas Gregor43959a92009-08-20 07:17:43 +00005647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005648StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005649TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005650 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005651}
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregor43959a92009-08-20 07:17:43 +00005653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005656 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005657 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005658 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005659
Mike Stump1eb44332009-09-09 15:08:12 +00005660 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005661 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005662 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005663}
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregor43959a92009-08-20 07:17:43 +00005665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005666StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005668 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005669 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005670 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5671 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005672 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5673 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005674 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregor43959a92009-08-20 07:17:43 +00005677 if (Transformed != *D)
5678 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 Decls.push_back(Transformed);
5681 }
Mike Stump1eb44332009-09-09 15:08:12 +00005682
Douglas Gregor43959a92009-08-20 07:17:43 +00005683 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005684 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005686 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005687}
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor43959a92009-08-20 07:17:43 +00005689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005690StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005691TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005692
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005693 SmallVector<Expr*, 8> Constraints;
5694 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005695 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005696
John McCall60d7b3a2010-08-24 06:29:42 +00005697 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005698 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005699
5700 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005701
Anders Carlsson703e3942010-01-24 05:50:09 +00005702 // Go through the outputs.
5703 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005704 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005705
Anders Carlsson703e3942010-01-24 05:50:09 +00005706 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005707 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
Anders Carlsson703e3942010-01-24 05:50:09 +00005709 // Transform the output expr.
5710 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005711 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005712 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005713 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005714
Anders Carlsson703e3942010-01-24 05:50:09 +00005715 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
John McCall9ae2f072010-08-23 23:25:46 +00005717 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
Anders Carlsson703e3942010-01-24 05:50:09 +00005720 // Go through the inputs.
5721 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005722 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
Anders Carlsson703e3942010-01-24 05:50:09 +00005724 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005725 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
Anders Carlsson703e3942010-01-24 05:50:09 +00005727 // Transform the input expr.
5728 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005729 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005730 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005732
Anders Carlsson703e3942010-01-24 05:50:09 +00005733 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005734
John McCall9ae2f072010-08-23 23:25:46 +00005735 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005736 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005737
Anders Carlsson703e3942010-01-24 05:50:09 +00005738 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005739 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005740
5741 // Go through the clobbers.
5742 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005743 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005744
5745 // No need to transform the asm string literal.
5746 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005747 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5748 S->isVolatile(), S->getNumOutputs(),
5749 S->getNumInputs(), Names.data(),
5750 Constraints, Exprs, AsmString.get(),
5751 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005752}
5753
Chad Rosier8cd64b42012-06-11 20:47:18 +00005754template<typename Derived>
5755StmtResult
5756TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005757 ArrayRef<Token> AsmToks =
5758 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005759
John McCallaeeacf72013-05-03 00:10:13 +00005760 bool HadError = false, HadChange = false;
5761
5762 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5763 SmallVector<Expr*, 8> TransformedExprs;
5764 TransformedExprs.reserve(SrcExprs.size());
5765 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5766 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5767 if (!Result.isUsable()) {
5768 HadError = true;
5769 } else {
5770 HadChange |= (Result.get() != SrcExprs[i]);
5771 TransformedExprs.push_back(Result.take());
5772 }
5773 }
5774
5775 if (HadError) return StmtError();
5776 if (!HadChange && !getDerived().AlwaysRebuild())
5777 return Owned(S);
5778
Chad Rosier7bd092b2012-08-15 16:53:30 +00005779 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005780 AsmToks, S->getAsmString(),
5781 S->getNumOutputs(), S->getNumInputs(),
5782 S->getAllConstraints(), S->getClobbers(),
5783 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005784}
Douglas Gregor43959a92009-08-20 07:17:43 +00005785
5786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005787StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005788TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005789 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005791 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005793
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005794 // Transform the @catch statements (if present).
5795 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005796 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005797 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005799 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005801 if (Catch.get() != S->getCatchStmt(I))
5802 AnyCatchChanged = true;
5803 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005804 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005805
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005806 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005807 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005808 if (S->getFinallyStmt()) {
5809 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5810 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005811 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005812 }
5813
5814 // If nothing changed, just retain this statement.
5815 if (!getDerived().AlwaysRebuild() &&
5816 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005817 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005818 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005819 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005820
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005821 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005822 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005823 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005824}
Mike Stump1eb44332009-09-09 15:08:12 +00005825
Douglas Gregor43959a92009-08-20 07:17:43 +00005826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005827StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005828TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005829 // Transform the @catch parameter, if there is one.
5830 VarDecl *Var = 0;
5831 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5832 TypeSourceInfo *TSInfo = 0;
5833 if (FromVar->getTypeSourceInfo()) {
5834 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5835 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005836 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005837 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005838
Douglas Gregorbe270a02010-04-26 17:57:08 +00005839 QualType T;
5840 if (TSInfo)
5841 T = TSInfo->getType();
5842 else {
5843 T = getDerived().TransformType(FromVar->getType());
5844 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005845 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005847
Douglas Gregorbe270a02010-04-26 17:57:08 +00005848 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5849 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005850 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005852
John McCall60d7b3a2010-08-24 06:29:42 +00005853 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005854 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005855 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005856
5857 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005858 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005859 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005860}
Mike Stump1eb44332009-09-09 15:08:12 +00005861
Douglas Gregor43959a92009-08-20 07:17:43 +00005862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005863StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005864TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005865 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005866 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005867 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005868 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005870 // If nothing changed, just retain this statement.
5871 if (!getDerived().AlwaysRebuild() &&
5872 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005873 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005874
5875 // Build a new statement.
5876 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005877 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005878}
Mike Stump1eb44332009-09-09 15:08:12 +00005879
Douglas Gregor43959a92009-08-20 07:17:43 +00005880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005881StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005882TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005883 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005884 if (S->getThrowExpr()) {
5885 Operand = getDerived().TransformExpr(S->getThrowExpr());
5886 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005887 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005888 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005889
Douglas Gregord1377b22010-04-22 21:44:01 +00005890 if (!getDerived().AlwaysRebuild() &&
5891 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005892 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005893
John McCall9ae2f072010-08-23 23:25:46 +00005894 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005895}
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregor43959a92009-08-20 07:17:43 +00005897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005898StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005899TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005900 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005901 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005902 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005903 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005904 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005905 Object =
5906 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5907 Object.get());
5908 if (Object.isInvalid())
5909 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005910
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005911 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005912 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005913 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005914 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005915
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005916 // If nothing change, just retain the current statement.
5917 if (!getDerived().AlwaysRebuild() &&
5918 Object.get() == S->getSynchExpr() &&
5919 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005920 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005921
5922 // Build a new statement.
5923 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005924 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005925}
5926
5927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005928StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005929TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5930 ObjCAutoreleasePoolStmt *S) {
5931 // Transform the body.
5932 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5933 if (Body.isInvalid())
5934 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005935
John McCallf85e1932011-06-15 23:02:42 +00005936 // If nothing changed, just retain this statement.
5937 if (!getDerived().AlwaysRebuild() &&
5938 Body.get() == S->getSubStmt())
5939 return SemaRef.Owned(S);
5940
5941 // Build a new statement.
5942 return getDerived().RebuildObjCAutoreleasePoolStmt(
5943 S->getAtLoc(), Body.get());
5944}
5945
5946template<typename Derived>
5947StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005948TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005949 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005950 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005951 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005952 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005953 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005954
Douglas Gregorc3203e72010-04-22 23:10:45 +00005955 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005956 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005957 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005958 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005959
Douglas Gregorc3203e72010-04-22 23:10:45 +00005960 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005961 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005962 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005963 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005964
Douglas Gregorc3203e72010-04-22 23:10:45 +00005965 // If nothing changed, just retain this statement.
5966 if (!getDerived().AlwaysRebuild() &&
5967 Element.get() == S->getElement() &&
5968 Collection.get() == S->getCollection() &&
5969 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005970 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005971
Douglas Gregorc3203e72010-04-22 23:10:45 +00005972 // Build a new statement.
5973 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005974 Element.get(),
5975 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005976 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005977 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005978}
5979
5980
5981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005982StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005983TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5984 // Transform the exception declaration, if any.
5985 VarDecl *Var = 0;
5986 if (S->getExceptionDecl()) {
5987 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005988 TypeSourceInfo *T = getDerived().TransformType(
5989 ExceptionDecl->getTypeSourceInfo());
5990 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005991 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005992
Douglas Gregor83cb9422010-09-09 17:09:21 +00005993 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005994 ExceptionDecl->getInnerLocStart(),
5995 ExceptionDecl->getLocation(),
5996 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005997 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005998 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005999 }
Mike Stump1eb44332009-09-09 15:08:12 +00006000
Douglas Gregor43959a92009-08-20 07:17:43 +00006001 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006002 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006003 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006004 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006005
Douglas Gregor43959a92009-08-20 07:17:43 +00006006 if (!getDerived().AlwaysRebuild() &&
6007 !Var &&
6008 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006009 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006010
6011 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6012 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006013 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006014}
Mike Stump1eb44332009-09-09 15:08:12 +00006015
Douglas Gregor43959a92009-08-20 07:17:43 +00006016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006017StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006018TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6019 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006020 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006021 = getDerived().TransformCompoundStmt(S->getTryBlock());
6022 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006023 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006024
Douglas Gregor43959a92009-08-20 07:17:43 +00006025 // Transform the handlers.
6026 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006027 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006028 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006029 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006030 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6031 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006032 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Douglas Gregor43959a92009-08-20 07:17:43 +00006034 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6035 Handlers.push_back(Handler.takeAs<Stmt>());
6036 }
Mike Stump1eb44332009-09-09 15:08:12 +00006037
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 if (!getDerived().AlwaysRebuild() &&
6039 TryBlock.get() == S->getTryBlock() &&
6040 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006042
John McCall9ae2f072010-08-23 23:25:46 +00006043 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006044 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006045}
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Richard Smithad762fc2011-04-14 22:09:26 +00006047template<typename Derived>
6048StmtResult
6049TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6050 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6051 if (Range.isInvalid())
6052 return StmtError();
6053
6054 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6055 if (BeginEnd.isInvalid())
6056 return StmtError();
6057
6058 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6059 if (Cond.isInvalid())
6060 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006061 if (Cond.get())
6062 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6063 if (Cond.isInvalid())
6064 return StmtError();
6065 if (Cond.get())
6066 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006067
6068 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6069 if (Inc.isInvalid())
6070 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006071 if (Inc.get())
6072 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006073
6074 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6075 if (LoopVar.isInvalid())
6076 return StmtError();
6077
6078 StmtResult NewStmt = S;
6079 if (getDerived().AlwaysRebuild() ||
6080 Range.get() != S->getRangeStmt() ||
6081 BeginEnd.get() != S->getBeginEndStmt() ||
6082 Cond.get() != S->getCond() ||
6083 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006084 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006085 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6086 S->getColonLoc(), Range.get(),
6087 BeginEnd.get(), Cond.get(),
6088 Inc.get(), LoopVar.get(),
6089 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006090 if (NewStmt.isInvalid())
6091 return StmtError();
6092 }
Richard Smithad762fc2011-04-14 22:09:26 +00006093
6094 StmtResult Body = getDerived().TransformStmt(S->getBody());
6095 if (Body.isInvalid())
6096 return StmtError();
6097
6098 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6099 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006100 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006101 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6102 S->getColonLoc(), Range.get(),
6103 BeginEnd.get(), Cond.get(),
6104 Inc.get(), LoopVar.get(),
6105 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006106 if (NewStmt.isInvalid())
6107 return StmtError();
6108 }
Richard Smithad762fc2011-04-14 22:09:26 +00006109
6110 if (NewStmt.get() == S)
6111 return SemaRef.Owned(S);
6112
6113 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6114}
6115
John Wiegley28bbe4b2011-04-28 01:08:34 +00006116template<typename Derived>
6117StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006118TreeTransform<Derived>::TransformMSDependentExistsStmt(
6119 MSDependentExistsStmt *S) {
6120 // Transform the nested-name-specifier, if any.
6121 NestedNameSpecifierLoc QualifierLoc;
6122 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006123 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006124 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6125 if (!QualifierLoc)
6126 return StmtError();
6127 }
6128
6129 // Transform the declaration name.
6130 DeclarationNameInfo NameInfo = S->getNameInfo();
6131 if (NameInfo.getName()) {
6132 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6133 if (!NameInfo.getName())
6134 return StmtError();
6135 }
6136
6137 // Check whether anything changed.
6138 if (!getDerived().AlwaysRebuild() &&
6139 QualifierLoc == S->getQualifierLoc() &&
6140 NameInfo.getName() == S->getNameInfo().getName())
6141 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006142
Douglas Gregorba0513d2011-10-25 01:33:02 +00006143 // Determine whether this name exists, if we can.
6144 CXXScopeSpec SS;
6145 SS.Adopt(QualifierLoc);
6146 bool Dependent = false;
6147 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6148 case Sema::IER_Exists:
6149 if (S->isIfExists())
6150 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006151
Douglas Gregorba0513d2011-10-25 01:33:02 +00006152 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6153
6154 case Sema::IER_DoesNotExist:
6155 if (S->isIfNotExists())
6156 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006157
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 case Sema::IER_Dependent:
6161 Dependent = true;
6162 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006163
Douglas Gregor65019ac2011-10-25 03:44:56 +00006164 case Sema::IER_Error:
6165 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006166 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006167
Douglas Gregorba0513d2011-10-25 01:33:02 +00006168 // We need to continue with the instantiation, so do so now.
6169 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6170 if (SubStmt.isInvalid())
6171 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006172
Douglas Gregorba0513d2011-10-25 01:33:02 +00006173 // If we have resolved the name, just transform to the substatement.
6174 if (!Dependent)
6175 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006176
Douglas Gregorba0513d2011-10-25 01:33:02 +00006177 // The name is still dependent, so build a dependent expression again.
6178 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6179 S->isIfExists(),
6180 QualifierLoc,
6181 NameInfo,
6182 SubStmt.get());
6183}
6184
6185template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006186ExprResult
6187TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6188 NestedNameSpecifierLoc QualifierLoc;
6189 if (E->getQualifierLoc()) {
6190 QualifierLoc
6191 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6192 if (!QualifierLoc)
6193 return ExprError();
6194 }
6195
6196 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6197 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6198 if (!PD)
6199 return ExprError();
6200
6201 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6202 if (Base.isInvalid())
6203 return ExprError();
6204
6205 return new (SemaRef.getASTContext())
6206 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6207 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6208 QualifierLoc, E->getMemberLoc());
6209}
6210
6211template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006212StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006213TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6214 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6215 if(TryBlock.isInvalid()) return StmtError();
6216
6217 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6218 if(!getDerived().AlwaysRebuild() &&
6219 TryBlock.get() == S->getTryBlock() &&
6220 Handler.get() == S->getHandler())
6221 return SemaRef.Owned(S);
6222
6223 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6224 S->getTryLoc(),
6225 TryBlock.take(),
6226 Handler.take());
6227}
6228
6229template<typename Derived>
6230StmtResult
6231TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6232 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6233 if(Block.isInvalid()) return StmtError();
6234
6235 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6236 Block.take());
6237}
6238
6239template<typename Derived>
6240StmtResult
6241TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6242 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6243 if(FilterExpr.isInvalid()) return StmtError();
6244
6245 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6246 if(Block.isInvalid()) return StmtError();
6247
6248 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6249 FilterExpr.take(),
6250 Block.take());
6251}
6252
6253template<typename Derived>
6254StmtResult
6255TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6256 if(isa<SEHFinallyStmt>(Handler))
6257 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6258 else
6259 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6260}
6261
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006262template<typename Derived>
6263StmtResult
6264TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006265 DeclarationNameInfo DirName;
6266 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6267
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006268 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006269 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006270 ArrayRef<OMPClause *> Clauses = D->clauses();
6271 TClauses.reserve(Clauses.size());
6272 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6273 I != E; ++I) {
6274 if (*I) {
6275 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006276 if (!Clause) {
6277 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006278 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006279 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006280 TClauses.push_back(Clause);
6281 }
6282 else {
6283 TClauses.push_back(0);
6284 }
6285 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006286 if (!D->getAssociatedStmt()) {
6287 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006288 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006289 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006290 StmtResult AssociatedStmt =
6291 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006292 if (AssociatedStmt.isInvalid()) {
6293 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006294 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006295 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006296
Alexey Bataev0c018352013-09-06 18:03:48 +00006297 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6298 AssociatedStmt.take(),
6299 D->getLocStart(),
6300 D->getLocEnd());
6301 getSema().EndOpenMPDSABlock(Res.get());
6302 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006303}
6304
6305template<typename Derived>
6306OMPClause *
6307TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6308 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6309 C->getDefaultKindKwLoc(),
6310 C->getLocStart(),
6311 C->getLParenLoc(),
6312 C->getLocEnd());
6313}
6314
6315template<typename Derived>
6316OMPClause *
6317TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006318 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006319 Vars.reserve(C->varlist_size());
6320 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6321 E = C->varlist_end();
6322 I != E; ++I) {
6323 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6324 if (EVar.isInvalid())
6325 return 0;
6326 Vars.push_back(EVar.take());
6327 }
6328 return getDerived().RebuildOMPPrivateClause(Vars,
6329 C->getLocStart(),
6330 C->getLParenLoc(),
6331 C->getLocEnd());
6332}
6333
Alexey Bataev0c018352013-09-06 18:03:48 +00006334template<typename Derived>
6335OMPClause *
6336TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6337 llvm::SmallVector<Expr *, 16> Vars;
6338 Vars.reserve(C->varlist_size());
6339 for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),
6340 E = C->varlist_end();
6341 I != E; ++I) {
6342 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6343 if (EVar.isInvalid())
6344 return 0;
6345 Vars.push_back(EVar.take());
6346 }
6347 return getDerived().RebuildOMPSharedClause(Vars,
6348 C->getLocStart(),
6349 C->getLParenLoc(),
6350 C->getLocEnd());
6351}
6352
Douglas Gregor43959a92009-08-20 07:17:43 +00006353//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354// Expression transformation
6355//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006357ExprResult
John McCall454feb92009-12-08 09:21:05 +00006358TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360}
Mike Stump1eb44332009-09-09 15:08:12 +00006361
6362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006363ExprResult
John McCall454feb92009-12-08 09:21:05 +00006364TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006365 NestedNameSpecifierLoc QualifierLoc;
6366 if (E->getQualifierLoc()) {
6367 QualifierLoc
6368 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6369 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006371 }
John McCalldbd872f2009-12-08 09:08:17 +00006372
6373 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006374 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6375 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006378
John McCallec8045d2010-08-17 21:27:17 +00006379 DeclarationNameInfo NameInfo = E->getNameInfo();
6380 if (NameInfo.getName()) {
6381 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6382 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006384 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006385
6386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006387 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006388 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006389 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006390 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006391
6392 // Mark it referenced in the new context regardless.
6393 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006394 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006395
John McCall3fa5cae2010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006397 }
John McCalldbd872f2009-12-08 09:08:17 +00006398
6399 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006400 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006401 TemplateArgs = &TransArgs;
6402 TransArgs.setLAngleLoc(E->getLAngleLoc());
6403 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006404 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6405 E->getNumTemplateArgs(),
6406 TransArgs))
6407 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006408 }
6409
Chad Rosier4a9d7952012-08-08 18:46:20 +00006410 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006411 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412}
Mike Stump1eb44332009-09-09 15:08:12 +00006413
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006415ExprResult
John McCall454feb92009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006417 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418}
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006421ExprResult
John McCall454feb92009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006423 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424}
Mike Stump1eb44332009-09-09 15:08:12 +00006425
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006427ExprResult
John McCall454feb92009-12-08 09:21:05 +00006428TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006429 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430}
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006433ExprResult
John McCall454feb92009-12-08 09:21:05 +00006434TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006435 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006439ExprResult
John McCall454feb92009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006441 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006442}
6443
6444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006445ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006446TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006447 if (FunctionDecl *FD = E->getDirectCallee())
6448 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006449 return SemaRef.MaybeBindToTemporary(E);
6450}
6451
6452template<typename Derived>
6453ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006454TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6455 ExprResult ControllingExpr =
6456 getDerived().TransformExpr(E->getControllingExpr());
6457 if (ControllingExpr.isInvalid())
6458 return ExprError();
6459
Chris Lattner686775d2011-07-20 06:58:45 +00006460 SmallVector<Expr *, 4> AssocExprs;
6461 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006462 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6463 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6464 if (TS) {
6465 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6466 if (!AssocType)
6467 return ExprError();
6468 AssocTypes.push_back(AssocType);
6469 } else {
6470 AssocTypes.push_back(0);
6471 }
6472
6473 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6474 if (AssocExpr.isInvalid())
6475 return ExprError();
6476 AssocExprs.push_back(AssocExpr.release());
6477 }
6478
6479 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6480 E->getDefaultLoc(),
6481 E->getRParenLoc(),
6482 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006483 AssocTypes,
6484 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006485}
6486
6487template<typename Derived>
6488ExprResult
John McCall454feb92009-12-08 09:21:05 +00006489TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006490 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006496
John McCall9ae2f072010-08-23 23:25:46 +00006497 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 E->getRParen());
6499}
6500
Richard Smithefeeccf2012-10-21 03:28:35 +00006501/// \brief The operand of a unary address-of operator has special rules: it's
6502/// allowed to refer to a non-static member of a class even if there's no 'this'
6503/// object available.
6504template<typename Derived>
6505ExprResult
6506TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6507 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6508 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6509 else
6510 return getDerived().TransformExpr(E);
6511}
6512
Mike Stump1eb44332009-09-09 15:08:12 +00006513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006514ExprResult
John McCall454feb92009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006516 ExprResult SubExpr;
6517 if (E->getOpcode() == UO_AddrOf)
6518 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6519 else
6520 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006525 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6528 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006529 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530}
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006533ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006534TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6535 // Transform the type.
6536 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6537 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006538 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006539
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006540 // Transform all of the components into components similar to what the
6541 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006542 // FIXME: It would be slightly more efficient in the non-dependent case to
6543 // just map FieldDecls, rather than requiring the rebuilder to look for
6544 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006545 // template code that we don't care.
6546 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006547 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006548 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006549 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006550 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6551 const Node &ON = E->getComponent(I);
6552 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006553 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006554 Comp.LocStart = ON.getSourceRange().getBegin();
6555 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006556 switch (ON.getKind()) {
6557 case Node::Array: {
6558 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006559 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006560 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006561 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006562
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006563 ExprChanged = ExprChanged || Index.get() != FromIndex;
6564 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006565 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006566 break;
6567 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006568
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006569 case Node::Field:
6570 case Node::Identifier:
6571 Comp.isBrackets = false;
6572 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006573 if (!Comp.U.IdentInfo)
6574 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006575
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006576 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006577
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006578 case Node::Base:
6579 // Will be recomputed during the rebuild.
6580 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006581 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006582
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006583 Components.push_back(Comp);
6584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006585
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006586 // If nothing changed, retain the existing expression.
6587 if (!getDerived().AlwaysRebuild() &&
6588 Type == E->getTypeSourceInfo() &&
6589 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006591
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006592 // Build a new offsetof expression.
6593 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6594 Components.data(), Components.size(),
6595 E->getRParenLoc());
6596}
6597
6598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006600TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6601 assert(getDerived().AlreadyTransformed(E->getType()) &&
6602 "opaque value expression requires transformation");
6603 return SemaRef.Owned(E);
6604}
6605
6606template<typename Derived>
6607ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006608TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006609 // Rebuild the syntactic form. The original syntactic form has
6610 // opaque-value expressions in it, so strip those away and rebuild
6611 // the result. This is a really awful way of doing this, but the
6612 // better solution (rebuilding the semantic expressions and
6613 // rebinding OVEs as necessary) doesn't work; we'd need
6614 // TreeTransform to not strip away implicit conversions.
6615 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6616 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006617 if (result.isInvalid()) return ExprError();
6618
6619 // If that gives us a pseudo-object result back, the pseudo-object
6620 // expression must have been an lvalue-to-rvalue conversion which we
6621 // should reapply.
6622 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6623 result = SemaRef.checkPseudoObjectRValue(result.take());
6624
6625 return result;
6626}
6627
6628template<typename Derived>
6629ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006630TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6631 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006633 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006634
John McCalla93c9342009-12-07 02:54:59 +00006635 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006636 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
John McCall5ab75172009-11-04 07:28:41 +00006639 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006642 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6643 E->getKind(),
6644 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 }
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006647 // C++0x [expr.sizeof]p1:
6648 // The operand is either an expression, which is an unevaluated operand
6649 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006650 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6651 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006653 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6654 if (SubExpr.isInvalid())
6655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006656
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006657 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6658 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006660 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6661 E->getOperatorLoc(),
6662 E->getKind(),
6663 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664}
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006667ExprResult
John McCall454feb92009-12-08 09:21:05 +00006668TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006669 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006672
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
6677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (!getDerived().AlwaysRebuild() &&
6679 LHS.get() == E->getLHS() &&
6680 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006682
John McCall9ae2f072010-08-23 23:25:46 +00006683 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006685 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 E->getRBracketLoc());
6687}
Mike Stump1eb44332009-09-09 15:08:12 +00006688
6689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006690ExprResult
John McCall454feb92009-12-08 09:21:05 +00006691TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696
6697 // Transform arguments.
6698 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006699 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006700 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006701 &ArgChanged))
6702 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (!getDerived().AlwaysRebuild() &&
6705 Callee.get() == E->getCallee() &&
6706 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006707 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006710 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006712 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006713 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 E->getRParenLoc());
6715}
Mike Stump1eb44332009-09-09 15:08:12 +00006716
6717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006718ExprResult
John McCall454feb92009-12-08 09:21:05 +00006719TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006720 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006723
Douglas Gregor40d96a62011-02-28 21:54:11 +00006724 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006725 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006726 QualifierLoc
6727 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006728
Douglas Gregor40d96a62011-02-28 21:54:11 +00006729 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006731 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006732 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Eli Friedmanf595cc42009-12-04 06:40:45 +00006734 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006735 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6736 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006739
John McCall6bb80172010-03-30 21:47:33 +00006740 NamedDecl *FoundDecl = E->getFoundDecl();
6741 if (FoundDecl == E->getMemberDecl()) {
6742 FoundDecl = Member;
6743 } else {
6744 FoundDecl = cast_or_null<NamedDecl>(
6745 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6746 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006747 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006748 }
6749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
6751 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006752 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006753 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006754 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006755 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006756
Anders Carlsson1f240322009-12-22 05:24:09 +00006757 // Mark it referenced in the new context regardless.
6758 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006759 SemaRef.MarkMemberReferenced(E);
6760
John McCall3fa5cae2010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006762 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763
John McCalld5532b62009-11-23 01:53:49 +00006764 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006765 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006766 TransArgs.setLAngleLoc(E->getLAngleLoc());
6767 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006768 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6769 E->getNumTemplateArgs(),
6770 TransArgs))
6771 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006772 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 // FIXME: Bogus source location for the operator
6775 SourceLocation FakeOperatorLoc
6776 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6777
John McCallc2233c52010-01-15 08:34:02 +00006778 // FIXME: to do this check properly, we will need to preserve the
6779 // first-qualifier-in-scope here, just in case we had a dependent
6780 // base (and therefore couldn't do the check) and a
6781 // nested-name-qualifier (and therefore could do the lookup).
6782 NamedDecl *FirstQualifierInScope = 0;
6783
John McCall9ae2f072010-08-23 23:25:46 +00006784 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006786 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006787 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006788 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006789 Member,
John McCall6bb80172010-03-30 21:47:33 +00006790 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006791 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006792 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006793 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794}
Mike Stump1eb44332009-09-09 15:08:12 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006797ExprResult
John McCall454feb92009-12-08 09:21:05 +00006798TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006799 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006802
John McCall60d7b3a2010-08-24 06:29:42 +00006803 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 if (!getDerived().AlwaysRebuild() &&
6808 LHS.get() == E->getLHS() &&
6809 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006810 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006811
Lang Hamesbe9af122012-10-02 04:45:10 +00006812 Sema::FPContractStateRAII FPContractState(getSema());
6813 getSema().FPFeatures.fp_contract = E->isFPContractable();
6814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006816 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817}
6818
Mike Stump1eb44332009-09-09 15:08:12 +00006819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006820ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006822 CompoundAssignOperator *E) {
6823 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824}
Mike Stump1eb44332009-09-09 15:08:12 +00006825
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006827ExprResult TreeTransform<Derived>::
6828TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6829 // Just rebuild the common and RHS expressions and see whether we
6830 // get any changes.
6831
6832 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6833 if (commonExpr.isInvalid())
6834 return ExprError();
6835
6836 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6837 if (rhs.isInvalid())
6838 return ExprError();
6839
6840 if (!getDerived().AlwaysRebuild() &&
6841 commonExpr.get() == e->getCommon() &&
6842 rhs.get() == e->getFalseExpr())
6843 return SemaRef.Owned(e);
6844
6845 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6846 e->getQuestionLoc(),
6847 0,
6848 e->getColonLoc(),
6849 rhs.get());
6850}
6851
6852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006853ExprResult
John McCall454feb92009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006855 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006858
John McCall60d7b3a2010-08-24 06:29:42 +00006859 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
John McCall60d7b3a2010-08-24 06:29:42 +00006863 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 Cond.get() == E->getCond() &&
6869 LHS.get() == E->getLHS() &&
6870 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006872
John McCall9ae2f072010-08-23 23:25:46 +00006873 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006874 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006875 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006876 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006877 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878}
Mike Stump1eb44332009-09-09 15:08:12 +00006879
6880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006881ExprResult
John McCall454feb92009-12-08 09:21:05 +00006882TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006883 // Implicit casts are eliminated during transformation, since they
6884 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006885 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886}
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006889ExprResult
John McCall454feb92009-12-08 09:21:05 +00006890TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006891 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6892 if (!Type)
6893 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006894
John McCall60d7b3a2010-08-24 06:29:42 +00006895 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006896 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006898 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006901 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006903 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006904
John McCall9d125032010-01-15 18:39:57 +00006905 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006906 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006908 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909}
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006912ExprResult
John McCall454feb92009-12-08 09:21:05 +00006913TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006914 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6915 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6916 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006918
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006921 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006924 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006926 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927
John McCall1d7d8d62010-01-19 22:33:45 +00006928 // Note: the expression type doesn't necessarily match the
6929 // type-as-written, but that's okay, because it should always be
6930 // derivable from the initializer.
6931
John McCall42f56b52010-01-18 19:35:47 +00006932 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006934 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935}
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006938ExprResult
John McCall454feb92009-12-08 09:21:05 +00006939TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006940 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006942 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (!getDerived().AlwaysRebuild() &&
6945 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006946 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006947
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006949 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006951 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 E->getAccessorLoc(),
6953 E->getAccessor());
6954}
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006957ExprResult
John McCall454feb92009-12-08 09:21:05 +00006958TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006961 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006962 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006963 Inits, &InitChanged))
6964 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006967 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006969 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006970 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971}
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006974ExprResult
John McCall454feb92009-12-08 09:21:05 +00006975TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006977
Douglas Gregor43959a92009-08-20 07:17:43 +00006978 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006979 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregor43959a92009-08-20 07:17:43 +00006983 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006984 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 bool ExprChanged = false;
6986 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6987 DEnd = E->designators_end();
6988 D != DEnd; ++D) {
6989 if (D->isFieldDesignator()) {
6990 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6991 D->getDotLoc(),
6992 D->getFieldLoc()));
6993 continue;
6994 }
Mike Stump1eb44332009-09-09 15:08:12 +00006995
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006997 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007000
7001 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7005 ArrayExprs.push_back(Index.release());
7006 continue;
7007 }
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007010 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7012 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007014
John McCall60d7b3a2010-08-24 06:29:42 +00007015 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007017 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007018
7019 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 End.get(),
7021 D->getLBracketLoc(),
7022 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7025 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 ArrayExprs.push_back(Start.release());
7028 ArrayExprs.push_back(End.release());
7029 }
Mike Stump1eb44332009-09-09 15:08:12 +00007030
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 if (!getDerived().AlwaysRebuild() &&
7032 Init.get() == E->getInit() &&
7033 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007034 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007036 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007038 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039}
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007044 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007045 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007046
Douglas Gregor5557b252009-10-28 00:29:27 +00007047 // FIXME: Will we ever have proper type location here? Will we actually
7048 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 QualType T = getDerived().TransformType(E->getType());
7050 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007051 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 if (!getDerived().AlwaysRebuild() &&
7054 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007055 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 return getDerived().RebuildImplicitValueInitExpr(T);
7058}
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007061ExprResult
John McCall454feb92009-12-08 09:21:05 +00007062TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007063 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7064 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007065 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007066
John McCall60d7b3a2010-08-24 06:29:42 +00007067 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007072 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007075
John McCall9ae2f072010-08-23 23:25:46 +00007076 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007077 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078}
7079
7080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007081ExprResult
John McCall454feb92009-12-08 09:21:05 +00007082TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007084 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007085 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7086 &ArgumentChanged))
7087 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007088
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007090 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 E->getRParenLoc());
7092}
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094/// \brief Transform an address-of-label expression.
7095///
7096/// By default, the transformation of an address-of-label expression always
7097/// rebuilds the expression, so that the label identifier can be resolved to
7098/// the corresponding label statement by semantic analysis.
7099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007100ExprResult
John McCall454feb92009-12-08 09:21:05 +00007101TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007102 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7103 E->getLabel());
7104 if (!LD)
7105 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007106
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007108 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109}
Mike Stump1eb44332009-09-09 15:08:12 +00007110
7111template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007112ExprResult
John McCall454feb92009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007114 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007115 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007116 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007117 if (SubStmt.isInvalid()) {
7118 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007119 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007120 }
Mike Stump1eb44332009-09-09 15:08:12 +00007121
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007123 SubStmt.get() == E->getSubStmt()) {
7124 // Calling this an 'error' is unintuitive, but it does the right thing.
7125 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007126 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007127 }
Mike Stump1eb44332009-09-09 15:08:12 +00007128
7129 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007130 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 E->getRParenLoc());
7132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
John McCall454feb92009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007137 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007139 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007140
John McCall60d7b3a2010-08-24 06:29:42 +00007141 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007144
John McCall60d7b3a2010-08-24 06:29:42 +00007145 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 if (!getDerived().AlwaysRebuild() &&
7150 Cond.get() == E->getCond() &&
7151 LHS.get() == E->getLHS() &&
7152 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007153 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007156 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 E->getRParenLoc());
7158}
Mike Stump1eb44332009-09-09 15:08:12 +00007159
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007161ExprResult
John McCall454feb92009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164}
7165
7166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007167ExprResult
John McCall454feb92009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007169 switch (E->getOperator()) {
7170 case OO_New:
7171 case OO_Delete:
7172 case OO_Array_New:
7173 case OO_Array_Delete:
7174 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007175
Douglas Gregor668d6d92009-12-13 20:44:55 +00007176 case OO_Call: {
7177 // This is a call to an object's operator().
7178 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7179
7180 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007181 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007182 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007183 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007184
7185 // FIXME: Poor location information
7186 SourceLocation FakeLParenLoc
7187 = SemaRef.PP.getLocForEndOfToken(
7188 static_cast<Expr *>(Object.get())->getLocEnd());
7189
7190 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007191 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007192 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007193 Args))
7194 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007195
John McCall9ae2f072010-08-23 23:25:46 +00007196 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007197 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007198 E->getLocEnd());
7199 }
7200
7201#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7202 case OO_##Name:
7203#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7204#include "clang/Basic/OperatorKinds.def"
7205 case OO_Subscript:
7206 // Handled below.
7207 break;
7208
7209 case OO_Conditional:
7210 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007211
7212 case OO_None:
7213 case NUM_OVERLOADED_OPERATORS:
7214 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007215 }
7216
John McCall60d7b3a2010-08-24 06:29:42 +00007217 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Richard Smithefeeccf2012-10-21 03:28:35 +00007221 ExprResult First;
7222 if (E->getOperator() == OO_Amp)
7223 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7224 else
7225 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007226 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007227 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007228
John McCall60d7b3a2010-08-24 06:29:42 +00007229 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007230 if (E->getNumArgs() == 2) {
7231 Second = getDerived().TransformExpr(E->getArg(1));
7232 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007233 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234 }
Mike Stump1eb44332009-09-09 15:08:12 +00007235
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236 if (!getDerived().AlwaysRebuild() &&
7237 Callee.get() == E->getCallee() &&
7238 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007239 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007240 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007241
Lang Hamesbe9af122012-10-02 04:45:10 +00007242 Sema::FPContractStateRAII FPContractState(getSema());
7243 getSema().FPFeatures.fp_contract = E->isFPContractable();
7244
Douglas Gregorb98b1992009-08-11 05:31:07 +00007245 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7246 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007247 Callee.get(),
7248 First.get(),
7249 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250}
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007253ExprResult
John McCall454feb92009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7255 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256}
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007259ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007260TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7261 // Transform the callee.
7262 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7263 if (Callee.isInvalid())
7264 return ExprError();
7265
7266 // Transform exec config.
7267 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7268 if (EC.isInvalid())
7269 return ExprError();
7270
7271 // Transform arguments.
7272 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007273 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007274 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007275 &ArgChanged))
7276 return ExprError();
7277
7278 if (!getDerived().AlwaysRebuild() &&
7279 Callee.get() == E->getCallee() &&
7280 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007281 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007282
7283 // FIXME: Wrong source location information for the '('.
7284 SourceLocation FakeLParenLoc
7285 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7286 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007287 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007288 E->getRParenLoc(), EC.get());
7289}
7290
7291template<typename Derived>
7292ExprResult
John McCall454feb92009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007294 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7295 if (!Type)
7296 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007297
John McCall60d7b3a2010-08-24 06:29:42 +00007298 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007299 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007301 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007302
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007304 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007306 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007308 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007309 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007310 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007311 E->getAngleBrackets().getEnd(),
7312 // FIXME. this should be '(' location
7313 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007314 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007315 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316}
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007319ExprResult
John McCall454feb92009-12-08 09:21:05 +00007320TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7321 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322}
Mike Stump1eb44332009-09-09 15:08:12 +00007323
7324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007325ExprResult
John McCall454feb92009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7327 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007328}
7329
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007331ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007333 CXXReinterpretCastExpr *E) {
7334 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335}
Mike Stump1eb44332009-09-09 15:08:12 +00007336
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007338ExprResult
John McCall454feb92009-12-08 09:21:05 +00007339TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7340 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341}
Mike Stump1eb44332009-09-09 15:08:12 +00007342
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007344ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007346 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007347 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7348 if (!Type)
7349 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007350
John McCall60d7b3a2010-08-24 06:29:42 +00007351 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007352 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007357 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007360
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007361 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007362 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007363 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 E->getRParenLoc());
7365}
Mike Stump1eb44332009-09-09 15:08:12 +00007366
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007368ExprResult
John McCall454feb92009-12-08 09:21:05 +00007369TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007371 TypeSourceInfo *TInfo
7372 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7373 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007377 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007378 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007379
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007380 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7381 E->getLocStart(),
7382 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007383 E->getLocEnd());
7384 }
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Eli Friedmanef331b72012-01-20 01:26:23 +00007386 // We don't know whether the subexpression is potentially evaluated until
7387 // after we perform semantic analysis. We speculatively assume it is
7388 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007389 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007390 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7391 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007392
John McCall60d7b3a2010-08-24 06:29:42 +00007393 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 if (!getDerived().AlwaysRebuild() &&
7398 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007399 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007400
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007401 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7402 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007403 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404 E->getLocEnd());
7405}
7406
7407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007408ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007409TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7410 if (E->isTypeOperand()) {
7411 TypeSourceInfo *TInfo
7412 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7413 if (!TInfo)
7414 return ExprError();
7415
7416 if (!getDerived().AlwaysRebuild() &&
7417 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007418 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007419
Douglas Gregor3c52a212011-03-06 17:40:41 +00007420 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007421 E->getLocStart(),
7422 TInfo,
7423 E->getLocEnd());
7424 }
7425
Francois Pichet01b7c302010-09-08 12:20:18 +00007426 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7427
7428 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7429 if (SubExpr.isInvalid())
7430 return ExprError();
7431
7432 if (!getDerived().AlwaysRebuild() &&
7433 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007434 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007435
7436 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7437 E->getLocStart(),
7438 SubExpr.get(),
7439 E->getLocEnd());
7440}
7441
7442template<typename Derived>
7443ExprResult
John McCall454feb92009-12-08 09:21:05 +00007444TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007445 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446}
Mike Stump1eb44332009-09-09 15:08:12 +00007447
Douglas Gregorb98b1992009-08-11 05:31:07 +00007448template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007449ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007450TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007451 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007452 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453}
Mike Stump1eb44332009-09-09 15:08:12 +00007454
Douglas Gregorb98b1992009-08-11 05:31:07 +00007455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007456ExprResult
John McCall454feb92009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007458 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007459
Douglas Gregorec79d872012-02-24 17:41:38 +00007460 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7461 // Make sure that we capture 'this'.
7462 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007463 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007464 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007465
Douglas Gregor828a1972010-01-07 23:12:05 +00007466 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467}
Mike Stump1eb44332009-09-09 15:08:12 +00007468
Douglas Gregorb98b1992009-08-11 05:31:07 +00007469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007470ExprResult
John McCall454feb92009-12-08 09:21:05 +00007471TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007472 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007473 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476 if (!getDerived().AlwaysRebuild() &&
7477 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007478 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479
Douglas Gregorbca01b42011-07-06 22:04:06 +00007480 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7481 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007482}
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorb98b1992009-08-11 05:31:07 +00007484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007485ExprResult
John McCall454feb92009-12-08 09:21:05 +00007486TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007487 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007488 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7489 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007491 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007492
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007496
Douglas Gregor036aed12009-12-23 23:03:06 +00007497 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498}
Mike Stump1eb44332009-09-09 15:08:12 +00007499
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007501ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007502TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7503 FieldDecl *Field
7504 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7505 E->getField()));
7506 if (!Field)
7507 return ExprError();
7508
7509 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7510 return SemaRef.Owned(E);
7511
7512 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7513}
7514
7515template<typename Derived>
7516ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007517TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7518 CXXScalarValueInitExpr *E) {
7519 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7520 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007521 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007522
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007524 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007525 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007526
Chad Rosier4a9d7952012-08-08 18:46:20 +00007527 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007528 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007529 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530}
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Douglas Gregorb98b1992009-08-11 05:31:07 +00007532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007533ExprResult
John McCall454feb92009-12-08 09:21:05 +00007534TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007536 TypeSourceInfo *AllocTypeInfo
7537 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7538 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007540
Douglas Gregorb98b1992009-08-11 05:31:07 +00007541 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007542 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007545
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546 // Transform the placement arguments (if any).
7547 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007548 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007549 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007550 E->getNumPlacementArgs(), true,
7551 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007553
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007554 // Transform the initializer (if any).
7555 Expr *OldInit = E->getInitializer();
7556 ExprResult NewInit;
7557 if (OldInit)
7558 NewInit = getDerived().TransformExpr(OldInit);
7559 if (NewInit.isInvalid())
7560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007561
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007562 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007563 FunctionDecl *OperatorNew = 0;
7564 if (E->getOperatorNew()) {
7565 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007566 getDerived().TransformDecl(E->getLocStart(),
7567 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007568 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007569 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007570 }
7571
7572 FunctionDecl *OperatorDelete = 0;
7573 if (E->getOperatorDelete()) {
7574 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007575 getDerived().TransformDecl(E->getLocStart(),
7576 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007577 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007578 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007580
Douglas Gregorb98b1992009-08-11 05:31:07 +00007581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007582 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007584 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007585 OperatorNew == E->getOperatorNew() &&
7586 OperatorDelete == E->getOperatorDelete() &&
7587 !ArgumentChanged) {
7588 // Mark any declarations we need as referenced.
7589 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007590 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007591 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007592 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007593 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007594
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007595 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007596 QualType ElementType
7597 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7598 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7599 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7600 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007601 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007602 }
7603 }
7604 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007605
John McCall3fa5cae2010-10-26 07:05:15 +00007606 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007607 }
Mike Stump1eb44332009-09-09 15:08:12 +00007608
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007609 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007610 if (!ArraySize.get()) {
7611 // If no array size was specified, but the new expression was
7612 // instantiated with an array type (e.g., "new T" where T is
7613 // instantiated with "int[4]"), extract the outer bound from the
7614 // array type as our array size. We do this with constant and
7615 // dependently-sized array types.
7616 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7617 if (!ArrayT) {
7618 // Do nothing
7619 } else if (const ConstantArrayType *ConsArrayT
7620 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007621 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007622 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007624 SemaRef.Context.getSizeType(),
7625 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007626 AllocType = ConsArrayT->getElementType();
7627 } else if (const DependentSizedArrayType *DepArrayT
7628 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7629 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007630 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007631 AllocType = DepArrayT->getElementType();
7632 }
7633 }
7634 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007635
Douglas Gregorb98b1992009-08-11 05:31:07 +00007636 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7637 E->isGlobalNew(),
7638 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007639 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007640 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007641 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007642 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007643 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007644 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007645 E->getDirectInitRange(),
7646 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007647}
Mike Stump1eb44332009-09-09 15:08:12 +00007648
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007650ExprResult
John McCall454feb92009-12-08 09:21:05 +00007651TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007652 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007653 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007655
Douglas Gregor1af74512010-02-26 00:38:10 +00007656 // Transform the delete operator, if known.
7657 FunctionDecl *OperatorDelete = 0;
7658 if (E->getOperatorDelete()) {
7659 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007660 getDerived().TransformDecl(E->getLocStart(),
7661 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007662 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007663 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007665
Douglas Gregorb98b1992009-08-11 05:31:07 +00007666 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007667 Operand.get() == E->getArgument() &&
7668 OperatorDelete == E->getOperatorDelete()) {
7669 // Mark any declarations we need as referenced.
7670 // FIXME: instantiation-specific.
7671 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007672 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007673
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007674 if (!E->getArgument()->isTypeDependent()) {
7675 QualType Destroyed = SemaRef.Context.getBaseElementType(
7676 E->getDestroyedType());
7677 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7678 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007679 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007680 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007681 }
7682 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007683
John McCall3fa5cae2010-10-26 07:05:15 +00007684 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007685 }
Mike Stump1eb44332009-09-09 15:08:12 +00007686
Douglas Gregorb98b1992009-08-11 05:31:07 +00007687 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7688 E->isGlobalDelete(),
7689 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007690 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007691}
Mike Stump1eb44332009-09-09 15:08:12 +00007692
Douglas Gregorb98b1992009-08-11 05:31:07 +00007693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007694ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007695TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007696 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007697 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007698 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007700
John McCallb3d87482010-08-24 05:47:05 +00007701 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007702 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007703 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007704 E->getOperatorLoc(),
7705 E->isArrow()? tok::arrow : tok::period,
7706 ObjectTypePtr,
7707 MayBePseudoDestructor);
7708 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007709 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007710
John McCallb3d87482010-08-24 05:47:05 +00007711 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007712 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7713 if (QualifierLoc) {
7714 QualifierLoc
7715 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7716 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007717 return ExprError();
7718 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007719 CXXScopeSpec SS;
7720 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007721
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007722 PseudoDestructorTypeStorage Destroyed;
7723 if (E->getDestroyedTypeInfo()) {
7724 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007725 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007726 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007727 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007728 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007729 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007730 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007731 // We aren't likely to be able to resolve the identifier down to a type
7732 // now anyway, so just retain the identifier.
7733 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7734 E->getDestroyedTypeLoc());
7735 } else {
7736 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007737 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007738 *E->getDestroyedTypeIdentifier(),
7739 E->getDestroyedTypeLoc(),
7740 /*Scope=*/0,
7741 SS, ObjectTypePtr,
7742 false);
7743 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007744 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007745
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007746 Destroyed
7747 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7748 E->getDestroyedTypeLoc());
7749 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007750
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007751 TypeSourceInfo *ScopeTypeInfo = 0;
7752 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007753 CXXScopeSpec EmptySS;
7754 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7755 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007756 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007757 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007759
John McCall9ae2f072010-08-23 23:25:46 +00007760 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007761 E->getOperatorLoc(),
7762 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007763 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007764 ScopeTypeInfo,
7765 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007766 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007767 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007768}
Mike Stump1eb44332009-09-09 15:08:12 +00007769
Douglas Gregora71d8192009-09-04 17:36:40 +00007770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007771ExprResult
John McCallba135432009-11-21 08:51:07 +00007772TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007773 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007774 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7775 Sema::LookupOrdinaryName);
7776
7777 // Transform all the decls.
7778 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7779 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007780 NamedDecl *InstD = static_cast<NamedDecl*>(
7781 getDerived().TransformDecl(Old->getNameLoc(),
7782 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007783 if (!InstD) {
7784 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7785 // This can happen because of dependent hiding.
7786 if (isa<UsingShadowDecl>(*I))
7787 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007788 else {
7789 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007790 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007791 }
John McCall9f54ad42009-12-10 09:41:52 +00007792 }
John McCallf7a1a742009-11-24 19:00:30 +00007793
7794 // Expand using declarations.
7795 if (isa<UsingDecl>(InstD)) {
7796 UsingDecl *UD = cast<UsingDecl>(InstD);
7797 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7798 E = UD->shadow_end(); I != E; ++I)
7799 R.addDecl(*I);
7800 continue;
7801 }
7802
7803 R.addDecl(InstD);
7804 }
7805
7806 // Resolve a kind, but don't do any further analysis. If it's
7807 // ambiguous, the callee needs to deal with it.
7808 R.resolveKind();
7809
7810 // Rebuild the nested-name qualifier, if present.
7811 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007812 if (Old->getQualifierLoc()) {
7813 NestedNameSpecifierLoc QualifierLoc
7814 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7815 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007816 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007817
Douglas Gregor4c9be892011-02-28 20:01:57 +00007818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007819 }
7820
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007821 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007822 CXXRecordDecl *NamingClass
7823 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7824 Old->getNameLoc(),
7825 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007826 if (!NamingClass) {
7827 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007828 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007830
Douglas Gregor66c45152010-04-27 16:10:10 +00007831 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007832 }
7833
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007834 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7835
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007836 // If we have neither explicit template arguments, nor the template keyword,
7837 // it's a normal declaration name.
7838 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007839 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7840
7841 // If we have template arguments, rebuild them, then rebuild the
7842 // templateid expression.
7843 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007844 if (Old->hasExplicitTemplateArgs() &&
7845 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007846 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007847 TransArgs)) {
7848 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007849 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007850 }
John McCallf7a1a742009-11-24 19:00:30 +00007851
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007852 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007853 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854}
Mike Stump1eb44332009-09-09 15:08:12 +00007855
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007857ExprResult
John McCall454feb92009-12-08 09:21:05 +00007858TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007859 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7860 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007862
Douglas Gregorb98b1992009-08-11 05:31:07 +00007863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007864 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007865 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007866
Mike Stump1eb44332009-09-09 15:08:12 +00007867 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007869 T,
7870 E->getLocEnd());
7871}
Mike Stump1eb44332009-09-09 15:08:12 +00007872
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007874ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007875TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7876 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7877 if (!LhsT)
7878 return ExprError();
7879
7880 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7881 if (!RhsT)
7882 return ExprError();
7883
7884 if (!getDerived().AlwaysRebuild() &&
7885 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7886 return SemaRef.Owned(E);
7887
7888 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7889 E->getLocStart(),
7890 LhsT, RhsT,
7891 E->getLocEnd());
7892}
7893
7894template<typename Derived>
7895ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007896TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7897 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007898 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007899 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7900 TypeSourceInfo *From = E->getArg(I);
7901 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007902 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007903 TypeLocBuilder TLB;
7904 TLB.reserve(FromTL.getFullDataSize());
7905 QualType To = getDerived().TransformType(TLB, FromTL);
7906 if (To.isNull())
7907 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007908
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007909 if (To == From->getType())
7910 Args.push_back(From);
7911 else {
7912 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7913 ArgChanged = true;
7914 }
7915 continue;
7916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007917
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007918 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007919
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007920 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007921 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007922 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7923 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7924 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007925
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007926 // Determine whether the set of unexpanded parameter packs can and should
7927 // be expanded.
7928 bool Expand = true;
7929 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007930 Optional<unsigned> OrigNumExpansions =
7931 ExpansionTL.getTypePtr()->getNumExpansions();
7932 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007933 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7934 PatternTL.getSourceRange(),
7935 Unexpanded,
7936 Expand, RetainExpansion,
7937 NumExpansions))
7938 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007939
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007940 if (!Expand) {
7941 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007942 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007943 // expansion.
7944 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007945
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007946 TypeLocBuilder TLB;
7947 TLB.reserve(From->getTypeLoc().getFullDataSize());
7948
7949 QualType To = getDerived().TransformType(TLB, PatternTL);
7950 if (To.isNull())
7951 return ExprError();
7952
Chad Rosier4a9d7952012-08-08 18:46:20 +00007953 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007954 PatternTL.getSourceRange(),
7955 ExpansionTL.getEllipsisLoc(),
7956 NumExpansions);
7957 if (To.isNull())
7958 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007960 PackExpansionTypeLoc ToExpansionTL
7961 = TLB.push<PackExpansionTypeLoc>(To);
7962 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7963 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7964 continue;
7965 }
7966
7967 // Expand the pack expansion by substituting for each argument in the
7968 // pack(s).
7969 for (unsigned I = 0; I != *NumExpansions; ++I) {
7970 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7971 TypeLocBuilder TLB;
7972 TLB.reserve(PatternTL.getFullDataSize());
7973 QualType To = getDerived().TransformType(TLB, PatternTL);
7974 if (To.isNull())
7975 return ExprError();
7976
Eli Friedman20cfeca2013-07-19 21:49:32 +00007977 if (To->containsUnexpandedParameterPack()) {
7978 To = getDerived().RebuildPackExpansionType(To,
7979 PatternTL.getSourceRange(),
7980 ExpansionTL.getEllipsisLoc(),
7981 NumExpansions);
7982 if (To.isNull())
7983 return ExprError();
7984
7985 PackExpansionTypeLoc ToExpansionTL
7986 = TLB.push<PackExpansionTypeLoc>(To);
7987 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7988 }
7989
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007990 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007993 if (!RetainExpansion)
7994 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007995
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007996 // If we're supposed to retain a pack expansion, do so by temporarily
7997 // forgetting the partially-substituted parameter pack.
7998 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7999
8000 TypeLocBuilder TLB;
8001 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008003 QualType To = getDerived().TransformType(TLB, PatternTL);
8004 if (To.isNull())
8005 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008006
8007 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008008 PatternTL.getSourceRange(),
8009 ExpansionTL.getEllipsisLoc(),
8010 NumExpansions);
8011 if (To.isNull())
8012 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008013
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008014 PackExpansionTypeLoc ToExpansionTL
8015 = TLB.push<PackExpansionTypeLoc>(To);
8016 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8017 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8018 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008020 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8021 return SemaRef.Owned(E);
8022
8023 return getDerived().RebuildTypeTrait(E->getTrait(),
8024 E->getLocStart(),
8025 Args,
8026 E->getLocEnd());
8027}
8028
8029template<typename Derived>
8030ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008031TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8032 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8033 if (!T)
8034 return ExprError();
8035
8036 if (!getDerived().AlwaysRebuild() &&
8037 T == E->getQueriedTypeSourceInfo())
8038 return SemaRef.Owned(E);
8039
8040 ExprResult SubExpr;
8041 {
8042 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8043 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8044 if (SubExpr.isInvalid())
8045 return ExprError();
8046
8047 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8048 return SemaRef.Owned(E);
8049 }
8050
8051 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8052 E->getLocStart(),
8053 T,
8054 SubExpr.get(),
8055 E->getLocEnd());
8056}
8057
8058template<typename Derived>
8059ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008060TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8061 ExprResult SubExpr;
8062 {
8063 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8064 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8065 if (SubExpr.isInvalid())
8066 return ExprError();
8067
8068 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8069 return SemaRef.Owned(E);
8070 }
8071
8072 return getDerived().RebuildExpressionTrait(
8073 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8074}
8075
8076template<typename Derived>
8077ExprResult
John McCall865d4472009-11-19 22:55:06 +00008078TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008079 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008080 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8081}
8082
8083template<typename Derived>
8084ExprResult
8085TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8086 DependentScopeDeclRefExpr *E,
8087 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008088 NestedNameSpecifierLoc QualifierLoc
8089 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8090 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008091 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008092 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008093
John McCall43fed0d2010-11-12 08:19:04 +00008094 // TODO: If this is a conversion-function-id, verify that the
8095 // destination type name (if present) resolves the same way after
8096 // instantiation as it did in the local scope.
8097
Abramo Bagnara25777432010-08-11 22:01:17 +00008098 DeclarationNameInfo NameInfo
8099 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8100 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008102
John McCallf7a1a742009-11-24 19:00:30 +00008103 if (!E->hasExplicitTemplateArgs()) {
8104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008105 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008106 // Note: it is sufficient to compare the Name component of NameInfo:
8107 // if name has not changed, DNLoc has not changed either.
8108 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008109 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008110
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008111 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008112 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008113 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008114 /*TemplateArgs*/ 0,
8115 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008116 }
John McCalld5532b62009-11-23 01:53:49 +00008117
8118 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008119 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8120 E->getNumTemplateArgs(),
8121 TransArgs))
8122 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008123
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008124 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008125 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008126 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008127 &TransArgs,
8128 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008129}
8130
8131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008132ExprResult
John McCall454feb92009-12-08 09:21:05 +00008133TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008134 // CXXConstructExprs other than for list-initialization and
8135 // CXXTemporaryObjectExpr are always implicit, so when we have
8136 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008137 if ((E->getNumArgs() == 1 ||
8138 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008139 (!getDerived().DropCallArgument(E->getArg(0))) &&
8140 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008141 return getDerived().TransformExpr(E->getArg(0));
8142
Douglas Gregorb98b1992009-08-11 05:31:07 +00008143 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8144
8145 QualType T = getDerived().TransformType(E->getType());
8146 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008147 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008148
8149 CXXConstructorDecl *Constructor
8150 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008151 getDerived().TransformDecl(E->getLocStart(),
8152 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008153 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008155
Douglas Gregorb98b1992009-08-11 05:31:07 +00008156 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008157 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008158 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008159 &ArgumentChanged))
8160 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008161
Douglas Gregorb98b1992009-08-11 05:31:07 +00008162 if (!getDerived().AlwaysRebuild() &&
8163 T == E->getType() &&
8164 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008165 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008166 // Mark the constructor as referenced.
8167 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008168 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008169 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008170 }
Mike Stump1eb44332009-09-09 15:08:12 +00008171
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008172 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8173 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008174 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008175 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008176 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008177 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008178 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008179 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008180}
Mike Stump1eb44332009-09-09 15:08:12 +00008181
Douglas Gregorb98b1992009-08-11 05:31:07 +00008182/// \brief Transform a C++ temporary-binding expression.
8183///
Douglas Gregor51326552009-12-24 18:51:59 +00008184/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8185/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008187ExprResult
John McCall454feb92009-12-08 09:21:05 +00008188TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008189 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190}
Mike Stump1eb44332009-09-09 15:08:12 +00008191
John McCall4765fa02010-12-06 08:20:24 +00008192/// \brief Transform a C++ expression that contains cleanups that should
8193/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008194///
John McCall4765fa02010-12-06 08:20:24 +00008195/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008196/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008198ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008199TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008200 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008201}
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 Gregorb98b1992009-08-11 05:31:07 +00008205TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008206 CXXTemporaryObjectExpr *E) {
8207 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8208 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008210
Douglas Gregorb98b1992009-08-11 05:31:07 +00008211 CXXConstructorDecl *Constructor
8212 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008213 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008214 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008217
Douglas Gregorb98b1992009-08-11 05:31:07 +00008218 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008219 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008220 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008222 &ArgumentChanged))
8223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008224
Douglas Gregorb98b1992009-08-11 05:31:07 +00008225 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008226 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008227 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008228 !ArgumentChanged) {
8229 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008230 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008231 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008233
Richard Smithc83c2302012-12-19 01:39:02 +00008234 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008235 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8236 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008237 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008238 E->getLocEnd());
8239}
Mike Stump1eb44332009-09-09 15:08:12 +00008240
Douglas Gregorb98b1992009-08-11 05:31:07 +00008241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008242ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008243TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008244 // Transform the type of the lambda parameters and start the definition of
8245 // the lambda itself.
8246 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008247 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008248 if (!MethodTy)
8249 return ExprError();
8250
Eli Friedman8da8a662012-09-19 01:18:11 +00008251 // Create the local class that will describe the lambda.
8252 CXXRecordDecl *Class
8253 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8254 MethodTy,
8255 /*KnownDependent=*/false);
8256 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8257
Douglas Gregorc6889e72012-02-14 22:28:59 +00008258 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008259 SmallVector<QualType, 4> ParamTypes;
8260 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008261 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8262 E->getCallOperator()->param_begin(),
8263 E->getCallOperator()->param_size(),
8264 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008265 return ExprError();
Manuel Klimek152b4e42013-08-22 12:12:24 +00008266
Douglas Gregordfca6f52012-02-13 22:00:16 +00008267 // Build the call operator.
8268 CXXMethodDecl *CallOperator
8269 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008270 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008271 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008272 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008273 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008274
Richard Smith612409e2012-07-25 03:56:55 +00008275 return getDerived().TransformLambdaScope(E, CallOperator);
8276}
8277
8278template<typename Derived>
8279ExprResult
8280TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8281 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008282 bool Invalid = false;
8283
8284 // Transform any init-capture expressions before entering the scope of the
8285 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008286 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008287 InitCaptureExprs.resize(E->explicit_capture_end() -
8288 E->explicit_capture_begin());
8289 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8290 CEnd = E->capture_end();
8291 C != CEnd; ++C) {
8292 if (!C->isInitCapture())
8293 continue;
8294 InitCaptureExprs[C - E->capture_begin()] =
8295 getDerived().TransformExpr(E->getInitCaptureInit(C));
8296 }
8297
Douglas Gregord5387e82012-02-14 00:00:48 +00008298 // Introduce the context of the call operator.
8299 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8300
Douglas Gregordfca6f52012-02-13 22:00:16 +00008301 // Enter the scope of the lambda.
Manuel Klimek152b4e42013-08-22 12:12:24 +00008302 sema::LambdaScopeInfo *LSI
8303 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008304 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008305 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008306 E->hasExplicitParameters(),
8307 E->hasExplicitResultType(),
8308 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008309
Douglas Gregordfca6f52012-02-13 22:00:16 +00008310 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008311 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008312 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008313 CEnd = E->capture_end();
8314 C != CEnd; ++C) {
8315 // When we hit the first implicit capture, tell Sema that we've finished
8316 // the list of explicit captures.
8317 if (!FinishedExplicitCaptures && C->isImplicit()) {
8318 getSema().finishLambdaExplicitCaptures(LSI);
8319 FinishedExplicitCaptures = true;
8320 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008321
Douglas Gregordfca6f52012-02-13 22:00:16 +00008322 // Capturing 'this' is trivial.
8323 if (C->capturesThis()) {
8324 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8325 continue;
8326 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008327
Richard Smith0d8e9642013-05-16 06:20:58 +00008328 // Rebuild init-captures, including the implied field declaration.
8329 if (C->isInitCapture()) {
8330 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8331 if (Init.isInvalid()) {
8332 Invalid = true;
8333 continue;
8334 }
8335 FieldDecl *OldFD = C->getInitCaptureField();
8336 FieldDecl *NewFD = getSema().checkInitCapture(
8337 C->getLocation(), OldFD->getType()->isReferenceType(),
8338 OldFD->getIdentifier(), Init.take());
8339 if (!NewFD)
8340 Invalid = true;
8341 else
8342 getDerived().transformedLocalDecl(OldFD, NewFD);
8343 continue;
8344 }
8345
8346 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8347
Douglas Gregora7365242012-02-14 19:27:52 +00008348 // Determine the capture kind for Sema.
8349 Sema::TryCaptureKind Kind
8350 = C->isImplicit()? Sema::TryCapture_Implicit
8351 : C->getCaptureKind() == LCK_ByCopy
8352 ? Sema::TryCapture_ExplicitByVal
8353 : Sema::TryCapture_ExplicitByRef;
8354 SourceLocation EllipsisLoc;
8355 if (C->isPackExpansion()) {
8356 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8357 bool ShouldExpand = false;
8358 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008359 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8361 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008362 Unexpanded,
8363 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008364 NumExpansions)) {
8365 Invalid = true;
8366 continue;
8367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368
Douglas Gregora7365242012-02-14 19:27:52 +00008369 if (ShouldExpand) {
8370 // The transform has determined that we should perform an expansion;
8371 // transform and capture each of the arguments.
8372 // expansion of the pattern. Do so.
8373 VarDecl *Pack = C->getCapturedVar();
8374 for (unsigned I = 0; I != *NumExpansions; ++I) {
8375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8376 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008377 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008378 Pack));
8379 if (!CapturedVar) {
8380 Invalid = true;
8381 continue;
8382 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008383
Douglas Gregora7365242012-02-14 19:27:52 +00008384 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008385 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8386 }
Douglas Gregora7365242012-02-14 19:27:52 +00008387 continue;
8388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389
Douglas Gregora7365242012-02-14 19:27:52 +00008390 EllipsisLoc = C->getEllipsisLoc();
8391 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008392
Douglas Gregordfca6f52012-02-13 22:00:16 +00008393 // Transform the captured variable.
8394 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008395 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008396 C->getCapturedVar()));
8397 if (!CapturedVar) {
8398 Invalid = true;
8399 continue;
8400 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008401
Douglas Gregordfca6f52012-02-13 22:00:16 +00008402 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008403 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008404 }
8405 if (!FinishedExplicitCaptures)
8406 getSema().finishLambdaExplicitCaptures(LSI);
8407
Douglas Gregordfca6f52012-02-13 22:00:16 +00008408
8409 // Enter a new evaluation context to insulate the lambda from any
8410 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008411 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008412
8413 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008414 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008415 /*IsInstantiation=*/true);
8416 return ExprError();
8417 }
8418
8419 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008420 StmtResult Body = getDerived().TransformStmt(E->getBody());
8421 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008423 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008425 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008426
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008428 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008429}
8430
8431template<typename Derived>
8432ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008433TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008434 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008435 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8436 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008438
Douglas Gregorb98b1992009-08-11 05:31:07 +00008439 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008440 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008441 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008443 &ArgumentChanged))
8444 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445
Douglas Gregorb98b1992009-08-11 05:31:07 +00008446 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008447 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008448 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008449 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008450
Douglas Gregorb98b1992009-08-11 05:31:07 +00008451 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008452 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008453 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008454 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008455 E->getRParenLoc());
8456}
Mike Stump1eb44332009-09-09 15:08:12 +00008457
Douglas Gregorb98b1992009-08-11 05:31:07 +00008458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008459ExprResult
John McCall865d4472009-11-19 22:55:06 +00008460TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008461 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008462 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008463 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008464 Expr *OldBase;
8465 QualType BaseType;
8466 QualType ObjectType;
8467 if (!E->isImplicitAccess()) {
8468 OldBase = E->getBase();
8469 Base = getDerived().TransformExpr(OldBase);
8470 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008471 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008472
John McCallaa81e162009-12-01 22:10:20 +00008473 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008474 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008475 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008476 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008477 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008478 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008479 ObjectTy,
8480 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008481 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008482 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008483
John McCallb3d87482010-08-24 05:47:05 +00008484 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008485 BaseType = ((Expr*) Base.get())->getType();
8486 } else {
8487 OldBase = 0;
8488 BaseType = getDerived().TransformType(E->getBaseType());
8489 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8490 }
Mike Stump1eb44332009-09-09 15:08:12 +00008491
Douglas Gregor6cd21982009-10-20 05:58:46 +00008492 // Transform the first part of the nested-name-specifier that qualifies
8493 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008494 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008495 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008496 E->getFirstQualifierFoundInScope(),
8497 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008498
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008499 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008500 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008501 QualifierLoc
8502 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8503 ObjectType,
8504 FirstQualifierInScope);
8505 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008506 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008507 }
Mike Stump1eb44332009-09-09 15:08:12 +00008508
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008509 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8510
John McCall43fed0d2010-11-12 08:19:04 +00008511 // TODO: If this is a conversion-function-id, verify that the
8512 // destination type name (if present) resolves the same way after
8513 // instantiation as it did in the local scope.
8514
Abramo Bagnara25777432010-08-11 22:01:17 +00008515 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008516 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008517 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008519
John McCallaa81e162009-12-01 22:10:20 +00008520 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008521 // This is a reference to a member without an explicitly-specified
8522 // template argument list. Optimize for this common case.
8523 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008524 Base.get() == OldBase &&
8525 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008526 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008527 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008528 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008529 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008530
John McCall9ae2f072010-08-23 23:25:46 +00008531 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008532 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008533 E->isArrow(),
8534 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008535 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008536 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008537 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008538 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008539 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008540 }
8541
John McCalld5532b62009-11-23 01:53:49 +00008542 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008543 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8544 E->getNumTemplateArgs(),
8545 TransArgs))
8546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008547
John McCall9ae2f072010-08-23 23:25:46 +00008548 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008549 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008550 E->isArrow(),
8551 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008552 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008553 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008554 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008555 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008556 &TransArgs);
8557}
8558
8559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008560ExprResult
John McCall454feb92009-12-08 09:21:05 +00008561TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008562 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008563 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008564 QualType BaseType;
8565 if (!Old->isImplicitAccess()) {
8566 Base = getDerived().TransformExpr(Old->getBase());
8567 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008568 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008569 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8570 Old->isArrow());
8571 if (Base.isInvalid())
8572 return ExprError();
8573 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008574 } else {
8575 BaseType = getDerived().TransformType(Old->getBaseType());
8576 }
John McCall129e2df2009-11-30 22:42:35 +00008577
Douglas Gregor4c9be892011-02-28 20:01:57 +00008578 NestedNameSpecifierLoc QualifierLoc;
8579 if (Old->getQualifierLoc()) {
8580 QualifierLoc
8581 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8582 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008583 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008584 }
8585
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008586 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8587
Abramo Bagnara25777432010-08-11 22:01:17 +00008588 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008589 Sema::LookupOrdinaryName);
8590
8591 // Transform all the decls.
8592 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8593 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008594 NamedDecl *InstD = static_cast<NamedDecl*>(
8595 getDerived().TransformDecl(Old->getMemberLoc(),
8596 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008597 if (!InstD) {
8598 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8599 // This can happen because of dependent hiding.
8600 if (isa<UsingShadowDecl>(*I))
8601 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008602 else {
8603 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008604 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008605 }
John McCall9f54ad42009-12-10 09:41:52 +00008606 }
John McCall129e2df2009-11-30 22:42:35 +00008607
8608 // Expand using declarations.
8609 if (isa<UsingDecl>(InstD)) {
8610 UsingDecl *UD = cast<UsingDecl>(InstD);
8611 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8612 E = UD->shadow_end(); I != E; ++I)
8613 R.addDecl(*I);
8614 continue;
8615 }
8616
8617 R.addDecl(InstD);
8618 }
8619
8620 R.resolveKind();
8621
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008622 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008623 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008625 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008626 Old->getMemberLoc(),
8627 Old->getNamingClass()));
8628 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008629 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630
Douglas Gregor66c45152010-04-27 16:10:10 +00008631 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008632 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008633
John McCall129e2df2009-11-30 22:42:35 +00008634 TemplateArgumentListInfo TransArgs;
8635 if (Old->hasExplicitTemplateArgs()) {
8636 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8637 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008638 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8639 Old->getNumTemplateArgs(),
8640 TransArgs))
8641 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008642 }
John McCallc2233c52010-01-15 08:34:02 +00008643
8644 // FIXME: to do this check properly, we will need to preserve the
8645 // first-qualifier-in-scope here, just in case we had a dependent
8646 // base (and therefore couldn't do the check) and a
8647 // nested-name-qualifier (and therefore could do the lookup).
8648 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008649
John McCall9ae2f072010-08-23 23:25:46 +00008650 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008651 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008652 Old->getOperatorLoc(),
8653 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008654 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008655 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008656 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008657 R,
8658 (Old->hasExplicitTemplateArgs()
8659 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008660}
8661
8662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008663ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008664TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008665 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008666 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8667 if (SubExpr.isInvalid())
8668 return ExprError();
8669
8670 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008671 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008672
8673 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8674}
8675
8676template<typename Derived>
8677ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008678TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008679 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8680 if (Pattern.isInvalid())
8681 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008682
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008683 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8684 return SemaRef.Owned(E);
8685
Douglas Gregor67fd1252011-01-14 21:20:45 +00008686 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8687 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008688}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008689
8690template<typename Derived>
8691ExprResult
8692TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8693 // If E is not value-dependent, then nothing will change when we transform it.
8694 // Note: This is an instantiation-centric view.
8695 if (!E->isValueDependent())
8696 return SemaRef.Owned(E);
8697
8698 // Note: None of the implementations of TryExpandParameterPacks can ever
8699 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008700 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008701 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8702 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008703 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008704 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008705 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008706 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008707 ShouldExpand, RetainExpansion,
8708 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008709 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008710
Douglas Gregor089e8932011-10-10 18:59:29 +00008711 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008712 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713
Douglas Gregor089e8932011-10-10 18:59:29 +00008714 NamedDecl *Pack = E->getPack();
8715 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008717 Pack));
8718 if (!Pack)
8719 return ExprError();
8720 }
8721
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722
Douglas Gregoree8aff02011-01-04 17:33:58 +00008723 // We now know the length of the parameter pack, so build a new expression
8724 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008725 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8726 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008727 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008728}
8729
Douglas Gregorbe230c32011-01-03 17:17:50 +00008730template<typename Derived>
8731ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008732TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8733 SubstNonTypeTemplateParmPackExpr *E) {
8734 // Default behavior is to do nothing with this transformation.
8735 return SemaRef.Owned(E);
8736}
8737
8738template<typename Derived>
8739ExprResult
John McCall91a57552011-07-15 05:09:51 +00008740TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8741 SubstNonTypeTemplateParmExpr *E) {
8742 // Default behavior is to do nothing with this transformation.
8743 return SemaRef.Owned(E);
8744}
8745
8746template<typename Derived>
8747ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008748TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8749 // Default behavior is to do nothing with this transformation.
8750 return SemaRef.Owned(E);
8751}
8752
8753template<typename Derived>
8754ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008755TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8756 MaterializeTemporaryExpr *E) {
8757 return getDerived().TransformExpr(E->GetTemporaryExpr());
8758}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008759
Douglas Gregor03e80032011-06-21 17:03:29 +00008760template<typename Derived>
8761ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008762TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8763 CXXStdInitializerListExpr *E) {
8764 return getDerived().TransformExpr(E->getSubExpr());
8765}
8766
8767template<typename Derived>
8768ExprResult
John McCall454feb92009-12-08 09:21:05 +00008769TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008770 return SemaRef.MaybeBindToTemporary(E);
8771}
8772
8773template<typename Derived>
8774ExprResult
8775TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008776 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008777}
8778
8779template<typename Derived>
8780ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008781TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8782 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8783 if (SubExpr.isInvalid())
8784 return ExprError();
8785
8786 if (!getDerived().AlwaysRebuild() &&
8787 SubExpr.get() == E->getSubExpr())
8788 return SemaRef.Owned(E);
8789
8790 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008791}
8792
8793template<typename Derived>
8794ExprResult
8795TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8796 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008797 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008798 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008799 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008800 /*IsCall=*/false, Elements, &ArgChanged))
8801 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008803 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8804 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008805
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008806 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8807 Elements.data(),
8808 Elements.size());
8809}
8810
8811template<typename Derived>
8812ExprResult
8813TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008814 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008815 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008816 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008817 bool ArgChanged = false;
8818 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8819 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008821 if (OrigElement.isPackExpansion()) {
8822 // This key/value element is a pack expansion.
8823 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8824 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8825 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8826 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8827
8828 // Determine whether the set of unexpanded parameter packs can
8829 // and should be expanded.
8830 bool Expand = true;
8831 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008832 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8833 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008834 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8835 OrigElement.Value->getLocEnd());
8836 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8837 PatternRange,
8838 Unexpanded,
8839 Expand, RetainExpansion,
8840 NumExpansions))
8841 return ExprError();
8842
8843 if (!Expand) {
8844 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008845 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008846 // expansion.
8847 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8848 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8849 if (Key.isInvalid())
8850 return ExprError();
8851
8852 if (Key.get() != OrigElement.Key)
8853 ArgChanged = true;
8854
8855 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8856 if (Value.isInvalid())
8857 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008858
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008859 if (Value.get() != OrigElement.Value)
8860 ArgChanged = true;
8861
Chad Rosier4a9d7952012-08-08 18:46:20 +00008862 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008863 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8864 };
8865 Elements.push_back(Expansion);
8866 continue;
8867 }
8868
8869 // Record right away that the argument was changed. This needs
8870 // to happen even if the array expands to nothing.
8871 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008872
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008873 // The transform has determined that we should perform an elementwise
8874 // expansion of the pattern. Do so.
8875 for (unsigned I = 0; I != *NumExpansions; ++I) {
8876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8877 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8878 if (Key.isInvalid())
8879 return ExprError();
8880
8881 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8882 if (Value.isInvalid())
8883 return ExprError();
8884
Chad Rosier4a9d7952012-08-08 18:46:20 +00008885 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008886 Key.get(), Value.get(), SourceLocation(), NumExpansions
8887 };
8888
8889 // If any unexpanded parameter packs remain, we still have a
8890 // pack expansion.
8891 if (Key.get()->containsUnexpandedParameterPack() ||
8892 Value.get()->containsUnexpandedParameterPack())
8893 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008894
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008895 Elements.push_back(Element);
8896 }
8897
8898 // We've finished with this pack expansion.
8899 continue;
8900 }
8901
8902 // Transform and check key.
8903 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8904 if (Key.isInvalid())
8905 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008906
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008907 if (Key.get() != OrigElement.Key)
8908 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008909
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008910 // Transform and check value.
8911 ExprResult Value
8912 = getDerived().TransformExpr(OrigElement.Value);
8913 if (Value.isInvalid())
8914 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008915
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008916 if (Value.get() != OrigElement.Value)
8917 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008918
8919 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008920 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008921 };
8922 Elements.push_back(Element);
8923 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008924
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008925 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8926 return SemaRef.MaybeBindToTemporary(E);
8927
8928 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8929 Elements.data(),
8930 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008931}
8932
Mike Stump1eb44332009-09-09 15:08:12 +00008933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008934ExprResult
John McCall454feb92009-12-08 09:21:05 +00008935TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008936 TypeSourceInfo *EncodedTypeInfo
8937 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8938 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008940
Douglas Gregorb98b1992009-08-11 05:31:07 +00008941 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008942 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008943 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008944
8945 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008946 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008947 E->getRParenLoc());
8948}
Mike Stump1eb44332009-09-09 15:08:12 +00008949
Douglas Gregorb98b1992009-08-11 05:31:07 +00008950template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008951ExprResult TreeTransform<Derived>::
8952TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008953 // This is a kind of implicit conversion, and it needs to get dropped
8954 // and recomputed for the same general reasons that ImplicitCastExprs
8955 // do, as well a more specific one: this expression is only valid when
8956 // it appears *immediately* as an argument expression.
8957 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008958}
8959
8960template<typename Derived>
8961ExprResult TreeTransform<Derived>::
8962TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008963 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008964 = getDerived().TransformType(E->getTypeInfoAsWritten());
8965 if (!TSInfo)
8966 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008967
John McCallf85e1932011-06-15 23:02:42 +00008968 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008969 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008970 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008971
John McCallf85e1932011-06-15 23:02:42 +00008972 if (!getDerived().AlwaysRebuild() &&
8973 TSInfo == E->getTypeInfoAsWritten() &&
8974 Result.get() == E->getSubExpr())
8975 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008976
John McCallf85e1932011-06-15 23:02:42 +00008977 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008978 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008979 Result.get());
8980}
8981
8982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008983ExprResult
John McCall454feb92009-12-08 09:21:05 +00008984TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008985 // Transform arguments.
8986 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008987 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008988 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008989 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008990 &ArgChanged))
8991 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008992
Douglas Gregor92e986e2010-04-22 16:44:27 +00008993 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8994 // Class message: transform the receiver type.
8995 TypeSourceInfo *ReceiverTypeInfo
8996 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8997 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008998 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008999
Douglas Gregor92e986e2010-04-22 16:44:27 +00009000 // If nothing changed, just retain the existing message send.
9001 if (!getDerived().AlwaysRebuild() &&
9002 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009003 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009004
9005 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009006 SmallVector<SourceLocation, 16> SelLocs;
9007 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009008 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9009 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009010 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009011 E->getMethodDecl(),
9012 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009013 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009014 E->getRightLoc());
9015 }
9016
9017 // Instance message: transform the receiver
9018 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9019 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009020 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009021 = getDerived().TransformExpr(E->getInstanceReceiver());
9022 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009023 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009024
9025 // If nothing changed, just retain the existing message send.
9026 if (!getDerived().AlwaysRebuild() &&
9027 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009028 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009029
Douglas Gregor92e986e2010-04-22 16:44:27 +00009030 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009031 SmallVector<SourceLocation, 16> SelLocs;
9032 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009033 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009034 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009035 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009036 E->getMethodDecl(),
9037 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009038 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009039 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009040}
9041
Mike Stump1eb44332009-09-09 15:08:12 +00009042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009043ExprResult
John McCall454feb92009-12-08 09:21:05 +00009044TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009045 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009046}
9047
Mike Stump1eb44332009-09-09 15:08:12 +00009048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009049ExprResult
John McCall454feb92009-12-08 09:21:05 +00009050TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009051 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009052}
9053
Mike Stump1eb44332009-09-09 15:08:12 +00009054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009055ExprResult
John McCall454feb92009-12-08 09:21:05 +00009056TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009057 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009058 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009059 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009060 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009061
9062 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009063
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009064 // If nothing changed, just retain the existing expression.
9065 if (!getDerived().AlwaysRebuild() &&
9066 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009067 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009068
John McCall9ae2f072010-08-23 23:25:46 +00009069 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009070 E->getLocation(),
9071 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009072}
9073
Mike Stump1eb44332009-09-09 15:08:12 +00009074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009075ExprResult
John McCall454feb92009-12-08 09:21:05 +00009076TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009077 // 'super' and types never change. Property never changes. Just
9078 // retain the existing expression.
9079 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009080 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009081
Douglas Gregore3303542010-04-26 20:47:02 +00009082 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009083 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009084 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009085 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009086
Douglas Gregore3303542010-04-26 20:47:02 +00009087 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009088
Douglas Gregore3303542010-04-26 20:47:02 +00009089 // If nothing changed, just retain the existing expression.
9090 if (!getDerived().AlwaysRebuild() &&
9091 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009092 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009093
John McCall12f78a62010-12-02 01:19:52 +00009094 if (E->isExplicitProperty())
9095 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9096 E->getExplicitProperty(),
9097 E->getLocation());
9098
9099 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009100 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009101 E->getImplicitPropertyGetter(),
9102 E->getImplicitPropertySetter(),
9103 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009104}
9105
Mike Stump1eb44332009-09-09 15:08:12 +00009106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009107ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009108TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9109 // Transform the base expression.
9110 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9111 if (Base.isInvalid())
9112 return ExprError();
9113
9114 // Transform the key expression.
9115 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9116 if (Key.isInvalid())
9117 return ExprError();
9118
9119 // If nothing changed, just retain the existing expression.
9120 if (!getDerived().AlwaysRebuild() &&
9121 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9122 return SemaRef.Owned(E);
9123
Chad Rosier4a9d7952012-08-08 18:46:20 +00009124 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009125 Base.get(), Key.get(),
9126 E->getAtIndexMethodDecl(),
9127 E->setAtIndexMethodDecl());
9128}
9129
9130template<typename Derived>
9131ExprResult
John McCall454feb92009-12-08 09:21:05 +00009132TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009133 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009134 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009135 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009136 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009137
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009138 // If nothing changed, just retain the existing expression.
9139 if (!getDerived().AlwaysRebuild() &&
9140 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009141 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009142
John McCall9ae2f072010-08-23 23:25:46 +00009143 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009144 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009145 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009146}
9147
Mike Stump1eb44332009-09-09 15:08:12 +00009148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009149ExprResult
John McCall454feb92009-12-08 09:21:05 +00009150TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009151 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009152 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009153 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009154 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009155 SubExprs, &ArgumentChanged))
9156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009157
Douglas Gregorb98b1992009-08-11 05:31:07 +00009158 if (!getDerived().AlwaysRebuild() &&
9159 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009161
Douglas Gregorb98b1992009-08-11 05:31:07 +00009162 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009163 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009164 E->getRParenLoc());
9165}
9166
Mike Stump1eb44332009-09-09 15:08:12 +00009167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009168ExprResult
John McCall454feb92009-12-08 09:21:05 +00009169TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009170 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009171
John McCallc6ac9c32011-02-04 18:33:18 +00009172 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9173 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9174
9175 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009176 blockScope->TheDecl->setBlockMissingReturnType(
9177 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009178
Chris Lattner686775d2011-07-20 06:58:45 +00009179 SmallVector<ParmVarDecl*, 4> params;
9180 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009181
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009182 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009183 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9184 oldBlock->param_begin(),
9185 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009186 0, paramTypes, &params)) {
9187 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009188 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009189 }
John McCallc6ac9c32011-02-04 18:33:18 +00009190
Jordan Rose09189892013-03-08 22:25:36 +00009191 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009192 QualType exprResultType =
9193 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009194
Jordan Rosebea522f2013-03-08 21:51:21 +00009195 QualType functionType =
9196 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009197 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009198 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009199
9200 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009201 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009202 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009203
9204 if (!oldBlock->blockMissingReturnType()) {
9205 blockScope->HasImplicitReturnType = false;
9206 blockScope->ReturnType = exprResultType;
9207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009208
John McCall711c52b2011-01-05 12:14:39 +00009209 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009210 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009211 if (body.isInvalid()) {
9212 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009213 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009214 }
John McCall711c52b2011-01-05 12:14:39 +00009215
John McCallc6ac9c32011-02-04 18:33:18 +00009216#ifndef NDEBUG
9217 // In builds with assertions, make sure that we captured everything we
9218 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009219 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9220 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9221 e = oldBlock->capture_end(); i != e; ++i) {
9222 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009223
Douglas Gregorfc921372011-05-20 15:32:55 +00009224 // Ignore parameter packs.
9225 if (isa<ParmVarDecl>(oldCapture) &&
9226 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9227 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009228
Douglas Gregorfc921372011-05-20 15:32:55 +00009229 VarDecl *newCapture =
9230 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9231 oldCapture));
9232 assert(blockScope->CaptureMap.count(newCapture));
9233 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009234 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009235 }
9236#endif
9237
9238 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9239 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009240}
9241
Mike Stump1eb44332009-09-09 15:08:12 +00009242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009243ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009244TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009245 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009246}
Eli Friedman276b0612011-10-11 02:20:01 +00009247
9248template<typename Derived>
9249ExprResult
9250TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009251 QualType RetTy = getDerived().TransformType(E->getType());
9252 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009253 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009254 SubExprs.reserve(E->getNumSubExprs());
9255 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9256 SubExprs, &ArgumentChanged))
9257 return ExprError();
9258
9259 if (!getDerived().AlwaysRebuild() &&
9260 !ArgumentChanged)
9261 return SemaRef.Owned(E);
9262
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009263 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009264 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009265}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009266
Douglas Gregorb98b1992009-08-11 05:31:07 +00009267//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009268// Type reconstruction
9269//===----------------------------------------------------------------------===//
9270
Mike Stump1eb44332009-09-09 15:08:12 +00009271template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009272QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9273 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009274 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009275 getDerived().getBaseEntity());
9276}
9277
Mike Stump1eb44332009-09-09 15:08:12 +00009278template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009279QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9280 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009281 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009282 getDerived().getBaseEntity());
9283}
9284
Mike Stump1eb44332009-09-09 15:08:12 +00009285template<typename Derived>
9286QualType
John McCall85737a72009-10-30 00:06:24 +00009287TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9288 bool WrittenAsLValue,
9289 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009290 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009291 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009292}
9293
9294template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009295QualType
John McCall85737a72009-10-30 00:06:24 +00009296TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9297 QualType ClassType,
9298 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009299 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009300 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009301}
9302
9303template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009304QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009305TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9306 ArrayType::ArraySizeModifier SizeMod,
9307 const llvm::APInt *Size,
9308 Expr *SizeExpr,
9309 unsigned IndexTypeQuals,
9310 SourceRange BracketsRange) {
9311 if (SizeExpr || !Size)
9312 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9313 IndexTypeQuals, BracketsRange,
9314 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009315
9316 QualType Types[] = {
9317 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9318 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9319 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009320 };
Craig Topperb9602322013-07-15 03:38:40 +00009321 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009322 QualType SizeType;
9323 for (unsigned I = 0; I != NumTypes; ++I)
9324 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9325 SizeType = Types[I];
9326 break;
9327 }
Mike Stump1eb44332009-09-09 15:08:12 +00009328
Eli Friedman01f276d2012-01-25 23:20:27 +00009329 // Note that we can return a VariableArrayType here in the case where
9330 // the element type was a dependent VariableArrayType.
9331 IntegerLiteral *ArraySize
9332 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9333 /*FIXME*/BracketsRange.getBegin());
9334 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009335 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009336 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009337}
Mike Stump1eb44332009-09-09 15:08:12 +00009338
Douglas Gregor577f75a2009-08-04 16:50:30 +00009339template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009340QualType
9341TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009342 ArrayType::ArraySizeModifier SizeMod,
9343 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009344 unsigned IndexTypeQuals,
9345 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009346 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009347 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009348}
9349
9350template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009351QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009352TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009353 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009354 unsigned IndexTypeQuals,
9355 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009356 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009357 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009358}
Mike Stump1eb44332009-09-09 15:08:12 +00009359
Douglas Gregor577f75a2009-08-04 16:50:30 +00009360template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009361QualType
9362TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009363 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009364 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009365 unsigned IndexTypeQuals,
9366 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009367 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009368 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009369 IndexTypeQuals, BracketsRange);
9370}
9371
9372template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009373QualType
9374TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009375 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009376 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009377 unsigned IndexTypeQuals,
9378 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009379 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009380 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009381 IndexTypeQuals, BracketsRange);
9382}
9383
9384template<typename Derived>
9385QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009386 unsigned NumElements,
9387 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009388 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009389 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009390}
Mike Stump1eb44332009-09-09 15:08:12 +00009391
Douglas Gregor577f75a2009-08-04 16:50:30 +00009392template<typename Derived>
9393QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9394 unsigned NumElements,
9395 SourceLocation AttributeLoc) {
9396 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9397 NumElements, true);
9398 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009399 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9400 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009401 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009402}
Mike Stump1eb44332009-09-09 15:08:12 +00009403
Douglas Gregor577f75a2009-08-04 16:50:30 +00009404template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009405QualType
9406TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009407 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009408 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009409 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009410}
Mike Stump1eb44332009-09-09 15:08:12 +00009411
Douglas Gregor577f75a2009-08-04 16:50:30 +00009412template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009413QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9414 QualType T,
9415 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009416 const FunctionProtoType::ExtProtoInfo &EPI) {
9417 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009418 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009419 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009420 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009421}
Mike Stump1eb44332009-09-09 15:08:12 +00009422
Douglas Gregor577f75a2009-08-04 16:50:30 +00009423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009424QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9425 return SemaRef.Context.getFunctionNoProtoType(T);
9426}
9427
9428template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009429QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9430 assert(D && "no decl found");
9431 if (D->isInvalidDecl()) return QualType();
9432
Douglas Gregor92e986e2010-04-22 16:44:27 +00009433 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009434 TypeDecl *Ty;
9435 if (isa<UsingDecl>(D)) {
9436 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009437 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009438 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9439
9440 // A valid resolved using typename decl points to exactly one type decl.
9441 assert(++Using->shadow_begin() == Using->shadow_end());
9442 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009443
John McCalled976492009-12-04 22:46:56 +00009444 } else {
9445 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9446 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9447 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9448 }
9449
9450 return SemaRef.Context.getTypeDeclType(Ty);
9451}
9452
9453template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009454QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9455 SourceLocation Loc) {
9456 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009457}
9458
9459template<typename Derived>
9460QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9461 return SemaRef.Context.getTypeOfType(Underlying);
9462}
9463
9464template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009465QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9466 SourceLocation Loc) {
9467 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009468}
9469
9470template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009471QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9472 UnaryTransformType::UTTKind UKind,
9473 SourceLocation Loc) {
9474 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9475}
9476
9477template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009478QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009479 TemplateName Template,
9480 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009481 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009482 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009483}
Mike Stump1eb44332009-09-09 15:08:12 +00009484
Douglas Gregordcee1a12009-08-06 05:28:30 +00009485template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009486QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9487 SourceLocation KWLoc) {
9488 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9489}
9490
9491template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009492TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009493TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009494 bool TemplateKW,
9495 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009496 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009497 Template);
9498}
9499
9500template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009501TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009502TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9503 const IdentifierInfo &Name,
9504 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009505 QualType ObjectType,
9506 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009507 UnqualifiedId TemplateName;
9508 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009509 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009510 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009511 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009512 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009513 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009514 /*EnteringContext=*/false,
9515 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009516 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009517}
Mike Stump1eb44332009-09-09 15:08:12 +00009518
Douglas Gregorb98b1992009-08-11 05:31:07 +00009519template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009520TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009521TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009522 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009523 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009524 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009525 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009526 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009527 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009528 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009529 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009530 Sema::TemplateTy Template;
9531 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009532 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009533 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009534 /*EnteringContext=*/false,
9535 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009536 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009537}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009538
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009540ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009541TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9542 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009543 Expr *OrigCallee,
9544 Expr *First,
9545 Expr *Second) {
9546 Expr *Callee = OrigCallee->IgnoreParenCasts();
9547 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009548
Douglas Gregorb98b1992009-08-11 05:31:07 +00009549 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009550 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009551 if (!First->getType()->isOverloadableType() &&
9552 !Second->getType()->isOverloadableType())
9553 return getSema().CreateBuiltinArraySubscriptExpr(First,
9554 Callee->getLocStart(),
9555 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009556 } else if (Op == OO_Arrow) {
9557 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009558 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9559 } else if (Second == 0 || isPostIncDec) {
9560 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009561 // The argument is not of overloadable type, so try to create a
9562 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009563 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009564 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009565
John McCall9ae2f072010-08-23 23:25:46 +00009566 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009567 }
9568 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009569 if (!First->getType()->isOverloadableType() &&
9570 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009571 // Neither of the arguments is an overloadable type, so try to
9572 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009573 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009574 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009575 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009576 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009577 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009578
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009579 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009580 }
9581 }
Mike Stump1eb44332009-09-09 15:08:12 +00009582
9583 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009584 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009585 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009586
John McCall9ae2f072010-08-23 23:25:46 +00009587 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009588 assert(ULE->requiresADL());
9589
9590 // FIXME: Do we have to check
9591 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009592 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009593 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009594 // If we've resolved this to a particular non-member function, just call
9595 // that function. If we resolved it to a member function,
9596 // CreateOverloaded* will find that function for us.
9597 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9598 if (!isa<CXXMethodDecl>(ND))
9599 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009600 }
Mike Stump1eb44332009-09-09 15:08:12 +00009601
Douglas Gregorb98b1992009-08-11 05:31:07 +00009602 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009603 Expr *Args[2] = { First, Second };
9604 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009605
Douglas Gregorb98b1992009-08-11 05:31:07 +00009606 // Create the overloaded operator invocation for unary operators.
9607 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009608 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009609 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009610 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009611 }
Mike Stump1eb44332009-09-09 15:08:12 +00009612
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009613 if (Op == OO_Subscript) {
9614 SourceLocation LBrace;
9615 SourceLocation RBrace;
9616
9617 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9618 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9619 LBrace = SourceLocation::getFromRawEncoding(
9620 NameLoc.CXXOperatorName.BeginOpNameLoc);
9621 RBrace = SourceLocation::getFromRawEncoding(
9622 NameLoc.CXXOperatorName.EndOpNameLoc);
9623 } else {
9624 LBrace = Callee->getLocStart();
9625 RBrace = OpLoc;
9626 }
9627
9628 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9629 First, Second);
9630 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009631
Douglas Gregorb98b1992009-08-11 05:31:07 +00009632 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009633 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009634 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009635 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9636 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009638
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009639 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009640}
Mike Stump1eb44332009-09-09 15:08:12 +00009641
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009642template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009643ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009644TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009645 SourceLocation OperatorLoc,
9646 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009647 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009648 TypeSourceInfo *ScopeType,
9649 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009650 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009651 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009652 QualType BaseType = Base->getType();
9653 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009654 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009655 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009656 !BaseType->getAs<PointerType>()->getPointeeType()
9657 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009658 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009659 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009660 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009661 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009662 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009663 /*FIXME?*/true);
9664 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009665
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009666 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009667 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9668 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9669 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9670 NameInfo.setNamedTypeInfo(DestroyedType);
9671
Richard Smith6314db92012-05-15 06:15:11 +00009672 // The scope type is now known to be a valid nested name specifier
9673 // component. Tack it on to the end of the nested name specifier.
9674 if (ScopeType)
9675 SS.Extend(SemaRef.Context, SourceLocation(),
9676 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009677
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009678 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009679 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009680 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009681 SS, TemplateKWLoc,
9682 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009683 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009684 /*TemplateArgs*/ 0);
9685}
9686
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009687template<typename Derived>
9688StmtResult
9689TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009690 SourceLocation Loc = S->getLocStart();
9691 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9692 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9693 S->getCapturedRegionKind(), NumParams);
9694 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9695
9696 if (Body.isInvalid()) {
9697 getSema().ActOnCapturedRegionError();
9698 return StmtError();
9699 }
9700
9701 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009702}
9703
Douglas Gregor577f75a2009-08-04 16:50:30 +00009704} // end namespace clang
9705
9706#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H