blob: 6559dede1c9415a514e7394278e8ed06246ae5e9 [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.
Faisal Valifad9e132013-09-26 19:54:12 +0000790 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
791 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000792 }
793
Douglas Gregor577f75a2009-08-04 16:50:30 +0000794 /// \brief Build a new template specialization type.
795 ///
796 /// By default, performs semantic analysis when building the template
797 /// specialization type. Subclasses may override this routine to provide
798 /// different behavior.
799 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000800 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000801 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000802
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000803 /// \brief Build a new parenthesized type.
804 ///
805 /// By default, builds a new ParenType type from the inner type.
806 /// Subclasses may override this routine to provide different behavior.
807 QualType RebuildParenType(QualType InnerType) {
808 return SemaRef.Context.getParenType(InnerType);
809 }
810
Douglas Gregor577f75a2009-08-04 16:50:30 +0000811 /// \brief Build a new qualified name type.
812 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000813 /// By default, builds a new ElaboratedType type from the keyword,
814 /// the nested-name-specifier and the named type.
815 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000816 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
817 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000818 NestedNameSpecifierLoc QualifierLoc,
819 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000820 return SemaRef.Context.getElaboratedType(Keyword,
821 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000822 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000823 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000824
825 /// \brief Build a new typename type that refers to a template-id.
826 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000827 /// By default, builds a new DependentNameType type from the
828 /// nested-name-specifier and the given type. Subclasses may override
829 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000830 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 ElaboratedTypeKeyword Keyword,
832 NestedNameSpecifierLoc QualifierLoc,
833 const IdentifierInfo *Name,
834 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000835 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000836 // Rebuild the template name.
837 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000838 CXXScopeSpec SS;
839 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000841 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000842
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 if (InstName.isNull())
844 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000845
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000846 // If it's still dependent, make a dependent specialization.
847 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000848 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
849 QualifierLoc.getNestedNameSpecifier(),
850 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000851 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000852
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000853 // Otherwise, make an elaborated type wrapping a non-dependent
854 // specialization.
855 QualType T =
856 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
857 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000858
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000859 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
860 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000861
862 return SemaRef.Context.getElaboratedType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000864 T);
865 }
866
Douglas Gregor577f75a2009-08-04 16:50:30 +0000867 /// \brief Build a new typename type that refers to an identifier.
868 ///
869 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000871 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000874 NestedNameSpecifierLoc QualifierLoc,
875 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000877 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000878 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000879
Douglas Gregor2494dd02011-03-01 01:34:45 +0000880 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000881 // If the name is still dependent, just build a new dependent name type.
882 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000883 return SemaRef.Context.getDependentNameType(Keyword,
884 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000885 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000886 }
887
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000888 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000889 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000890 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000891
892 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
893
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000894 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000895 // into a non-dependent elaborated-type-specifier. Find the tag we're
896 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000897 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000898 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
899 if (!DC)
900 return QualType();
901
John McCall56138762010-05-27 06:40:31 +0000902 if (SemaRef.RequireCompleteDeclContext(SS, DC))
903 return QualType();
904
Douglas Gregor40336422010-03-31 22:19:08 +0000905 TagDecl *Tag = 0;
906 SemaRef.LookupQualifiedName(Result, DC);
907 switch (Result.getResultKind()) {
908 case LookupResult::NotFound:
909 case LookupResult::NotFoundInCurrentInstantiation:
910 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000911
Douglas Gregor40336422010-03-31 22:19:08 +0000912 case LookupResult::Found:
913 Tag = Result.getAsSingle<TagDecl>();
914 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000915
Douglas Gregor40336422010-03-31 22:19:08 +0000916 case LookupResult::FoundOverloaded:
917 case LookupResult::FoundUnresolvedValue:
918 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000919
Douglas Gregor40336422010-03-31 22:19:08 +0000920 case LookupResult::Ambiguous:
921 // Let the LookupResult structure handle ambiguities.
922 return QualType();
923 }
924
925 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000926 // Check where the name exists but isn't a tag type and use that to emit
927 // better diagnostics.
928 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
929 SemaRef.LookupQualifiedName(Result, DC);
930 switch (Result.getResultKind()) {
931 case LookupResult::Found:
932 case LookupResult::FoundOverloaded:
933 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000934 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000935 unsigned Kind = 0;
936 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000937 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
938 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000939 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
940 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
941 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000942 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000943 default:
944 // FIXME: Would be nice to highlight just the source range.
945 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
946 << Kind << Id << DC;
947 break;
948 }
Douglas Gregor40336422010-03-31 22:19:08 +0000949 return QualType();
950 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000951
Richard Trieubbf34c02011-06-10 03:11:26 +0000952 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
953 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000954 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000955 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
956 return QualType();
957 }
958
959 // Build the elaborated-type-specifier type.
960 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000961 return SemaRef.Context.getElaboratedType(Keyword,
962 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000963 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000964 }
Mike Stump1eb44332009-09-09 15:08:12 +0000965
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000966 /// \brief Build a new pack expansion type.
967 ///
968 /// By default, builds a new PackExpansionType type from the given pattern.
969 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000970 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000971 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000972 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000973 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000974 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
975 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000976 }
977
Eli Friedmanb001de72011-10-06 23:00:33 +0000978 /// \brief Build a new atomic type given its value type.
979 ///
980 /// By default, performs semantic analysis when building the atomic type.
981 /// Subclasses may override this routine to provide different behavior.
982 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
983
Douglas Gregord1067e52009-08-06 06:41:21 +0000984 /// \brief Build a new template name given a nested name specifier, a flag
985 /// indicating whether the "template" keyword was provided, and the template
986 /// that the template name refers to.
987 ///
988 /// By default, builds the new template name directly. Subclasses may override
989 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000990 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000991 bool TemplateKW,
992 TemplateDecl *Template);
993
Douglas Gregord1067e52009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier and the
995 /// name that is referred to as a template.
996 ///
997 /// By default, performs semantic analysis to determine whether the name can
998 /// be resolved to a specific template, then builds the appropriate kind of
999 /// template name. Subclasses may override this routine to provide different
1000 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001001 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1002 const IdentifierInfo &Name,
1003 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001004 QualType ObjectType,
1005 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001006
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001007 /// \brief Build a new template name given a nested name specifier and the
1008 /// overloaded operator name that is referred to as a template.
1009 ///
1010 /// By default, performs semantic analysis to determine whether the name can
1011 /// be resolved to a specific template, then builds the appropriate kind of
1012 /// template name. Subclasses may override this routine to provide different
1013 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001014 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001015 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001016 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001017 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001018
1019 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001020 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001021 ///
1022 /// By default, performs semantic analysis to determine whether the name can
1023 /// be resolved to a specific template, then builds the appropriate kind of
1024 /// template name. Subclasses may override this routine to provide different
1025 /// behavior.
1026 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1027 const TemplateArgument &ArgPack) {
1028 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1029 }
1030
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 /// \brief Build a new compound statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001035 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 MultiStmtArg Statements,
1037 SourceLocation RBraceLoc,
1038 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001039 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 IsStmtExpr);
1041 }
1042
1043 /// \brief Build a new case statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001047 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001048 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001052 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 ColonLoc);
1054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 /// \brief Attach the body to a new case statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001060 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001061 getSema().ActOnCaseStmtBody(S, Body);
1062 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 /// \brief Build a new default statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001071 Stmt *SubStmt) {
1072 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 /*CurScope=*/0);
1074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 /// \brief Build a new label statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1081 SourceLocation ColonLoc, Stmt *SubStmt) {
1082 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Richard Smith534986f2012-04-14 00:33:13 +00001085 /// \brief Build a new label statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001089 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1090 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001091 Stmt *SubStmt) {
1092 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1093 }
1094
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 /// \brief Build a new "if" statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001099 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001100 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001101 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001102 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 }
Mike Stump1eb44332009-09-09 15:08:12 +00001104
Douglas Gregor43959a92009-08-20 07:17:43 +00001105 /// \brief Start building a new switch statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001109 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001110 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001111 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001112 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 }
Mike Stump1eb44332009-09-09 15:08:12 +00001114
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 /// \brief Attach the body to the switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001120 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001121 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001122 }
1123
1124 /// \brief Build a new while statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001128 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1129 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001130 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001131 }
Mike Stump1eb44332009-09-09 15:08:12 +00001132
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 /// \brief Build a new do-while statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001137 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001138 SourceLocation WhileLoc, SourceLocation LParenLoc,
1139 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001140 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1141 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new for statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001148 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001149 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 VarDecl *CondVar, Sema::FullExprArg Inc,
1151 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001152 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001153 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 }
Mike Stump1eb44332009-09-09 15:08:12 +00001155
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 /// \brief Build a new goto statement.
1157 ///
1158 /// By default, performs semantic analysis to build the new statement.
1159 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001160 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1161 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001162 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001163 }
1164
1165 /// \brief Build a new indirect goto statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001169 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001170 SourceLocation StarLoc,
1171 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001172 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001173 }
Mike Stump1eb44332009-09-09 15:08:12 +00001174
Douglas Gregor43959a92009-08-20 07:17:43 +00001175 /// \brief Build a new return statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001179 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001180 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001181 }
Mike Stump1eb44332009-09-09 15:08:12 +00001182
Douglas Gregor43959a92009-08-20 07:17:43 +00001183 /// \brief Build a new declaration statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001187 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1188 SourceLocation StartLoc, SourceLocation EndLoc) {
1189 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001190 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001191 }
Mike Stump1eb44332009-09-09 15:08:12 +00001192
Anders Carlsson703e3942010-01-24 05:50:09 +00001193 /// \brief Build a new inline asm statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001197 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1198 bool IsVolatile, unsigned NumOutputs,
1199 unsigned NumInputs, IdentifierInfo **Names,
1200 MultiExprArg Constraints, MultiExprArg Exprs,
1201 Expr *AsmString, MultiExprArg Clobbers,
1202 SourceLocation RParenLoc) {
1203 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1204 NumInputs, Names, Constraints, Exprs,
1205 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001206 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001207
Chad Rosier8cd64b42012-06-11 20:47:18 +00001208 /// \brief Build a new MS style inline asm statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001212 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001213 ArrayRef<Token> AsmToks,
1214 StringRef AsmString,
1215 unsigned NumOutputs, unsigned NumInputs,
1216 ArrayRef<StringRef> Constraints,
1217 ArrayRef<StringRef> Clobbers,
1218 ArrayRef<Expr*> Exprs,
1219 SourceLocation EndLoc) {
1220 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1221 NumOutputs, NumInputs,
1222 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001223 }
1224
James Dennett699c9042012-06-15 07:13:21 +00001225 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001231 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001233 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001235 }
1236
Douglas Gregorbe270a02010-04-26 17:57:08 +00001237 /// \brief Rebuild an Objective-C exception declaration.
1238 ///
1239 /// By default, performs semantic analysis to build the new declaration.
1240 /// Subclasses may override this routine to provide different behavior.
1241 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1242 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001243 return getSema().BuildObjCExceptionDecl(TInfo, T,
1244 ExceptionDecl->getInnerLocStart(),
1245 ExceptionDecl->getLocation(),
1246 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001248
James Dennett699c9042012-06-15 07:13:21 +00001249 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001254 SourceLocation RParenLoc,
1255 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001256 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001257 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001258 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001259 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001266 Stmt *Body) {
1267 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001269
James Dennett699c9042012-06-15 07:13:21 +00001270 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001274 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001275 Expr *Operand) {
1276 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001278
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001279 /// \brief Build a new OpenMP parallel directive.
1280 ///
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
1283 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1284 Stmt *AStmt,
1285 SourceLocation StartLoc,
1286 SourceLocation EndLoc) {
1287 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1288 StartLoc, EndLoc);
1289 }
1290
1291 /// \brief Build a new OpenMP 'default' clause.
1292 ///
1293 /// By default, performs semantic analysis to build the new statement.
1294 /// Subclasses may override this routine to provide different behavior.
1295 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1296 SourceLocation KindKwLoc,
1297 SourceLocation StartLoc,
1298 SourceLocation LParenLoc,
1299 SourceLocation EndLoc) {
1300 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1301 StartLoc, LParenLoc, EndLoc);
1302 }
1303
1304 /// \brief Build a new OpenMP 'private' clause.
1305 ///
1306 /// By default, performs semantic analysis to build the new statement.
1307 /// Subclasses may override this routine to provide different behavior.
1308 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1309 SourceLocation StartLoc,
1310 SourceLocation LParenLoc,
1311 SourceLocation EndLoc) {
1312 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1313 EndLoc);
1314 }
1315
Alexey Bataev0c018352013-09-06 18:03:48 +00001316 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1317 SourceLocation StartLoc,
1318 SourceLocation LParenLoc,
1319 SourceLocation EndLoc) {
1320 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1321 EndLoc);
1322 }
1323
James Dennett699c9042012-06-15 07:13:21 +00001324 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
1328 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1329 Expr *object) {
1330 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1331 }
1332
James Dennett699c9042012-06-15 07:13:21 +00001333 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001334 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001335 /// By default, performs semantic analysis to build the new statement.
1336 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001337 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001338 Expr *Object, Stmt *Body) {
1339 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001340 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001341
James Dennett699c9042012-06-15 07:13:21 +00001342 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1347 Stmt *Body) {
1348 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1349 }
John McCall990567c2011-07-27 01:07:15 +00001350
Douglas Gregorc3203e72010-04-22 23:10:45 +00001351 /// \brief Build a new Objective-C fast enumeration statement.
1352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001355 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001356 Stmt *Element,
1357 Expr *Collection,
1358 SourceLocation RParenLoc,
1359 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001360 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001361 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001362 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001363 RParenLoc);
1364 if (ForEachStmt.isInvalid())
1365 return StmtError();
1366
1367 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001369
Douglas Gregor43959a92009-08-20 07:17:43 +00001370 /// \brief Build a new C++ exception declaration.
1371 ///
1372 /// By default, performs semantic analysis to build the new decaration.
1373 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001374 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001375 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001376 SourceLocation StartLoc,
1377 SourceLocation IdLoc,
1378 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001379 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1380 StartLoc, IdLoc, Id);
1381 if (Var)
1382 getSema().CurContext->addDecl(Var);
1383 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001384 }
1385
1386 /// \brief Build a new C++ catch statement.
1387 ///
1388 /// By default, performs semantic analysis to build the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001390 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001391 VarDecl *ExceptionDecl,
1392 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001393 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1394 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001395 }
Mike Stump1eb44332009-09-09 15:08:12 +00001396
Douglas Gregor43959a92009-08-20 07:17:43 +00001397 /// \brief Build a new C++ try statement.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001401 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1402 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001403 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001404 }
Mike Stump1eb44332009-09-09 15:08:12 +00001405
Richard Smithad762fc2011-04-14 22:09:26 +00001406 /// \brief Build a new C++0x range-based for statement.
1407 ///
1408 /// By default, performs semantic analysis to build the new statement.
1409 /// Subclasses may override this routine to provide different behavior.
1410 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1411 SourceLocation ColonLoc,
1412 Stmt *Range, Stmt *BeginEnd,
1413 Expr *Cond, Expr *Inc,
1414 Stmt *LoopVar,
1415 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001416 // If we've just learned that the range is actually an Objective-C
1417 // collection, treat this as an Objective-C fast enumeration loop.
1418 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1419 if (RangeStmt->isSingleDecl()) {
1420 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001421 if (RangeVar->isInvalidDecl())
1422 return StmtError();
1423
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001424 Expr *RangeExpr = RangeVar->getInit();
1425 if (!RangeExpr->isTypeDependent() &&
1426 RangeExpr->getType()->isObjCObjectPointerType())
1427 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1428 RParenLoc);
1429 }
1430 }
1431 }
1432
Richard Smithad762fc2011-04-14 22:09:26 +00001433 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001434 Cond, Inc, LoopVar, RParenLoc,
1435 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001436 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001437
1438 /// \brief Build a new C++0x range-based for statement.
1439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001442 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001443 bool IsIfExists,
1444 NestedNameSpecifierLoc QualifierLoc,
1445 DeclarationNameInfo NameInfo,
1446 Stmt *Nested) {
1447 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1448 QualifierLoc, NameInfo, Nested);
1449 }
1450
Richard Smithad762fc2011-04-14 22:09:26 +00001451 /// \brief Attach body to a C++0x range-based for statement.
1452 ///
1453 /// By default, performs semantic analysis to finish the new statement.
1454 /// Subclasses may override this routine to provide different behavior.
1455 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1456 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1457 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001458
John Wiegley28bbe4b2011-04-28 01:08:34 +00001459 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1460 SourceLocation TryLoc,
1461 Stmt *TryBlock,
1462 Stmt *Handler) {
1463 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1464 }
1465
1466 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1467 Expr *FilterExpr,
1468 Stmt *Block) {
1469 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1470 }
1471
1472 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1473 Stmt *Block) {
1474 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1475 }
1476
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// \brief Build a new expression that references a declaration.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001481 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001482 LookupResult &R,
1483 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001484 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1485 }
1486
1487
1488 /// \brief Build a new expression that references a declaration.
1489 ///
1490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001492 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001493 ValueDecl *VD,
1494 const DeclarationNameInfo &NameInfo,
1495 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001496 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001497 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001498
1499 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001500
1501 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 }
Mike Stump1eb44332009-09-09 15:08:12 +00001503
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001505 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001508 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001510 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
1512
Douglas Gregora71d8192009-09-04 17:36:40 +00001513 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001518 SourceLocation OperatorLoc,
1519 bool isArrow,
1520 CXXScopeSpec &SS,
1521 TypeSourceInfo *ScopeType,
1522 SourceLocation CCLoc,
1523 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001524 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001525
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001527 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001530 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001531 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001532 Expr *SubExpr) {
1533 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 }
Mike Stump1eb44332009-09-09 15:08:12 +00001535
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001536 /// \brief Build a new builtin offsetof expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001540 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001541 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001542 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001543 unsigned NumComponents,
1544 SourceLocation RParenLoc) {
1545 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1546 NumComponents, RParenLoc);
1547 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001548
1549 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001550 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001551 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001554 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1555 SourceLocation OpLoc,
1556 UnaryExprOrTypeTrait ExprKind,
1557 SourceRange R) {
1558 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
1560
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001561 /// \brief Build a new sizeof, alignof or vec step expression with an
1562 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001566 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1567 UnaryExprOrTypeTrait ExprKind,
1568 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001570 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001573
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001574 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
Mike Stump1eb44332009-09-09 15:08:12 +00001576
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001583 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001585 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1586 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 RBracketLoc);
1588 }
1589
1590 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001591 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001594 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001596 SourceLocation RParenLoc,
1597 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001598 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001599 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 }
1601
1602 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001603 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001606 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001607 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001608 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001609 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001610 const DeclarationNameInfo &MemberNameInfo,
1611 ValueDecl *Member,
1612 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001613 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001614 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001615 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1616 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001617 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001618 // We have a reference to an unnamed field. This is always the
1619 // base of an anonymous struct/union member access, i.e. the
1620 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001621 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001622 assert(Member->getType()->isRecordType() &&
1623 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001624
Richard Smith9138b4e2011-10-26 19:06:56 +00001625 BaseResult =
1626 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001627 QualifierLoc.getNestedNameSpecifier(),
1628 FoundDecl, Member);
1629 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001630 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001631 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001632 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001633 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001634 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001635 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001636 cast<FieldDecl>(Member)->getType(),
1637 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001638 return getSema().Owned(ME);
1639 }
Mike Stump1eb44332009-09-09 15:08:12 +00001640
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001641 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001642 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001643
John Wiegley429bb272011-04-08 18:41:53 +00001644 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001645 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001646
John McCall6bb80172010-03-30 21:47:33 +00001647 // FIXME: this involves duplicating earlier analysis in a lot of
1648 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001649 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001650 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001651 R.resolveKind();
1652
John McCall9ae2f072010-08-23 23:25:46 +00001653 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001654 SS, TemplateKWLoc,
1655 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001656 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 }
Mike Stump1eb44332009-09-09 15:08:12 +00001658
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001660 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001663 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001664 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001665 Expr *LHS, Expr *RHS) {
1666 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 }
1668
1669 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001670 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001673 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001674 SourceLocation QuestionLoc,
1675 Expr *LHS,
1676 SourceLocation ColonLoc,
1677 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001678 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1679 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 }
1681
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001683 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001686 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001690 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001699 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001701 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001702 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001703 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
Mike Stump1eb44332009-09-09 15:08:12 +00001705
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 SourceLocation OpLoc,
1712 SourceLocation AccessorLoc,
1713 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001714
John McCall129e2df2009-11-30 22:42:35 +00001715 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001716 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001717 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001718 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001719 SS, SourceLocation(),
1720 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001721 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001722 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001726 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001729 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001730 MultiExprArg Inits,
1731 SourceLocation RBraceLoc,
1732 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001733 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001734 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001735 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001736 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001737
Douglas Gregore48319a2009-11-09 17:16:50 +00001738 // Patch in the result type we were given, which may have been computed
1739 // when the initial InitListExpr was built.
1740 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1741 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001742 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 }
Mike Stump1eb44332009-09-09 15:08:12 +00001744
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001746 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// By default, performs semantic analysis to build the new expression.
1748 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001749 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 MultiExprArg ArrayExprs,
1751 SourceLocation EqualOrColonLoc,
1752 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001753 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001756 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001758 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001759
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001760 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 }
Mike Stump1eb44332009-09-09 15:08:12 +00001762
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001764 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// By default, builds the implicit value initialization without performing
1766 /// any semantic analysis. Subclasses may override this routine to provide
1767 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001768 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1770 }
Mike Stump1eb44332009-09-09 15:08:12 +00001771
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001773 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001778 SourceLocation RParenLoc) {
1779 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001781 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 }
1783
1784 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001785 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001788 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001789 MultiExprArg SubExprs,
1790 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001791 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
Mike Stump1eb44332009-09-09 15:08:12 +00001793
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001795 ///
1796 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 /// rather than attempting to map the label statement itself.
1798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001800 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001801 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001805 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001809 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001811 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 }
Mike Stump1eb44332009-09-09 15:08:12 +00001813
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 /// \brief Build a new __builtin_choose_expr expression.
1815 ///
1816 /// By default, performs semantic analysis to build the new expression.
1817 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001818 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001819 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 SourceLocation RParenLoc) {
1821 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001822 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 RParenLoc);
1824 }
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Peter Collingbournef111d932011-04-15 00:35:48 +00001826 /// \brief Build a new generic selection expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
1830 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1831 SourceLocation DefaultLoc,
1832 SourceLocation RParenLoc,
1833 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001834 ArrayRef<TypeSourceInfo *> Types,
1835 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001836 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001837 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001838 }
1839
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 /// \brief Build a new overloaded operator call expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// The semantic analysis provides the behavior of template instantiation,
1844 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001845 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 /// argument-dependent lookup, etc. Subclasses may override this routine to
1847 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001848 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001850 Expr *Callee,
1851 Expr *First,
1852 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001853
1854 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 /// reinterpret_cast.
1856 ///
1857 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001858 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 Stmt::StmtClass Class,
1862 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001863 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation RAngleLoc,
1865 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001866 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation RParenLoc) {
1868 switch (Class) {
1869 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001870 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001871 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001872 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873
1874 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001875 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001876 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001877 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001878
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001880 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001881 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001882 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001886 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001887 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001888 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001891 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
Mike Stump1eb44332009-09-09 15:08:12 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 /// \brief Build a new C++ static_cast expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001901 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 SourceLocation RAngleLoc,
1903 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001904 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001906 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001907 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001908 SourceRange(LAngleLoc, RAngleLoc),
1909 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
1911
1912 /// \brief Build a new C++ dynamic_cast expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001918 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 SourceLocation RAngleLoc,
1920 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001921 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001923 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001924 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001925 SourceRange(LAngleLoc, RAngleLoc),
1926 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 }
1928
1929 /// \brief Build a new C++ reinterpret_cast expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001933 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001935 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 SourceLocation RAngleLoc,
1937 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001938 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001940 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001941 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001942 SourceRange(LAngleLoc, RAngleLoc),
1943 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 }
1945
1946 /// \brief Build a new C++ const_cast expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001950 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001952 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 SourceLocation RAngleLoc,
1954 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001955 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001957 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001958 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001959 SourceRange(LAngleLoc, RAngleLoc),
1960 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ functional-style cast expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001967 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1968 SourceLocation LParenLoc,
1969 Expr *Sub,
1970 SourceLocation RParenLoc) {
1971 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001972 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 RParenLoc);
1974 }
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 /// \brief Build a new C++ typeid(type) expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001980 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001981 SourceLocation TypeidLoc,
1982 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001984 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001985 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 }
Mike Stump1eb44332009-09-09 15:08:12 +00001987
Francois Pichet01b7c302010-09-08 12:20:18 +00001988
Douglas Gregorb98b1992009-08-11 05:31:07 +00001989 /// \brief Build a new C++ typeid(expr) expression.
1990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001993 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001994 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001995 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001997 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001998 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001999 }
2000
Francois Pichet01b7c302010-09-08 12:20:18 +00002001 /// \brief Build a new C++ __uuidof(type) expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
2005 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2006 SourceLocation TypeidLoc,
2007 TypeSourceInfo *Operand,
2008 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002009 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002010 RParenLoc);
2011 }
2012
2013 /// \brief Build a new C++ __uuidof(expr) expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2018 SourceLocation TypeidLoc,
2019 Expr *Operand,
2020 SourceLocation RParenLoc) {
2021 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2022 RParenLoc);
2023 }
2024
Douglas Gregorb98b1992009-08-11 05:31:07 +00002025 /// \brief Build a new C++ "this" expression.
2026 ///
2027 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002028 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002029 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002030 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002031 QualType ThisType,
2032 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002033 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002035 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2036 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 }
2038
2039 /// \brief Build a new C++ throw expression.
2040 ///
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002043 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2044 bool IsThrownVariableInScope) {
2045 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 }
2047
2048 /// \brief Build a new C++ default-argument expression.
2049 ///
2050 /// By default, builds a new default-argument expression, which does not
2051 /// require any semantic analysis. Subclasses may override this routine to
2052 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002053 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002054 ParmVarDecl *Param) {
2055 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2056 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002057 }
2058
Richard Smithc3bf52c2013-04-20 22:23:05 +00002059 /// \brief Build a new C++11 default-initialization expression.
2060 ///
2061 /// By default, builds a new default field initialization expression, which
2062 /// does not require any semantic analysis. Subclasses may override this
2063 /// routine to provide different behavior.
2064 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2065 FieldDecl *Field) {
2066 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2067 Field));
2068 }
2069
Douglas Gregorb98b1992009-08-11 05:31:07 +00002070 /// \brief Build a new C++ zero-initialization expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002074 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2075 SourceLocation LParenLoc,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002078 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002079 }
Mike Stump1eb44332009-09-09 15:08:12 +00002080
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 /// \brief Build a new C++ "new" expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002085 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002086 bool UseGlobal,
2087 SourceLocation PlacementLParen,
2088 MultiExprArg PlacementArgs,
2089 SourceLocation PlacementRParen,
2090 SourceRange TypeIdParens,
2091 QualType AllocatedType,
2092 TypeSourceInfo *AllocatedTypeInfo,
2093 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002094 SourceRange DirectInitRange,
2095 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002096 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002098 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002100 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002101 AllocatedType,
2102 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002103 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002104 DirectInitRange,
2105 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 }
Mike Stump1eb44332009-09-09 15:08:12 +00002107
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 /// \brief Build a new C++ "delete" expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002112 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 bool IsGlobalDelete,
2114 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002115 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002116 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002117 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002118 }
Mike Stump1eb44332009-09-09 15:08:12 +00002119
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 /// \brief Build a new unary type trait expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002124 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002125 SourceLocation StartLoc,
2126 TypeSourceInfo *T,
2127 SourceLocation RParenLoc) {
2128 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 }
2130
Francois Pichet6ad6f282010-12-07 00:08:36 +00002131 /// \brief Build a new binary type trait expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2136 SourceLocation StartLoc,
2137 TypeSourceInfo *LhsT,
2138 TypeSourceInfo *RhsT,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2141 }
2142
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002143 /// \brief Build a new type trait expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildTypeTrait(TypeTrait Trait,
2148 SourceLocation StartLoc,
2149 ArrayRef<TypeSourceInfo *> Args,
2150 SourceLocation RParenLoc) {
2151 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2152 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002153
John Wiegley21ff2e52011-04-28 00:16:57 +00002154 /// \brief Build a new array type trait expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
2158 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2159 SourceLocation StartLoc,
2160 TypeSourceInfo *TSInfo,
2161 Expr *DimExpr,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2164 }
2165
John Wiegley55262202011-04-25 06:54:41 +00002166 /// \brief Build a new expression trait expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
2170 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2171 SourceLocation StartLoc,
2172 Expr *Queried,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2175 }
2176
Mike Stump1eb44332009-09-09 15:08:12 +00002177 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 /// expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002182 ExprResult RebuildDependentScopeDeclRefExpr(
2183 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002184 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002185 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002186 const TemplateArgumentListInfo *TemplateArgs,
2187 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002189 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002190
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002191 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002192 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002193 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002194
Richard Smithefeeccf2012-10-21 03:28:35 +00002195 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2196 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002197 }
2198
2199 /// \brief Build a new template-id expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002203 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002204 SourceLocation TemplateKWLoc,
2205 LookupResult &R,
2206 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002207 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002208 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2209 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002210 }
2211
2212 /// \brief Build a new object-construction expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002216 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002217 SourceLocation Loc,
2218 CXXConstructorDecl *Constructor,
2219 bool IsElidable,
2220 MultiExprArg Args,
2221 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002222 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002223 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002224 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002225 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002226 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002227 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002228 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002229 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002230
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002231 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002232 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002233 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002234 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002235 RequiresZeroInit, ConstructKind,
2236 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002237 }
2238
2239 /// \brief Build a new object-construction expression.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002243 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2244 SourceLocation LParenLoc,
2245 MultiExprArg Args,
2246 SourceLocation RParenLoc) {
2247 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002248 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002249 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002250 RParenLoc);
2251 }
2252
2253 /// \brief Build a new object-construction expression.
2254 ///
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002257 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2258 SourceLocation LParenLoc,
2259 MultiExprArg Args,
2260 SourceLocation RParenLoc) {
2261 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002262 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002263 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 RParenLoc);
2265 }
Mike Stump1eb44332009-09-09 15:08:12 +00002266
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267 /// \brief Build a new member reference expression.
2268 ///
2269 /// By default, performs semantic analysis to build the new expression.
2270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002271 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002272 QualType BaseType,
2273 bool IsArrow,
2274 SourceLocation OperatorLoc,
2275 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002276 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002277 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002278 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002279 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002281 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002282
John McCall9ae2f072010-08-23 23:25:46 +00002283 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002284 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002285 SS, TemplateKWLoc,
2286 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002287 MemberNameInfo,
2288 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002289 }
2290
John McCall129e2df2009-11-30 22:42:35 +00002291 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002295 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2296 SourceLocation OperatorLoc,
2297 bool IsArrow,
2298 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002299 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002300 NamedDecl *FirstQualifierInScope,
2301 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002302 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002303 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002304 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002305
John McCall9ae2f072010-08-23 23:25:46 +00002306 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002307 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002308 SS, TemplateKWLoc,
2309 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002310 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002311 }
Mike Stump1eb44332009-09-09 15:08:12 +00002312
Sebastian Redl2e156222010-09-10 20:55:43 +00002313 /// \brief Build a new noexcept expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
2317 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2318 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2319 }
2320
Douglas Gregoree8aff02011-01-04 17:33:58 +00002321 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002322 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2323 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002324 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002325 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002326 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002327 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2328 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002329 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330
2331 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2332 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002333 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002334 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002335
Patrick Beardeb382ec2012-04-19 00:25:12 +00002336 /// \brief Build a new Objective-C boxed expression.
2337 ///
2338 /// By default, performs semantic analysis to build the new expression.
2339 /// Subclasses may override this routine to provide different behavior.
2340 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2341 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2342 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002343
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002344 /// \brief Build a new Objective-C array literal.
2345 ///
2346 /// By default, performs semantic analysis to build the new expression.
2347 /// Subclasses may override this routine to provide different behavior.
2348 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2349 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002351 MultiExprArg(Elements, NumElements));
2352 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002353
2354 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002355 Expr *Base, Expr *Key,
2356 ObjCMethodDecl *getterMethod,
2357 ObjCMethodDecl *setterMethod) {
2358 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2359 getterMethod, setterMethod);
2360 }
2361
2362 /// \brief Build a new Objective-C dictionary literal.
2363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
2366 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2367 ObjCDictionaryElement *Elements,
2368 unsigned NumElements) {
2369 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002371
James Dennett699c9042012-06-15 07:13:21 +00002372 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002376 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002377 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002378 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002379 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002380 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002381 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002382
Douglas Gregor92e986e2010-04-22 16:44:27 +00002383 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002384 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002385 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002386 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002387 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002388 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002389 MultiExprArg Args,
2390 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002391 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2392 ReceiverTypeInfo->getType(),
2393 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002394 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002395 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002396 }
2397
2398 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002399 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002400 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002401 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002402 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002404 MultiExprArg Args,
2405 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002406 return SemaRef.BuildInstanceMessage(Receiver,
2407 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002408 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002409 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002410 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002411 }
2412
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002413 /// \brief Build a new Objective-C ivar reference expression.
2414 ///
2415 /// By default, performs semantic analysis to build the new expression.
2416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002417 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002418 SourceLocation IvarLoc,
2419 bool IsArrow, bool IsFreeIvar) {
2420 // FIXME: We lose track of the IsFreeIvar bit.
2421 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002422 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002423 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2424 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002425 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002426 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002427 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002428 false);
John Wiegley429bb272011-04-08 18:41:53 +00002429 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002430 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002431
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002432 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002433 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002434
John Wiegley429bb272011-04-08 18:41:53 +00002435 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002436 /*FIXME:*/IvarLoc, IsArrow,
2437 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002438 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002439 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002440 /*TemplateArgs=*/0);
2441 }
Douglas Gregore3303542010-04-26 20:47:02 +00002442
2443 /// \brief Build a new Objective-C property reference expression.
2444 ///
2445 /// By default, performs semantic analysis to build the new expression.
2446 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002447 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002448 ObjCPropertyDecl *Property,
2449 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002450 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002451 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002452 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2453 Sema::LookupMemberName);
2454 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002455 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002456 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002457 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002458 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002459 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002460
Douglas Gregore3303542010-04-26 20:47:02 +00002461 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002462 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002463
John Wiegley429bb272011-04-08 18:41:53 +00002464 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002465 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002466 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002467 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002468 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002469 /*TemplateArgs=*/0);
2470 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002471
John McCall12f78a62010-12-02 01:19:52 +00002472 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002473 ///
2474 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002475 /// Subclasses may override this routine to provide different behavior.
2476 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2477 ObjCMethodDecl *Getter,
2478 ObjCMethodDecl *Setter,
2479 SourceLocation PropertyLoc) {
2480 // Since these expressions can only be value-dependent, we do not
2481 // need to perform semantic analysis again.
2482 return Owned(
2483 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2484 VK_LValue, OK_ObjCProperty,
2485 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002486 }
2487
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002488 /// \brief Build a new Objective-C "isa" expression.
2489 ///
2490 /// By default, performs semantic analysis to build the new expression.
2491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002492 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002493 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002494 bool IsArrow) {
2495 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002496 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002497 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2498 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002499 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002500 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002501 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002502 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002503 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002504
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002505 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002506 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002507
John Wiegley429bb272011-04-08 18:41:53 +00002508 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002509 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002510 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002511 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002512 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002513 /*TemplateArgs=*/0);
2514 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002515
Douglas Gregorb98b1992009-08-11 05:31:07 +00002516 /// \brief Build a new shuffle vector expression.
2517 ///
2518 /// By default, performs semantic analysis to build the new expression.
2519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002520 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002521 MultiExprArg SubExprs,
2522 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002523 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002524 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002525 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2526 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2527 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002528 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002529
Douglas Gregorb98b1992009-08-11 05:31:07 +00002530 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002531 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002532 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2533 SemaRef.Context.BuiltinFnTy,
2534 VK_RValue, BuiltinLoc);
2535 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2536 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2537 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002538
2539 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002540 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002541 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002542 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002543 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002544 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002545
Douglas Gregorb98b1992009-08-11 05:31:07 +00002546 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002547 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002548 }
John McCall43fed0d2010-11-12 08:19:04 +00002549
Hal Finkel414a1bd2013-09-18 03:29:45 +00002550 /// \brief Build a new convert vector expression.
2551 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2552 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2553 SourceLocation RParenLoc) {
2554 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2555 BuiltinLoc, RParenLoc);
2556 }
2557
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002558 /// \brief Build a new template argument pack expansion.
2559 ///
2560 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002561 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002562 /// different behavior.
2563 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002564 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002565 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002566 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002567 case TemplateArgument::Expression: {
2568 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002569 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2570 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002571 if (Result.isInvalid())
2572 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002573
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002574 return TemplateArgumentLoc(Result.get(), Result.get());
2575 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002576
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002577 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002578 return TemplateArgumentLoc(TemplateArgument(
2579 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002580 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002581 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002582 Pattern.getTemplateNameLoc(),
2583 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002584
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002585 case TemplateArgument::Null:
2586 case TemplateArgument::Integral:
2587 case TemplateArgument::Declaration:
2588 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002589 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002590 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002591 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002592
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002593 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002594 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002595 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002596 EllipsisLoc,
2597 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002598 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2599 Expansion);
2600 break;
2601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002602
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002603 return TemplateArgumentLoc();
2604 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002605
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002606 /// \brief Build a new expression pack expansion.
2607 ///
2608 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002610 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002611 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002612 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002613 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002614 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002615
2616 /// \brief Build a new atomic operation expression.
2617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
2620 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2621 MultiExprArg SubExprs,
2622 QualType RetTy,
2623 AtomicExpr::AtomicOp Op,
2624 SourceLocation RParenLoc) {
2625 // Just create the expression; there is not any interesting semantic
2626 // analysis here because we can't actually build an AtomicExpr until
2627 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002628 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002629 RParenLoc);
2630 }
2631
John McCall43fed0d2010-11-12 08:19:04 +00002632private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002633 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2634 QualType ObjectType,
2635 NamedDecl *FirstQualifierInScope,
2636 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002637
2638 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2639 QualType ObjectType,
2640 NamedDecl *FirstQualifierInScope,
2641 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002642};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002643
Douglas Gregor43959a92009-08-20 07:17:43 +00002644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002645StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002646 if (!S)
2647 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002648
Douglas Gregor43959a92009-08-20 07:17:43 +00002649 switch (S->getStmtClass()) {
2650 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002651
Douglas Gregor43959a92009-08-20 07:17:43 +00002652 // Transform individual statement nodes
2653#define STMT(Node, Parent) \
2654 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002655#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002656#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002657#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002658
Douglas Gregor43959a92009-08-20 07:17:43 +00002659 // Transform expressions by calling TransformExpr.
2660#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002661#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002662#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002663#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002664 {
John McCall60d7b3a2010-08-24 06:29:42 +00002665 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002666 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002667 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002668
Richard Smith41956372013-01-14 22:39:08 +00002669 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002670 }
Mike Stump1eb44332009-09-09 15:08:12 +00002671 }
2672
John McCall3fa5cae2010-10-26 07:05:15 +00002673 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002674}
Mike Stump1eb44332009-09-09 15:08:12 +00002675
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002676template<typename Derived>
2677OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2678 if (!S)
2679 return S;
2680
2681 switch (S->getClauseKind()) {
2682 default: break;
2683 // Transform individual clause nodes
2684#define OPENMP_CLAUSE(Name, Class) \
2685 case OMPC_ ## Name : \
2686 return getDerived().Transform ## Class(cast<Class>(S));
2687#include "clang/Basic/OpenMPKinds.def"
2688 }
2689
2690 return S;
2691}
2692
Mike Stump1eb44332009-09-09 15:08:12 +00002693
Douglas Gregor670444e2009-08-04 22:27:00 +00002694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002695ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002696 if (!E)
2697 return SemaRef.Owned(E);
2698
2699 switch (E->getStmtClass()) {
2700 case Stmt::NoStmtClass: break;
2701#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002702#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002703#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002704 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002705#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002706 }
2707
John McCall3fa5cae2010-10-26 07:05:15 +00002708 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002709}
2710
2711template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002712ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2713 bool CXXDirectInit) {
2714 // Initializers are instantiated like expressions, except that various outer
2715 // layers are stripped.
2716 if (!Init)
2717 return SemaRef.Owned(Init);
2718
2719 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2720 Init = ExprTemp->getSubExpr();
2721
Richard Smith858c2c32013-05-30 22:40:16 +00002722 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2723 Init = MTE->GetTemporaryExpr();
2724
Richard Smithc83c2302012-12-19 01:39:02 +00002725 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2726 Init = Binder->getSubExpr();
2727
2728 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2729 Init = ICE->getSubExprAsWritten();
2730
Richard Smith7c3e6152013-06-12 22:31:48 +00002731 if (CXXStdInitializerListExpr *ILE =
2732 dyn_cast<CXXStdInitializerListExpr>(Init))
2733 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2734
Richard Smith5cf15892012-12-21 08:13:35 +00002735 // If this is not a direct-initializer, we only need to reconstruct
2736 // InitListExprs. Other forms of copy-initialization will be a no-op if
2737 // the initializer is already the right type.
2738 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2739 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2740 return getDerived().TransformExpr(Init);
2741
2742 // Revert value-initialization back to empty parens.
2743 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2744 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002745 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002746 Parens.getEnd());
2747 }
2748
2749 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2750 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002751 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002752 SourceLocation());
2753
2754 // Revert initialization by constructor back to a parenthesized or braced list
2755 // of expressions. Any other form of initializer can just be reused directly.
2756 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002757 return getDerived().TransformExpr(Init);
2758
2759 SmallVector<Expr*, 8> NewArgs;
2760 bool ArgChanged = false;
2761 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2762 /*IsCall*/true, NewArgs, &ArgChanged))
2763 return ExprError();
2764
2765 // If this was list initialization, revert to list form.
2766 if (Construct->isListInitialization())
2767 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2768 Construct->getLocEnd(),
2769 Construct->getType());
2770
Richard Smithc83c2302012-12-19 01:39:02 +00002771 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002772 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002773 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2774 Parens.getEnd());
2775}
2776
2777template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002778bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2779 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002780 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002781 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002782 bool *ArgChanged) {
2783 for (unsigned I = 0; I != NumInputs; ++I) {
2784 // If requested, drop call arguments that need to be dropped.
2785 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2786 if (ArgChanged)
2787 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002788
Douglas Gregoraa165f82011-01-03 19:04:46 +00002789 break;
2790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002792 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2793 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002794
Chris Lattner686775d2011-07-20 06:58:45 +00002795 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002796 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2797 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002799 // Determine whether the set of unexpanded parameter packs can and should
2800 // be expanded.
2801 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002802 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002803 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2804 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002805 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2806 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002807 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002808 Expand, RetainExpansion,
2809 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002810 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002811
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002812 if (!Expand) {
2813 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002814 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002815 // expansion.
2816 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2817 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2818 if (OutPattern.isInvalid())
2819 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002820
2821 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002822 Expansion->getEllipsisLoc(),
2823 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002824 if (Out.isInvalid())
2825 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002827 if (ArgChanged)
2828 *ArgChanged = true;
2829 Outputs.push_back(Out.get());
2830 continue;
2831 }
John McCallc8fc90a2011-07-06 07:30:07 +00002832
2833 // Record right away that the argument was changed. This needs
2834 // to happen even if the array expands to nothing.
2835 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002837 // The transform has determined that we should perform an elementwise
2838 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002839 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002840 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2841 ExprResult Out = getDerived().TransformExpr(Pattern);
2842 if (Out.isInvalid())
2843 return true;
2844
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002845 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002846 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2847 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002848 if (Out.isInvalid())
2849 return true;
2850 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002851
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002852 Outputs.push_back(Out.get());
2853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002854
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002855 continue;
2856 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857
Richard Smithc83c2302012-12-19 01:39:02 +00002858 ExprResult Result =
2859 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2860 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002861 if (Result.isInvalid())
2862 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002863
Douglas Gregoraa165f82011-01-03 19:04:46 +00002864 if (Result.get() != Inputs[I] && ArgChanged)
2865 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866
2867 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Douglas Gregoraa165f82011-01-03 19:04:46 +00002870 return false;
2871}
2872
2873template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002874NestedNameSpecifierLoc
2875TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2876 NestedNameSpecifierLoc NNS,
2877 QualType ObjectType,
2878 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002879 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002881 Qualifier = Qualifier.getPrefix())
2882 Qualifiers.push_back(Qualifier);
2883
2884 CXXScopeSpec SS;
2885 while (!Qualifiers.empty()) {
2886 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2887 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002888
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002889 switch (QNNS->getKind()) {
2890 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002892 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002893 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002894 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002896 FirstQualifierInScope, false))
2897 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002901 case NestedNameSpecifier::Namespace: {
2902 NamespaceDecl *NS
2903 = cast_or_null<NamespaceDecl>(
2904 getDerived().TransformDecl(
2905 Q.getLocalBeginLoc(),
2906 QNNS->getAsNamespace()));
2907 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2908 break;
2909 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002911 case NestedNameSpecifier::NamespaceAlias: {
2912 NamespaceAliasDecl *Alias
2913 = cast_or_null<NamespaceAliasDecl>(
2914 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2915 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002917 Q.getLocalEndLoc());
2918 break;
2919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002920
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002921 case NestedNameSpecifier::Global:
2922 // There is no meaningful transformation that one could perform on the
2923 // global scope.
2924 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2925 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002926
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002927 case NestedNameSpecifier::TypeSpecWithTemplate:
2928 case NestedNameSpecifier::TypeSpec: {
2929 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2930 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002931
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002932 if (!TL)
2933 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002935 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002936 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002937 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002940 if (TL.getType()->isEnumeralType())
2941 SemaRef.Diag(TL.getBeginLoc(),
2942 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002943 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2944 Q.getLocalEndLoc());
2945 break;
2946 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002947 // If the nested-name-specifier is an invalid type def, don't emit an
2948 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002949 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2950 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002952 << TL.getType() << SS.getRange();
2953 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002954 return NestedNameSpecifierLoc();
2955 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002957
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002958 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002959 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002960 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002961 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002962
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002963 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002965 !getDerived().AlwaysRebuild())
2966 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967
2968 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002969 // nested-name-specifier, do so.
2970 if (SS.location_size() == NNS.getDataLength() &&
2971 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2972 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2973
2974 // Allocate new nested-name-specifier location information.
2975 return SS.getWithLocInContext(SemaRef.Context);
2976}
2977
2978template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002979DeclarationNameInfo
2980TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002981::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002982 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002983 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002984 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002985
2986 switch (Name.getNameKind()) {
2987 case DeclarationName::Identifier:
2988 case DeclarationName::ObjCZeroArgSelector:
2989 case DeclarationName::ObjCOneArgSelector:
2990 case DeclarationName::ObjCMultiArgSelector:
2991 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002992 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002993 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002994 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002995
Douglas Gregor81499bb2009-09-03 22:13:48 +00002996 case DeclarationName::CXXConstructorName:
2997 case DeclarationName::CXXDestructorName:
2998 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002999 TypeSourceInfo *NewTInfo;
3000 CanQualType NewCanTy;
3001 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003002 NewTInfo = getDerived().TransformType(OldTInfo);
3003 if (!NewTInfo)
3004 return DeclarationNameInfo();
3005 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003006 }
3007 else {
3008 NewTInfo = 0;
3009 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003010 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003011 if (NewT.isNull())
3012 return DeclarationNameInfo();
3013 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3014 }
Mike Stump1eb44332009-09-09 15:08:12 +00003015
Abramo Bagnara25777432010-08-11 22:01:17 +00003016 DeclarationName NewName
3017 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3018 NewCanTy);
3019 DeclarationNameInfo NewNameInfo(NameInfo);
3020 NewNameInfo.setName(NewName);
3021 NewNameInfo.setNamedTypeInfo(NewTInfo);
3022 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003023 }
Mike Stump1eb44332009-09-09 15:08:12 +00003024 }
3025
David Blaikieb219cfc2011-09-23 05:06:16 +00003026 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003027}
3028
3029template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003030TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003031TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3032 TemplateName Name,
3033 SourceLocation NameLoc,
3034 QualType ObjectType,
3035 NamedDecl *FirstQualifierInScope) {
3036 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3037 TemplateDecl *Template = QTN->getTemplateDecl();
3038 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003039
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003040 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003042 Template));
3043 if (!TransTemplate)
3044 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003045
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003046 if (!getDerived().AlwaysRebuild() &&
3047 SS.getScopeRep() == QTN->getQualifier() &&
3048 TransTemplate == Template)
3049 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003051 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3052 TransTemplate);
3053 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003054
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003055 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3056 if (SS.getScopeRep()) {
3057 // These apply to the scope specifier, not the template.
3058 ObjectType = QualType();
3059 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003060 }
3061
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003062 if (!getDerived().AlwaysRebuild() &&
3063 SS.getScopeRep() == DTN->getQualifier() &&
3064 ObjectType.isNull())
3065 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003066
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003067 if (DTN->isIdentifier()) {
3068 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003069 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003070 NameLoc,
3071 ObjectType,
3072 FirstQualifierInScope);
3073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003074
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003075 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3076 ObjectType);
3077 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003079 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3080 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003081 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003082 Template));
3083 if (!TransTemplate)
3084 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003086 if (!getDerived().AlwaysRebuild() &&
3087 TransTemplate == Template)
3088 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003089
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003090 return TemplateName(TransTemplate);
3091 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003093 if (SubstTemplateTemplateParmPackStorage *SubstPack
3094 = Name.getAsSubstTemplateTemplateParmPack()) {
3095 TemplateTemplateParmDecl *TransParam
3096 = cast_or_null<TemplateTemplateParmDecl>(
3097 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3098 if (!TransParam)
3099 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003100
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003101 if (!getDerived().AlwaysRebuild() &&
3102 TransParam == SubstPack->getParameterPack())
3103 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
3105 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003106 SubstPack->getArgumentPack());
3107 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003109 // These should be getting filtered out before they reach the AST.
3110 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003111}
3112
3113template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003114void TreeTransform<Derived>::InventTemplateArgumentLoc(
3115 const TemplateArgument &Arg,
3116 TemplateArgumentLoc &Output) {
3117 SourceLocation Loc = getDerived().getBaseLocation();
3118 switch (Arg.getKind()) {
3119 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003120 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003121 break;
3122
3123 case TemplateArgument::Type:
3124 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003125 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
John McCall833ca992009-10-29 08:12:44 +00003127 break;
3128
Douglas Gregor788cd062009-11-11 01:00:40 +00003129 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003130 case TemplateArgument::TemplateExpansion: {
3131 NestedNameSpecifierLocBuilder Builder;
3132 TemplateName Template = Arg.getAsTemplate();
3133 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3134 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3135 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3136 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003138 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003139 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003140 Builder.getWithLocInContext(SemaRef.Context),
3141 Loc);
3142 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003144 Builder.getWithLocInContext(SemaRef.Context),
3145 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor788cd062009-11-11 01:00:40 +00003147 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003148 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003149
John McCall833ca992009-10-29 08:12:44 +00003150 case TemplateArgument::Expression:
3151 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3152 break;
3153
3154 case TemplateArgument::Declaration:
3155 case TemplateArgument::Integral:
3156 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003157 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003158 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003159 break;
3160 }
3161}
3162
3163template<typename Derived>
3164bool TreeTransform<Derived>::TransformTemplateArgument(
3165 const TemplateArgumentLoc &Input,
3166 TemplateArgumentLoc &Output) {
3167 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003168 switch (Arg.getKind()) {
3169 case TemplateArgument::Null:
3170 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003171 case TemplateArgument::Pack:
3172 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003173 case TemplateArgument::NullPtr:
3174 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003175
Douglas Gregor670444e2009-08-04 22:27:00 +00003176 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003177 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003178 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003179 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003180
3181 DI = getDerived().TransformType(DI);
3182 if (!DI) return true;
3183
3184 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3185 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003186 }
Mike Stump1eb44332009-09-09 15:08:12 +00003187
Douglas Gregor788cd062009-11-11 01:00:40 +00003188 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003189 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3190 if (QualifierLoc) {
3191 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3192 if (!QualifierLoc)
3193 return true;
3194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003195
Douglas Gregor1d752d72011-03-02 18:46:51 +00003196 CXXScopeSpec SS;
3197 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003198 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003199 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3200 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003201 if (Template.isNull())
3202 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003203
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003204 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003205 Input.getTemplateNameLoc());
3206 return false;
3207 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003208
3209 case TemplateArgument::TemplateExpansion:
3210 llvm_unreachable("Caller should expand pack expansions");
3211
Douglas Gregor670444e2009-08-04 22:27:00 +00003212 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003213 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003214 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003215 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003216
John McCall833ca992009-10-29 08:12:44 +00003217 Expr *InputExpr = Input.getSourceExpression();
3218 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3219
Chris Lattner223de242011-04-25 20:37:58 +00003220 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003221 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003222 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003223 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003224 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003225 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003226 }
Mike Stump1eb44332009-09-09 15:08:12 +00003227
Douglas Gregor670444e2009-08-04 22:27:00 +00003228 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003229 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003230}
3231
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003232/// \brief Iterator adaptor that invents template argument location information
3233/// for each of the template arguments in its underlying iterator.
3234template<typename Derived, typename InputIterator>
3235class TemplateArgumentLocInventIterator {
3236 TreeTransform<Derived> &Self;
3237 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003239public:
3240 typedef TemplateArgumentLoc value_type;
3241 typedef TemplateArgumentLoc reference;
3242 typedef typename std::iterator_traits<InputIterator>::difference_type
3243 difference_type;
3244 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003246 class pointer {
3247 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003249 public:
3250 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003252 const TemplateArgumentLoc *operator->() const { return &Arg; }
3253 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003255 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003257 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3258 InputIterator Iter)
3259 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003261 TemplateArgumentLocInventIterator &operator++() {
3262 ++Iter;
3263 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003266 TemplateArgumentLocInventIterator operator++(int) {
3267 TemplateArgumentLocInventIterator Old(*this);
3268 ++(*this);
3269 return Old;
3270 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003271
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003272 reference operator*() const {
3273 TemplateArgumentLoc Result;
3274 Self.InventTemplateArgumentLoc(*Iter, Result);
3275 return Result;
3276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003278 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003279
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003280 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3281 const TemplateArgumentLocInventIterator &Y) {
3282 return X.Iter == Y.Iter;
3283 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003284
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003285 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3286 const TemplateArgumentLocInventIterator &Y) {
3287 return X.Iter != Y.Iter;
3288 }
3289};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003291template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003292template<typename InputIterator>
3293bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3294 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003295 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003296 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003297 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003298 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003299
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003300 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3301 // Unpack argument packs, which we translate them into separate
3302 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003303 // FIXME: We could do much better if we could guarantee that the
3304 // TemplateArgumentLocInfo for the pack expansion would be usable for
3305 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003307 TemplateArgument::pack_iterator>
3308 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003310 In.getArgument().pack_begin()),
3311 PackLocIterator(*this,
3312 In.getArgument().pack_end()),
3313 Outputs))
3314 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003315
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003316 continue;
3317 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003318
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003319 if (In.getArgument().isPackExpansion()) {
3320 // We have a pack expansion, for which we will be substituting into
3321 // the pattern.
3322 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003323 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003324 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003325 = getSema().getTemplateArgumentPackExpansionPattern(
3326 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003327
Chris Lattner686775d2011-07-20 06:58:45 +00003328 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003329 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3330 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003332 // Determine whether the set of unexpanded parameter packs can and should
3333 // be expanded.
3334 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003335 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003336 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003337 if (getDerived().TryExpandParameterPacks(Ellipsis,
3338 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003339 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003340 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003341 RetainExpansion,
3342 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003343 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003345 if (!Expand) {
3346 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003347 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003348 // expansion.
3349 TemplateArgumentLoc OutPattern;
3350 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3351 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3352 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003353
Douglas Gregorcded4f62011-01-14 17:04:44 +00003354 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3355 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003356 if (Out.getArgument().isNull())
3357 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003359 Outputs.addArgument(Out);
3360 continue;
3361 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003362
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003363 // The transform has determined that we should perform an elementwise
3364 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003365 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003366 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3367
3368 if (getDerived().TransformTemplateArgument(Pattern, Out))
3369 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003371 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003372 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3373 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003374 if (Out.getArgument().isNull())
3375 return true;
3376 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003378 Outputs.addArgument(Out);
3379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003380
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003381 // If we're supposed to retain a pack expansion, do so by temporarily
3382 // forgetting the partially-substituted parameter pack.
3383 if (RetainExpansion) {
3384 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003385
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003386 if (getDerived().TransformTemplateArgument(Pattern, Out))
3387 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003388
Douglas Gregorcded4f62011-01-14 17:04:44 +00003389 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3390 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003391 if (Out.getArgument().isNull())
3392 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003394 Outputs.addArgument(Out);
3395 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003397 continue;
3398 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399
3400 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003401 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003402 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003404 Outputs.addArgument(Out);
3405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003407 return false;
3408
3409}
3410
Douglas Gregor577f75a2009-08-04 16:50:30 +00003411//===----------------------------------------------------------------------===//
3412// Type transformation
3413//===----------------------------------------------------------------------===//
3414
3415template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003416QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003417 if (getDerived().AlreadyTransformed(T))
3418 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003419
John McCalla2becad2009-10-21 00:40:46 +00003420 // Temporary workaround. All of these transformations should
3421 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003422 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3423 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003424
John McCall43fed0d2010-11-12 08:19:04 +00003425 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003426
John McCalla2becad2009-10-21 00:40:46 +00003427 if (!NewDI)
3428 return QualType();
3429
3430 return NewDI->getType();
3431}
3432
3433template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003434TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003435 // Refine the base location to the type's location.
3436 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3437 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003438 if (getDerived().AlreadyTransformed(DI->getType()))
3439 return DI;
3440
3441 TypeLocBuilder TLB;
3442
3443 TypeLoc TL = DI->getTypeLoc();
3444 TLB.reserve(TL.getFullDataSize());
3445
John McCall43fed0d2010-11-12 08:19:04 +00003446 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003447 if (Result.isNull())
3448 return 0;
3449
John McCalla93c9342009-12-07 02:54:59 +00003450 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003451}
3452
3453template<typename Derived>
3454QualType
John McCall43fed0d2010-11-12 08:19:04 +00003455TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003456 switch (T.getTypeLocClass()) {
3457#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003458#define TYPELOC(CLASS, PARENT) \
3459 case TypeLoc::CLASS: \
3460 return getDerived().Transform##CLASS##Type(TLB, \
3461 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003462#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003463 }
Mike Stump1eb44332009-09-09 15:08:12 +00003464
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003465 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003466}
3467
3468/// FIXME: By default, this routine adds type qualifiers only to types
3469/// that can have qualifiers, and silently suppresses those qualifiers
3470/// that are not permitted (e.g., qualifiers on reference or function
3471/// types). This is the right thing for template instantiation, but
3472/// probably not for other clients.
3473template<typename Derived>
3474QualType
3475TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003476 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003477 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003478
John McCall43fed0d2010-11-12 08:19:04 +00003479 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003480 if (Result.isNull())
3481 return QualType();
3482
3483 // Silently suppress qualifiers if the result type can't be qualified.
3484 // FIXME: this is the right thing for template instantiation, but
3485 // probably not for other clients.
3486 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003487 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003488
John McCallf85e1932011-06-15 23:02:42 +00003489 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003490 // resulting type.
3491 if (Quals.hasObjCLifetime()) {
3492 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3493 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003494 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003496 // A lifetime qualifier applied to a substituted template parameter
3497 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003498 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003500 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3501 QualType Replacement = SubstTypeParam->getReplacementType();
3502 Qualifiers Qs = Replacement.getQualifiers();
3503 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003505 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3506 Qs);
3507 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003508 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003509 Replacement);
3510 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003511 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3512 // 'auto' types behave the same way as template parameters.
3513 QualType Deduced = AutoTy->getDeducedType();
3514 Qualifiers Qs = Deduced.getQualifiers();
3515 Qs.removeObjCLifetime();
3516 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3517 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003518 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3519 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003520 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003521 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003522 // Otherwise, complain about the addition of a qualifier to an
3523 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003524 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003525 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003526 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003527
Douglas Gregore559ca12011-06-17 22:11:49 +00003528 Quals.removeObjCLifetime();
3529 }
3530 }
3531 }
John McCall28654742010-06-05 06:41:15 +00003532 if (!Quals.empty()) {
3533 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003534 // BuildQualifiedType might not add qualifiers if they are invalid.
3535 if (Result.hasLocalQualifiers())
3536 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003537 // No location information to preserve.
3538 }
John McCalla2becad2009-10-21 00:40:46 +00003539
3540 return Result;
3541}
3542
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003543template<typename Derived>
3544TypeLoc
3545TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3546 QualType ObjectType,
3547 NamedDecl *UnqualLookup,
3548 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003549 QualType T = TL.getType();
3550 if (getDerived().AlreadyTransformed(T))
3551 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003552
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003553 TypeLocBuilder TLB;
3554 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003556 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003557 TemplateSpecializationTypeLoc SpecTL =
3558 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003560 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003561 getDerived().TransformTemplateName(SS,
3562 SpecTL.getTypePtr()->getTemplateName(),
3563 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003564 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003565 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003566 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003567
3568 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003569 Template);
3570 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003571 DependentTemplateSpecializationTypeLoc SpecTL =
3572 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003573
Douglas Gregora88f09f2011-02-28 17:23:35 +00003574 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575 = getDerived().RebuildTemplateName(SS,
3576 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003577 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003578 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003579 if (Template.isNull())
3580 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003581
3582 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003583 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003584 Template,
3585 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003586 } else {
3587 // Nothing special needs to be done for these.
3588 Result = getDerived().TransformType(TLB, TL);
3589 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003590
3591 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003592 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003594 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3595}
3596
Douglas Gregorb71d8212011-03-02 18:32:08 +00003597template<typename Derived>
3598TypeSourceInfo *
3599TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3600 QualType ObjectType,
3601 NamedDecl *UnqualLookup,
3602 CXXScopeSpec &SS) {
3603 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003604
Douglas Gregorb71d8212011-03-02 18:32:08 +00003605 QualType T = TSInfo->getType();
3606 if (getDerived().AlreadyTransformed(T))
3607 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003608
Douglas Gregorb71d8212011-03-02 18:32:08 +00003609 TypeLocBuilder TLB;
3610 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611
Douglas Gregorb71d8212011-03-02 18:32:08 +00003612 TypeLoc TL = TSInfo->getTypeLoc();
3613 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003614 TemplateSpecializationTypeLoc SpecTL =
3615 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003616
Douglas Gregorb71d8212011-03-02 18:32:08 +00003617 TemplateName Template
3618 = getDerived().TransformTemplateName(SS,
3619 SpecTL.getTypePtr()->getTemplateName(),
3620 SpecTL.getTemplateNameLoc(),
3621 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003622 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003623 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003624
3625 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003626 Template);
3627 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003628 DependentTemplateSpecializationTypeLoc SpecTL =
3629 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003630
Douglas Gregorb71d8212011-03-02 18:32:08 +00003631 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003632 = getDerived().RebuildTemplateName(SS,
3633 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003634 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003635 ObjectType, UnqualLookup);
3636 if (Template.isNull())
3637 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003638
3639 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003640 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003641 Template,
3642 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003643 } else {
3644 // Nothing special needs to be done for these.
3645 Result = getDerived().TransformType(TLB, TL);
3646 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003647
3648 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003649 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003650
Douglas Gregorb71d8212011-03-02 18:32:08 +00003651 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3652}
3653
John McCalla2becad2009-10-21 00:40:46 +00003654template <class TyLoc> static inline
3655QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3656 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3657 NewT.setNameLoc(T.getNameLoc());
3658 return T.getType();
3659}
3660
John McCalla2becad2009-10-21 00:40:46 +00003661template<typename Derived>
3662QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003663 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003664 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3665 NewT.setBuiltinLoc(T.getBuiltinLoc());
3666 if (T.needsExtraLocalData())
3667 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3668 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669}
Mike Stump1eb44332009-09-09 15:08:12 +00003670
Douglas Gregor577f75a2009-08-04 16:50:30 +00003671template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003672QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003673 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003674 // FIXME: recurse?
3675 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
Mike Stump1eb44332009-09-09 15:08:12 +00003677
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003679QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3680 DecayedTypeLoc TL) {
3681 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3682 if (OriginalType.isNull())
3683 return QualType();
3684
3685 QualType Result = TL.getType();
3686 if (getDerived().AlwaysRebuild() ||
3687 OriginalType != TL.getOriginalLoc().getType())
3688 Result = SemaRef.Context.getDecayedType(OriginalType);
3689 TLB.push<DecayedTypeLoc>(Result);
3690 // Nothing to set for DecayedTypeLoc.
3691 return Result;
3692}
3693
3694template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003695QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003696 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003697 QualType PointeeType
3698 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003699 if (PointeeType.isNull())
3700 return QualType();
3701
3702 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003703 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003704 // A dependent pointer type 'T *' has is being transformed such
3705 // that an Objective-C class type is being replaced for 'T'. The
3706 // resulting pointer type is an ObjCObjectPointerType, not a
3707 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003708 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003709
John McCallc12c5bb2010-05-15 11:32:37 +00003710 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3711 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003712 return Result;
3713 }
John McCall43fed0d2010-11-12 08:19:04 +00003714
Douglas Gregor92e986e2010-04-22 16:44:27 +00003715 if (getDerived().AlwaysRebuild() ||
3716 PointeeType != TL.getPointeeLoc().getType()) {
3717 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3718 if (Result.isNull())
3719 return QualType();
3720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003721
John McCallf85e1932011-06-15 23:02:42 +00003722 // Objective-C ARC can add lifetime qualifiers to the type that we're
3723 // pointing to.
3724 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003725
Douglas Gregor92e986e2010-04-22 16:44:27 +00003726 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3727 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003728 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729}
Mike Stump1eb44332009-09-09 15:08:12 +00003730
3731template<typename Derived>
3732QualType
John McCalla2becad2009-10-21 00:40:46 +00003733TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003734 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003735 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003736 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3737 if (PointeeType.isNull())
3738 return QualType();
3739
3740 QualType Result = TL.getType();
3741 if (getDerived().AlwaysRebuild() ||
3742 PointeeType != TL.getPointeeLoc().getType()) {
3743 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003744 TL.getSigilLoc());
3745 if (Result.isNull())
3746 return QualType();
3747 }
3748
Douglas Gregor39968ad2010-04-22 16:50:51 +00003749 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003750 NewT.setSigilLoc(TL.getSigilLoc());
3751 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003752}
3753
John McCall85737a72009-10-30 00:06:24 +00003754/// Transforms a reference type. Note that somewhat paradoxically we
3755/// don't care whether the type itself is an l-value type or an r-value
3756/// type; we only care if the type was *written* as an l-value type
3757/// or an r-value type.
3758template<typename Derived>
3759QualType
3760TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003761 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003762 const ReferenceType *T = TL.getTypePtr();
3763
3764 // Note that this works with the pointee-as-written.
3765 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3766 if (PointeeType.isNull())
3767 return QualType();
3768
3769 QualType Result = TL.getType();
3770 if (getDerived().AlwaysRebuild() ||
3771 PointeeType != T->getPointeeTypeAsWritten()) {
3772 Result = getDerived().RebuildReferenceType(PointeeType,
3773 T->isSpelledAsLValue(),
3774 TL.getSigilLoc());
3775 if (Result.isNull())
3776 return QualType();
3777 }
3778
John McCallf85e1932011-06-15 23:02:42 +00003779 // Objective-C ARC can add lifetime qualifiers to the type that we're
3780 // referring to.
3781 TLB.TypeWasModifiedSafely(
3782 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3783
John McCall85737a72009-10-30 00:06:24 +00003784 // r-value references can be rebuilt as l-value references.
3785 ReferenceTypeLoc NewTL;
3786 if (isa<LValueReferenceType>(Result))
3787 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3788 else
3789 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3790 NewTL.setSigilLoc(TL.getSigilLoc());
3791
3792 return Result;
3793}
3794
Mike Stump1eb44332009-09-09 15:08:12 +00003795template<typename Derived>
3796QualType
John McCalla2becad2009-10-21 00:40:46 +00003797TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003798 LValueReferenceTypeLoc TL) {
3799 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003800}
3801
Mike Stump1eb44332009-09-09 15:08:12 +00003802template<typename Derived>
3803QualType
John McCalla2becad2009-10-21 00:40:46 +00003804TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003805 RValueReferenceTypeLoc TL) {
3806 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807}
Mike Stump1eb44332009-09-09 15:08:12 +00003808
Douglas Gregor577f75a2009-08-04 16:50:30 +00003809template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003810QualType
John McCalla2becad2009-10-21 00:40:46 +00003811TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003813 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814 if (PointeeType.isNull())
3815 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003816
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003817 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3818 TypeSourceInfo* NewClsTInfo = 0;
3819 if (OldClsTInfo) {
3820 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3821 if (!NewClsTInfo)
3822 return QualType();
3823 }
3824
3825 const MemberPointerType *T = TL.getTypePtr();
3826 QualType OldClsType = QualType(T->getClass(), 0);
3827 QualType NewClsType;
3828 if (NewClsTInfo)
3829 NewClsType = NewClsTInfo->getType();
3830 else {
3831 NewClsType = getDerived().TransformType(OldClsType);
3832 if (NewClsType.isNull())
3833 return QualType();
3834 }
Mike Stump1eb44332009-09-09 15:08:12 +00003835
John McCalla2becad2009-10-21 00:40:46 +00003836 QualType Result = TL.getType();
3837 if (getDerived().AlwaysRebuild() ||
3838 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003839 NewClsType != OldClsType) {
3840 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003841 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003842 if (Result.isNull())
3843 return QualType();
3844 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003845
John McCalla2becad2009-10-21 00:40:46 +00003846 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3847 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003848 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003849
3850 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003851}
3852
Mike Stump1eb44332009-09-09 15:08:12 +00003853template<typename Derived>
3854QualType
John McCalla2becad2009-10-21 00:40:46 +00003855TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003856 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003857 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003858 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859 if (ElementType.isNull())
3860 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003861
John McCalla2becad2009-10-21 00:40:46 +00003862 QualType Result = TL.getType();
3863 if (getDerived().AlwaysRebuild() ||
3864 ElementType != T->getElementType()) {
3865 Result = getDerived().RebuildConstantArrayType(ElementType,
3866 T->getSizeModifier(),
3867 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003868 T->getIndexTypeCVRQualifiers(),
3869 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003870 if (Result.isNull())
3871 return QualType();
3872 }
Eli Friedman457a3772012-01-25 22:19:07 +00003873
3874 // We might have either a ConstantArrayType or a VariableArrayType now:
3875 // a ConstantArrayType is allowed to have an element type which is a
3876 // VariableArrayType if the type is dependent. Fortunately, all array
3877 // types have the same location layout.
3878 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003879 NewTL.setLBracketLoc(TL.getLBracketLoc());
3880 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003881
John McCalla2becad2009-10-21 00:40:46 +00003882 Expr *Size = TL.getSizeExpr();
3883 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003884 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3885 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003886 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003887 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003888 }
3889 NewTL.setSizeExpr(Size);
3890
3891 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892}
Mike Stump1eb44332009-09-09 15:08:12 +00003893
Douglas Gregor577f75a2009-08-04 16:50:30 +00003894template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003895QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003896 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003897 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003898 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003899 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003900 if (ElementType.isNull())
3901 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003902
John McCalla2becad2009-10-21 00:40:46 +00003903 QualType Result = TL.getType();
3904 if (getDerived().AlwaysRebuild() ||
3905 ElementType != T->getElementType()) {
3906 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003908 T->getIndexTypeCVRQualifiers(),
3909 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003910 if (Result.isNull())
3911 return QualType();
3912 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003913
John McCalla2becad2009-10-21 00:40:46 +00003914 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3915 NewTL.setLBracketLoc(TL.getLBracketLoc());
3916 NewTL.setRBracketLoc(TL.getRBracketLoc());
3917 NewTL.setSizeExpr(0);
3918
3919 return Result;
3920}
3921
3922template<typename Derived>
3923QualType
3924TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003925 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003926 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003927 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3928 if (ElementType.isNull())
3929 return QualType();
3930
John McCall60d7b3a2010-08-24 06:29:42 +00003931 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003932 = getDerived().TransformExpr(T->getSizeExpr());
3933 if (SizeResult.isInvalid())
3934 return QualType();
3935
John McCall9ae2f072010-08-23 23:25:46 +00003936 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003937
3938 QualType Result = TL.getType();
3939 if (getDerived().AlwaysRebuild() ||
3940 ElementType != T->getElementType() ||
3941 Size != T->getSizeExpr()) {
3942 Result = getDerived().RebuildVariableArrayType(ElementType,
3943 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003944 Size,
John McCalla2becad2009-10-21 00:40:46 +00003945 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003946 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003947 if (Result.isNull())
3948 return QualType();
3949 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003950
John McCalla2becad2009-10-21 00:40:46 +00003951 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3952 NewTL.setLBracketLoc(TL.getLBracketLoc());
3953 NewTL.setRBracketLoc(TL.getRBracketLoc());
3954 NewTL.setSizeExpr(Size);
3955
3956 return Result;
3957}
3958
3959template<typename Derived>
3960QualType
3961TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003962 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003963 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003964 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3965 if (ElementType.isNull())
3966 return QualType();
3967
Richard Smithf6702a32011-12-20 02:08:33 +00003968 // Array bounds are constant expressions.
3969 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3970 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003971
John McCall3b657512011-01-19 10:06:00 +00003972 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3973 Expr *origSize = TL.getSizeExpr();
3974 if (!origSize) origSize = T->getSizeExpr();
3975
3976 ExprResult sizeResult
3977 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003978 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003979 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003980 return QualType();
3981
John McCall3b657512011-01-19 10:06:00 +00003982 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003983
3984 QualType Result = TL.getType();
3985 if (getDerived().AlwaysRebuild() ||
3986 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003987 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003988 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3989 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003990 size,
John McCalla2becad2009-10-21 00:40:46 +00003991 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003992 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003993 if (Result.isNull())
3994 return QualType();
3995 }
John McCalla2becad2009-10-21 00:40:46 +00003996
3997 // We might have any sort of array type now, but fortunately they
3998 // all have the same location layout.
3999 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4000 NewTL.setLBracketLoc(TL.getLBracketLoc());
4001 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004002 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004003
4004 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004005}
Mike Stump1eb44332009-09-09 15:08:12 +00004006
4007template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004008QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004009 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004010 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004011 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004012
4013 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004014 QualType ElementType = getDerived().TransformType(T->getElementType());
4015 if (ElementType.isNull())
4016 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004017
Richard Smithf6702a32011-12-20 02:08:33 +00004018 // Vector sizes are constant expressions.
4019 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4020 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004021
John McCall60d7b3a2010-08-24 06:29:42 +00004022 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004023 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004024 if (Size.isInvalid())
4025 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004026
John McCalla2becad2009-10-21 00:40:46 +00004027 QualType Result = TL.getType();
4028 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004029 ElementType != T->getElementType() ||
4030 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004031 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004032 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004033 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004034 if (Result.isNull())
4035 return QualType();
4036 }
John McCalla2becad2009-10-21 00:40:46 +00004037
4038 // Result might be dependent or not.
4039 if (isa<DependentSizedExtVectorType>(Result)) {
4040 DependentSizedExtVectorTypeLoc NewTL
4041 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4042 NewTL.setNameLoc(TL.getNameLoc());
4043 } else {
4044 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4045 NewTL.setNameLoc(TL.getNameLoc());
4046 }
4047
4048 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004049}
Mike Stump1eb44332009-09-09 15:08:12 +00004050
4051template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004052QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004053 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004054 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004055 QualType ElementType = getDerived().TransformType(T->getElementType());
4056 if (ElementType.isNull())
4057 return QualType();
4058
John McCalla2becad2009-10-21 00:40:46 +00004059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004062 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004063 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004064 if (Result.isNull())
4065 return QualType();
4066 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004067
John McCalla2becad2009-10-21 00:40:46 +00004068 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4069 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004070
John McCalla2becad2009-10-21 00:40:46 +00004071 return Result;
4072}
4073
4074template<typename Derived>
4075QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004076 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004077 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004078 QualType ElementType = getDerived().TransformType(T->getElementType());
4079 if (ElementType.isNull())
4080 return QualType();
4081
4082 QualType Result = TL.getType();
4083 if (getDerived().AlwaysRebuild() ||
4084 ElementType != T->getElementType()) {
4085 Result = getDerived().RebuildExtVectorType(ElementType,
4086 T->getNumElements(),
4087 /*FIXME*/ SourceLocation());
4088 if (Result.isNull())
4089 return QualType();
4090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004091
John McCalla2becad2009-10-21 00:40:46 +00004092 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4093 NewTL.setNameLoc(TL.getNameLoc());
4094
4095 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004096}
Mike Stump1eb44332009-09-09 15:08:12 +00004097
David Blaikiedc84cd52013-02-20 22:23:23 +00004098template <typename Derived>
4099ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4100 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4101 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004102 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004103 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004105 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004106 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004107 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004108 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004109 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004110
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004111 TypeLocBuilder TLB;
4112 TypeLoc NewTL = OldDI->getTypeLoc();
4113 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004114
4115 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004116 OldExpansionTL.getPatternLoc());
4117 if (Result.isNull())
4118 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004119
4120 Result = RebuildPackExpansionType(Result,
4121 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004122 OldExpansionTL.getEllipsisLoc(),
4123 NumExpansions);
4124 if (Result.isNull())
4125 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004127 PackExpansionTypeLoc NewExpansionTL
4128 = TLB.push<PackExpansionTypeLoc>(Result);
4129 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4130 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4131 } else
4132 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004133 if (!NewDI)
4134 return 0;
4135
John McCallfb44de92011-05-01 22:35:37 +00004136 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004137 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004138
4139 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4140 OldParm->getDeclContext(),
4141 OldParm->getInnerLocStart(),
4142 OldParm->getLocation(),
4143 OldParm->getIdentifier(),
4144 NewDI->getType(),
4145 NewDI,
4146 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004147 /* DefArg */ NULL);
4148 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4149 OldParm->getFunctionScopeIndex() + indexAdjustment);
4150 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004151}
4152
4153template<typename Derived>
4154bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004155 TransformFunctionTypeParams(SourceLocation Loc,
4156 ParmVarDecl **Params, unsigned NumParams,
4157 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004158 SmallVectorImpl<QualType> &OutParamTypes,
4159 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004160 int indexAdjustment = 0;
4161
Douglas Gregora009b592011-01-07 00:20:55 +00004162 for (unsigned i = 0; i != NumParams; ++i) {
4163 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004164 assert(OldParm->getFunctionScopeIndex() == i);
4165
David Blaikiedc84cd52013-02-20 22:23:23 +00004166 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004167 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 if (OldParm->isParameterPack()) {
4169 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004170 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004171
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004173 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004174 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004175 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4176 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004177 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4178
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 // Determine whether we should expand the parameter packs.
4180 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004181 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004182 Optional<unsigned> OrigNumExpansions =
4183 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004184 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004185 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4186 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004187 Unexpanded,
4188 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004189 RetainExpansion,
4190 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004191 return true;
4192 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004193
Douglas Gregor603cfb42011-01-05 23:12:31 +00004194 if (ShouldExpand) {
4195 // Expand the function parameter pack into multiple, separate
4196 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004197 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004198 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004199 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004201 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004202 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004203 OrigNumExpansions,
4204 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004205 if (!NewParm)
4206 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207
Douglas Gregora009b592011-01-07 00:20:55 +00004208 OutParamTypes.push_back(NewParm->getType());
4209 if (PVars)
4210 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004211 }
Douglas Gregord3731192011-01-10 07:32:04 +00004212
4213 // If we're supposed to retain a pack expansion, do so by temporarily
4214 // forgetting the partially-substituted parameter pack.
4215 if (RetainExpansion) {
4216 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004218 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004219 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004220 OrigNumExpansions,
4221 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004222 if (!NewParm)
4223 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224
Douglas Gregord3731192011-01-10 07:32:04 +00004225 OutParamTypes.push_back(NewParm->getType());
4226 if (PVars)
4227 PVars->push_back(NewParm);
4228 }
4229
John McCallfb44de92011-05-01 22:35:37 +00004230 // The next parameter should have the same adjustment as the
4231 // last thing we pushed, but we post-incremented indexAdjustment
4232 // on every push. Also, if we push nothing, the adjustment should
4233 // go down by one.
4234 indexAdjustment--;
4235
Douglas Gregor603cfb42011-01-05 23:12:31 +00004236 // We're done with the pack expansion.
4237 continue;
4238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004239
4240 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004241 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004242 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4243 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004244 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004245 NumExpansions,
4246 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004247 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004248 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004249 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004250 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004251
John McCall21ef0fa2010-03-11 09:03:00 +00004252 if (!NewParm)
4253 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004254
Douglas Gregora009b592011-01-07 00:20:55 +00004255 OutParamTypes.push_back(NewParm->getType());
4256 if (PVars)
4257 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004258 continue;
4259 }
John McCall21ef0fa2010-03-11 09:03:00 +00004260
4261 // Deal with the possibility that we don't have a parameter
4262 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004263 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004264 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004265 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004266 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004267 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004268 = dyn_cast<PackExpansionType>(OldType)) {
4269 // We have a function parameter pack that may need to be expanded.
4270 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004271 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004272 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004273
Douglas Gregor603cfb42011-01-05 23:12:31 +00004274 // Determine whether we should expand the parameter packs.
4275 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004276 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004277 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004278 Unexpanded,
4279 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004280 RetainExpansion,
4281 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004282 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004284
Douglas Gregor603cfb42011-01-05 23:12:31 +00004285 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004286 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004287 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004288 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004289 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4290 QualType NewType = getDerived().TransformType(Pattern);
4291 if (NewType.isNull())
4292 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004293
Douglas Gregora009b592011-01-07 00:20:55 +00004294 OutParamTypes.push_back(NewType);
4295 if (PVars)
4296 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004297 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004298
Douglas Gregor603cfb42011-01-05 23:12:31 +00004299 // We're done with the pack expansion.
4300 continue;
4301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004302
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004303 // If we're supposed to retain a pack expansion, do so by temporarily
4304 // forgetting the partially-substituted parameter pack.
4305 if (RetainExpansion) {
4306 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4307 QualType NewType = getDerived().TransformType(Pattern);
4308 if (NewType.isNull())
4309 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004310
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004311 OutParamTypes.push_back(NewType);
4312 if (PVars)
4313 PVars->push_back(0);
4314 }
Douglas Gregord3731192011-01-10 07:32:04 +00004315
Chad Rosier4a9d7952012-08-08 18:46:20 +00004316 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004317 // expansion.
4318 OldType = Expansion->getPattern();
4319 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004320 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4321 NewType = getDerived().TransformType(OldType);
4322 } else {
4323 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004324 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004325
Douglas Gregor603cfb42011-01-05 23:12:31 +00004326 if (NewType.isNull())
4327 return true;
4328
4329 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004330 NewType = getSema().Context.getPackExpansionType(NewType,
4331 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004332
Douglas Gregora009b592011-01-07 00:20:55 +00004333 OutParamTypes.push_back(NewType);
4334 if (PVars)
4335 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004336 }
4337
John McCallfb44de92011-05-01 22:35:37 +00004338#ifndef NDEBUG
4339 if (PVars) {
4340 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4341 if (ParmVarDecl *parm = (*PVars)[i])
4342 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004343 }
John McCallfb44de92011-05-01 22:35:37 +00004344#endif
4345
4346 return false;
4347}
John McCall21ef0fa2010-03-11 09:03:00 +00004348
4349template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004350QualType
John McCalla2becad2009-10-21 00:40:46 +00004351TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004352 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004353 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4354}
4355
4356template<typename Derived>
4357QualType
4358TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4359 FunctionProtoTypeLoc TL,
4360 CXXRecordDecl *ThisContext,
4361 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004362 // Transform the parameters and return type.
4363 //
Richard Smithe6975e92012-04-17 00:58:00 +00004364 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004365 // When the function has a trailing return type, we instantiate the
4366 // parameters before the return type, since the return type can then refer
4367 // to the parameters themselves (via decltype, sizeof, etc.).
4368 //
Chris Lattner686775d2011-07-20 06:58:45 +00004369 SmallVector<QualType, 4> ParamTypes;
4370 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004371 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004372
Douglas Gregordab60ad2010-10-01 18:44:50 +00004373 QualType ResultType;
4374
Richard Smith9fbf3272012-08-14 22:51:13 +00004375 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004376 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004377 TL.getParmArray(),
4378 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004379 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004380 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004381 return QualType();
4382
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004383 {
4384 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004385 // If a declaration declares a member function or member function
4386 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004387 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004388 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004389 // declarator.
4390 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004391
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004392 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4393 if (ResultType.isNull())
4394 return QualType();
4395 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004396 }
4397 else {
4398 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4399 if (ResultType.isNull())
4400 return QualType();
4401
Chad Rosier4a9d7952012-08-08 18:46:20 +00004402 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004403 TL.getParmArray(),
4404 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004405 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004406 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004407 return QualType();
4408 }
4409
Richard Smithe6975e92012-04-17 00:58:00 +00004410 // FIXME: Need to transform the exception-specification too.
4411
John McCalla2becad2009-10-21 00:40:46 +00004412 QualType Result = TL.getType();
4413 if (getDerived().AlwaysRebuild() ||
4414 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004415 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004416 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004417 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004418 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004419 if (Result.isNull())
4420 return QualType();
4421 }
Mike Stump1eb44332009-09-09 15:08:12 +00004422
John McCalla2becad2009-10-21 00:40:46 +00004423 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004424 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004425 NewTL.setLParenLoc(TL.getLParenLoc());
4426 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004427 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004428 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4429 NewTL.setArg(i, ParamDecls[i]);
4430
4431 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004432}
Mike Stump1eb44332009-09-09 15:08:12 +00004433
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434template<typename Derived>
4435QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004436 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004437 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004438 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004439 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4440 if (ResultType.isNull())
4441 return QualType();
4442
4443 QualType Result = TL.getType();
4444 if (getDerived().AlwaysRebuild() ||
4445 ResultType != T->getResultType())
4446 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4447
4448 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004449 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004450 NewTL.setLParenLoc(TL.getLParenLoc());
4451 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004452 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004453
4454 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004455}
Mike Stump1eb44332009-09-09 15:08:12 +00004456
John McCalled976492009-12-04 22:46:56 +00004457template<typename Derived> QualType
4458TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004459 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004460 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004461 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004462 if (!D)
4463 return QualType();
4464
4465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4467 Result = getDerived().RebuildUnresolvedUsingType(D);
4468 if (Result.isNull())
4469 return QualType();
4470 }
4471
4472 // We might get an arbitrary type spec type back. We should at
4473 // least always get a type spec type, though.
4474 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4475 NewTL.setNameLoc(TL.getNameLoc());
4476
4477 return Result;
4478}
4479
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004481QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004482 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004483 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004484 TypedefNameDecl *Typedef
4485 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4486 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487 if (!Typedef)
4488 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
John McCalla2becad2009-10-21 00:40:46 +00004490 QualType Result = TL.getType();
4491 if (getDerived().AlwaysRebuild() ||
4492 Typedef != T->getDecl()) {
4493 Result = getDerived().RebuildTypedefType(Typedef);
4494 if (Result.isNull())
4495 return QualType();
4496 }
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCalla2becad2009-10-21 00:40:46 +00004498 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4499 NewTL.setNameLoc(TL.getNameLoc());
4500
4501 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502}
Mike Stump1eb44332009-09-09 15:08:12 +00004503
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004505QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004506 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004507 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004508 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4509 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004510
John McCall60d7b3a2010-08-24 06:29:42 +00004511 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004512 if (E.isInvalid())
4513 return QualType();
4514
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004515 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4516 if (E.isInvalid())
4517 return QualType();
4518
John McCalla2becad2009-10-21 00:40:46 +00004519 QualType Result = TL.getType();
4520 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004521 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004522 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004523 if (Result.isNull())
4524 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004525 }
John McCalla2becad2009-10-21 00:40:46 +00004526 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004527
John McCalla2becad2009-10-21 00:40:46 +00004528 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004529 NewTL.setTypeofLoc(TL.getTypeofLoc());
4530 NewTL.setLParenLoc(TL.getLParenLoc());
4531 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004532
4533 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004534}
Mike Stump1eb44332009-09-09 15:08:12 +00004535
4536template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004537QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004538 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004539 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4540 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4541 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004543
John McCalla2becad2009-10-21 00:40:46 +00004544 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004545 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4546 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004547 if (Result.isNull())
4548 return QualType();
4549 }
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCalla2becad2009-10-21 00:40:46 +00004551 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004552 NewTL.setTypeofLoc(TL.getTypeofLoc());
4553 NewTL.setLParenLoc(TL.getLParenLoc());
4554 NewTL.setRParenLoc(TL.getRParenLoc());
4555 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004556
4557 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558}
Mike Stump1eb44332009-09-09 15:08:12 +00004559
4560template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004561QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004562 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004563 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004564
Douglas Gregor670444e2009-08-04 22:27:00 +00004565 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004566 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4567 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCall60d7b3a2010-08-24 06:29:42 +00004569 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004570 if (E.isInvalid())
4571 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004572
Richard Smith76f3f692012-02-22 02:04:18 +00004573 E = getSema().ActOnDecltypeExpression(E.take());
4574 if (E.isInvalid())
4575 return QualType();
4576
John McCalla2becad2009-10-21 00:40:46 +00004577 QualType Result = TL.getType();
4578 if (getDerived().AlwaysRebuild() ||
4579 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004580 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004581 if (Result.isNull())
4582 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004583 }
John McCalla2becad2009-10-21 00:40:46 +00004584 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004585
John McCalla2becad2009-10-21 00:40:46 +00004586 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4587 NewTL.setNameLoc(TL.getNameLoc());
4588
4589 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004590}
4591
4592template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004593QualType TreeTransform<Derived>::TransformUnaryTransformType(
4594 TypeLocBuilder &TLB,
4595 UnaryTransformTypeLoc TL) {
4596 QualType Result = TL.getType();
4597 if (Result->isDependentType()) {
4598 const UnaryTransformType *T = TL.getTypePtr();
4599 QualType NewBase =
4600 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4601 Result = getDerived().RebuildUnaryTransformType(NewBase,
4602 T->getUTTKind(),
4603 TL.getKWLoc());
4604 if (Result.isNull())
4605 return QualType();
4606 }
4607
4608 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4609 NewTL.setKWLoc(TL.getKWLoc());
4610 NewTL.setParensRange(TL.getParensRange());
4611 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4612 return Result;
4613}
4614
4615template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004616QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4617 AutoTypeLoc TL) {
4618 const AutoType *T = TL.getTypePtr();
4619 QualType OldDeduced = T->getDeducedType();
4620 QualType NewDeduced;
4621 if (!OldDeduced.isNull()) {
4622 NewDeduced = getDerived().TransformType(OldDeduced);
4623 if (NewDeduced.isNull())
4624 return QualType();
4625 }
4626
4627 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004628 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4629 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004630 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004631 if (Result.isNull())
4632 return QualType();
4633 }
4634
4635 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4636 NewTL.setNameLoc(TL.getNameLoc());
4637
4638 return Result;
4639}
4640
4641template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004642QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004643 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004644 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004645 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004646 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4647 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004648 if (!Record)
4649 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004650
John McCalla2becad2009-10-21 00:40:46 +00004651 QualType Result = TL.getType();
4652 if (getDerived().AlwaysRebuild() ||
4653 Record != T->getDecl()) {
4654 Result = getDerived().RebuildRecordType(Record);
4655 if (Result.isNull())
4656 return QualType();
4657 }
Mike Stump1eb44332009-09-09 15:08:12 +00004658
John McCalla2becad2009-10-21 00:40:46 +00004659 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4660 NewTL.setNameLoc(TL.getNameLoc());
4661
4662 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004663}
Mike Stump1eb44332009-09-09 15:08:12 +00004664
4665template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004666QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004667 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004668 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004669 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004670 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4671 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004672 if (!Enum)
4673 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004674
John McCalla2becad2009-10-21 00:40:46 +00004675 QualType Result = TL.getType();
4676 if (getDerived().AlwaysRebuild() ||
4677 Enum != T->getDecl()) {
4678 Result = getDerived().RebuildEnumType(Enum);
4679 if (Result.isNull())
4680 return QualType();
4681 }
Mike Stump1eb44332009-09-09 15:08:12 +00004682
John McCalla2becad2009-10-21 00:40:46 +00004683 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4684 NewTL.setNameLoc(TL.getNameLoc());
4685
4686 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004687}
John McCall7da24312009-09-05 00:15:47 +00004688
John McCall3cb0ebd2010-03-10 03:28:59 +00004689template<typename Derived>
4690QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4691 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004692 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004693 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4694 TL.getTypePtr()->getDecl());
4695 if (!D) return QualType();
4696
4697 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4698 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4699 return T;
4700}
4701
Douglas Gregor577f75a2009-08-04 16:50:30 +00004702template<typename Derived>
4703QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004704 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004705 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004706 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004707}
4708
Mike Stump1eb44332009-09-09 15:08:12 +00004709template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004710QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004712 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004713 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004714
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004715 // Substitute into the replacement type, which itself might involve something
4716 // that needs to be transformed. This only tends to occur with default
4717 // template arguments of template template parameters.
4718 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4719 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4720 if (Replacement.isNull())
4721 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004722
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004723 // Always canonicalize the replacement type.
4724 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4725 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004726 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004727 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004728
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004729 // Propagate type-source information.
4730 SubstTemplateTypeParmTypeLoc NewTL
4731 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4732 NewTL.setNameLoc(TL.getNameLoc());
4733 return Result;
4734
John McCall49a832b2009-10-18 09:09:24 +00004735}
4736
4737template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004738QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4739 TypeLocBuilder &TLB,
4740 SubstTemplateTypeParmPackTypeLoc TL) {
4741 return TransformTypeSpecType(TLB, TL);
4742}
4743
4744template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004745QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004746 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004747 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004748 const TemplateSpecializationType *T = TL.getTypePtr();
4749
Douglas Gregor1d752d72011-03-02 18:46:51 +00004750 // The nested-name-specifier never matters in a TemplateSpecializationType,
4751 // because we can't have a dependent nested-name-specifier anyway.
4752 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004753 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004754 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4755 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004756 if (Template.isNull())
4757 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004758
John McCall43fed0d2010-11-12 08:19:04 +00004759 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4760}
4761
Eli Friedmanb001de72011-10-06 23:00:33 +00004762template<typename Derived>
4763QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4764 AtomicTypeLoc TL) {
4765 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4766 if (ValueType.isNull())
4767 return QualType();
4768
4769 QualType Result = TL.getType();
4770 if (getDerived().AlwaysRebuild() ||
4771 ValueType != TL.getValueLoc().getType()) {
4772 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4773 if (Result.isNull())
4774 return QualType();
4775 }
4776
4777 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4778 NewTL.setKWLoc(TL.getKWLoc());
4779 NewTL.setLParenLoc(TL.getLParenLoc());
4780 NewTL.setRParenLoc(TL.getRParenLoc());
4781
4782 return Result;
4783}
4784
Chad Rosier4a9d7952012-08-08 18:46:20 +00004785 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004786 /// container that provides a \c getArgLoc() member function.
4787 ///
4788 /// This iterator is intended to be used with the iterator form of
4789 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4790 template<typename ArgLocContainer>
4791 class TemplateArgumentLocContainerIterator {
4792 ArgLocContainer *Container;
4793 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004794
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004795 public:
4796 typedef TemplateArgumentLoc value_type;
4797 typedef TemplateArgumentLoc reference;
4798 typedef int difference_type;
4799 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004801 class pointer {
4802 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004803
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004804 public:
4805 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004807 const TemplateArgumentLoc *operator->() const {
4808 return &Arg;
4809 }
4810 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004811
4812
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004813 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004814
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004815 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4816 unsigned Index)
4817 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004818
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004819 TemplateArgumentLocContainerIterator &operator++() {
4820 ++Index;
4821 return *this;
4822 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004823
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004824 TemplateArgumentLocContainerIterator operator++(int) {
4825 TemplateArgumentLocContainerIterator Old(*this);
4826 ++(*this);
4827 return Old;
4828 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004829
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004830 TemplateArgumentLoc operator*() const {
4831 return Container->getArgLoc(Index);
4832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004833
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004834 pointer operator->() const {
4835 return pointer(Container->getArgLoc(Index));
4836 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004838 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004839 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004840 return X.Container == Y.Container && X.Index == Y.Index;
4841 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004842
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004843 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004844 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004845 return !(X == Y);
4846 }
4847 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004848
4849
John McCall43fed0d2010-11-12 08:19:04 +00004850template <typename Derived>
4851QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4852 TypeLocBuilder &TLB,
4853 TemplateSpecializationTypeLoc TL,
4854 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004855 TemplateArgumentListInfo NewTemplateArgs;
4856 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4857 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004858 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4859 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004860 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004861 ArgIterator(TL, TL.getNumArgs()),
4862 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004863 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004864
John McCall833ca992009-10-29 08:12:44 +00004865 // FIXME: maybe don't rebuild if all the template arguments are the same.
4866
4867 QualType Result =
4868 getDerived().RebuildTemplateSpecializationType(Template,
4869 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004870 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004871
4872 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004873 // Specializations of template template parameters are represented as
4874 // TemplateSpecializationTypes, and substitution of type alias templates
4875 // within a dependent context can transform them into
4876 // DependentTemplateSpecializationTypes.
4877 if (isa<DependentTemplateSpecializationType>(Result)) {
4878 DependentTemplateSpecializationTypeLoc NewTL
4879 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004880 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004881 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004882 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004883 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004884 NewTL.setLAngleLoc(TL.getLAngleLoc());
4885 NewTL.setRAngleLoc(TL.getRAngleLoc());
4886 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4887 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4888 return Result;
4889 }
4890
John McCall833ca992009-10-29 08:12:44 +00004891 TemplateSpecializationTypeLoc NewTL
4892 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004893 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004894 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4895 NewTL.setLAngleLoc(TL.getLAngleLoc());
4896 NewTL.setRAngleLoc(TL.getRAngleLoc());
4897 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4898 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004899 }
Mike Stump1eb44332009-09-09 15:08:12 +00004900
John McCall833ca992009-10-29 08:12:44 +00004901 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004902}
Mike Stump1eb44332009-09-09 15:08:12 +00004903
Douglas Gregora88f09f2011-02-28 17:23:35 +00004904template <typename Derived>
4905QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4906 TypeLocBuilder &TLB,
4907 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004908 TemplateName Template,
4909 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004910 TemplateArgumentListInfo NewTemplateArgs;
4911 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4912 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4913 typedef TemplateArgumentLocContainerIterator<
4914 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004915 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004916 ArgIterator(TL, TL.getNumArgs()),
4917 NewTemplateArgs))
4918 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004919
Douglas Gregora88f09f2011-02-28 17:23:35 +00004920 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004921
Douglas Gregora88f09f2011-02-28 17:23:35 +00004922 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4923 QualType Result
4924 = getSema().Context.getDependentTemplateSpecializationType(
4925 TL.getTypePtr()->getKeyword(),
4926 DTN->getQualifier(),
4927 DTN->getIdentifier(),
4928 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004929
Douglas Gregora88f09f2011-02-28 17:23:35 +00004930 DependentTemplateSpecializationTypeLoc NewTL
4931 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004932 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004933 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004934 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 NewTL.setLAngleLoc(TL.getLAngleLoc());
4937 NewTL.setRAngleLoc(TL.getRAngleLoc());
4938 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4939 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4940 return Result;
4941 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004942
4943 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004944 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004945 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004946 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004947
Douglas Gregora88f09f2011-02-28 17:23:35 +00004948 if (!Result.isNull()) {
4949 /// FIXME: Wrap this in an elaborated-type-specifier?
4950 TemplateSpecializationTypeLoc NewTL
4951 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004952 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004953 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004954 NewTL.setLAngleLoc(TL.getLAngleLoc());
4955 NewTL.setRAngleLoc(TL.getRAngleLoc());
4956 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4957 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4958 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004959
Douglas Gregora88f09f2011-02-28 17:23:35 +00004960 return Result;
4961}
4962
Mike Stump1eb44332009-09-09 15:08:12 +00004963template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004964QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004965TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004966 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004967 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004968
Douglas Gregor9e876872011-03-01 18:12:44 +00004969 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004970 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004971 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004972 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004973 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4974 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004975 return QualType();
4976 }
Mike Stump1eb44332009-09-09 15:08:12 +00004977
John McCall43fed0d2010-11-12 08:19:04 +00004978 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4979 if (NamedT.isNull())
4980 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004981
Richard Smith3e4c6c42011-05-05 21:57:07 +00004982 // C++0x [dcl.type.elab]p2:
4983 // If the identifier resolves to a typedef-name or the simple-template-id
4984 // resolves to an alias template specialization, the
4985 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004986 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4987 if (const TemplateSpecializationType *TST =
4988 NamedT->getAs<TemplateSpecializationType>()) {
4989 TemplateName Template = TST->getTemplateName();
4990 if (TypeAliasTemplateDecl *TAT =
4991 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4992 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4993 diag::err_tag_reference_non_tag) << 4;
4994 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4995 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004996 }
4997 }
4998
John McCalla2becad2009-10-21 00:40:46 +00004999 QualType Result = TL.getType();
5000 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005001 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005002 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005003 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005004 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005005 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005006 if (Result.isNull())
5007 return QualType();
5008 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005009
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005010 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005011 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005012 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005013 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005014}
Mike Stump1eb44332009-09-09 15:08:12 +00005015
5016template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005017QualType TreeTransform<Derived>::TransformAttributedType(
5018 TypeLocBuilder &TLB,
5019 AttributedTypeLoc TL) {
5020 const AttributedType *oldType = TL.getTypePtr();
5021 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5022 if (modifiedType.isNull())
5023 return QualType();
5024
5025 QualType result = TL.getType();
5026
5027 // FIXME: dependent operand expressions?
5028 if (getDerived().AlwaysRebuild() ||
5029 modifiedType != oldType->getModifiedType()) {
5030 // TODO: this is really lame; we should really be rebuilding the
5031 // equivalent type from first principles.
5032 QualType equivalentType
5033 = getDerived().TransformType(oldType->getEquivalentType());
5034 if (equivalentType.isNull())
5035 return QualType();
5036 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5037 modifiedType,
5038 equivalentType);
5039 }
5040
5041 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5042 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5043 if (TL.hasAttrOperand())
5044 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5045 if (TL.hasAttrExprOperand())
5046 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5047 else if (TL.hasAttrEnumOperand())
5048 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5049
5050 return result;
5051}
5052
5053template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005054QualType
5055TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5056 ParenTypeLoc TL) {
5057 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5058 if (Inner.isNull())
5059 return QualType();
5060
5061 QualType Result = TL.getType();
5062 if (getDerived().AlwaysRebuild() ||
5063 Inner != TL.getInnerLoc().getType()) {
5064 Result = getDerived().RebuildParenType(Inner);
5065 if (Result.isNull())
5066 return QualType();
5067 }
5068
5069 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5070 NewTL.setLParenLoc(TL.getLParenLoc());
5071 NewTL.setRParenLoc(TL.getRParenLoc());
5072 return Result;
5073}
5074
5075template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005076QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005077 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005078 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005079
Douglas Gregor2494dd02011-03-01 01:34:45 +00005080 NestedNameSpecifierLoc QualifierLoc
5081 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5082 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005083 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005084
John McCall33500952010-06-11 00:33:02 +00005085 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005086 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005087 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005088 QualifierLoc,
5089 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005090 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005091 if (Result.isNull())
5092 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005093
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005094 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5095 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005096 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5097
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005098 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005099 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005100 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005101 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005102 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005103 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005104 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005105 NewTL.setNameLoc(TL.getNameLoc());
5106 }
John McCalla2becad2009-10-21 00:40:46 +00005107 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005108}
Mike Stump1eb44332009-09-09 15:08:12 +00005109
Douglas Gregor577f75a2009-08-04 16:50:30 +00005110template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005111QualType TreeTransform<Derived>::
5112 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005113 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005114 NestedNameSpecifierLoc QualifierLoc;
5115 if (TL.getQualifierLoc()) {
5116 QualifierLoc
5117 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5118 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005119 return QualType();
5120 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005121
John McCall43fed0d2010-11-12 08:19:04 +00005122 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005123 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005124}
5125
5126template<typename Derived>
5127QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005128TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5129 DependentTemplateSpecializationTypeLoc TL,
5130 NestedNameSpecifierLoc QualifierLoc) {
5131 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005132
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005133 TemplateArgumentListInfo NewTemplateArgs;
5134 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5135 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005136
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005137 typedef TemplateArgumentLocContainerIterator<
5138 DependentTemplateSpecializationTypeLoc> ArgIterator;
5139 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5140 ArgIterator(TL, TL.getNumArgs()),
5141 NewTemplateArgs))
5142 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005143
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 QualType Result
5145 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5146 QualifierLoc,
5147 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005148 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005149 NewTemplateArgs);
5150 if (Result.isNull())
5151 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005152
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005153 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5154 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005155
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005156 // Copy information relevant to the template specialization.
5157 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005158 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005159 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005160 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005161 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5162 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005163 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005164 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005165
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005166 // Copy information relevant to the elaborated type.
5167 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005168 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005169 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005170 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5171 DependentTemplateSpecializationTypeLoc SpecTL
5172 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005173 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005174 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005175 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005176 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005177 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5178 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005179 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005180 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005181 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005182 TemplateSpecializationTypeLoc SpecTL
5183 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005184 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005185 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005186 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5187 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005188 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005189 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005190 }
5191 return Result;
5192}
5193
5194template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005195QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5196 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005197 QualType Pattern
5198 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005199 if (Pattern.isNull())
5200 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005201
5202 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005203 if (getDerived().AlwaysRebuild() ||
5204 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005205 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005206 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005207 TL.getEllipsisLoc(),
5208 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005209 if (Result.isNull())
5210 return QualType();
5211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005212
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005213 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5214 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5215 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005216}
5217
5218template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005219QualType
5220TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005221 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005222 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005223 TLB.pushFullCopy(TL);
5224 return TL.getType();
5225}
5226
5227template<typename Derived>
5228QualType
5229TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005230 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005231 // ObjCObjectType is never dependent.
5232 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005233 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005234}
Mike Stump1eb44332009-09-09 15:08:12 +00005235
5236template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005237QualType
5238TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005239 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005240 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005241 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005242 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005243}
5244
Douglas Gregor577f75a2009-08-04 16:50:30 +00005245//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005246// Statement transformation
5247//===----------------------------------------------------------------------===//
5248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005249StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005250TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005251 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005252}
5253
5254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005255StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005256TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5257 return getDerived().TransformCompoundStmt(S, false);
5258}
5259
5260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005262TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005264 Sema::CompoundScopeRAII CompoundScope(getSema());
5265
John McCall7114cba2010-08-27 19:56:05 +00005266 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005268 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5270 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005271 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005272 if (Result.isInvalid()) {
5273 // Immediately fail if this was a DeclStmt, since it's very
5274 // likely that this will cause problems for future statements.
5275 if (isa<DeclStmt>(*B))
5276 return StmtError();
5277
5278 // Otherwise, just keep processing substatements and fail later.
5279 SubStmtInvalid = true;
5280 continue;
5281 }
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5284 Statements.push_back(Result.takeAs<Stmt>());
5285 }
Mike Stump1eb44332009-09-09 15:08:12 +00005286
John McCall7114cba2010-08-27 19:56:05 +00005287 if (SubStmtInvalid)
5288 return StmtError();
5289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 if (!getDerived().AlwaysRebuild() &&
5291 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005292 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005293
5294 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005295 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 S->getRBracLoc(),
5297 IsStmtExpr);
5298}
Mike Stump1eb44332009-09-09 15:08:12 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005301StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005302TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005303 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005304 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005305 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5306 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Eli Friedman264c1f82009-11-19 03:14:00 +00005308 // Transform the left-hand case value.
5309 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005310 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005311 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Eli Friedman264c1f82009-11-19 03:14:00 +00005314 // Transform the right-hand case value (for the GNU case-range extension).
5315 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005316 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005317 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005318 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005319 }
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Build the case statement.
5322 // Case statements are always rebuilt so that they will attached to their
5323 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005324 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005325 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005327 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 S->getColonLoc());
5329 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005333 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005338 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005339}
5340
5341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005342StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005343TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005345 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // Default statements are always rebuilt
5350 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005351 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005352}
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregor43959a92009-08-20 07:17:43 +00005354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005355StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005356TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005357 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Chris Lattner57ad3782011-02-17 20:34:02 +00005361 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5362 S->getDecl());
5363 if (!LD)
5364 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005365
5366
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005368 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005369 cast<LabelDecl>(LD), SourceLocation(),
5370 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005371}
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005374StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005375TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5376 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5377 if (SubStmt.isInvalid())
5378 return StmtError();
5379
5380 // TODO: transform attributes
5381 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5382 return S;
5383
5384 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5385 S->getAttrs(),
5386 SubStmt.get());
5387}
5388
5389template<typename Derived>
5390StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005391TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005393 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005394 VarDecl *ConditionVar = 0;
5395 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005396 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005397 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005398 getDerived().TransformDefinition(
5399 S->getConditionVariable()->getLocation(),
5400 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005401 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005402 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005404 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005407 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005408
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005409 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005410 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005411 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005412 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005413 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415
John McCall9ae2f072010-08-23 23:25:46 +00005416 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005418 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005419
John McCall9ae2f072010-08-23 23:25:46 +00005420 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5421 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005422 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005423
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005425 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005426 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005430 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregor43959a92009-08-20 07:17:43 +00005434 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005435 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005436 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 Then.get() == S->getThen() &&
5438 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005439 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005441 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005442 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005443 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005444}
5445
5446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005447StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005448TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005450 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005451 VarDecl *ConditionVar = 0;
5452 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005453 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005454 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005455 getDerived().TransformDefinition(
5456 S->getConditionVariable()->getLocation(),
5457 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005458 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005459 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005460 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005461 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005462
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005463 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005464 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005465 }
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005468 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005469 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005470 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005475 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005480 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5481 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005482}
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregor43959a92009-08-20 07:17:43 +00005484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005487 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005488 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005489 VarDecl *ConditionVar = 0;
5490 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005491 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005492 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005493 getDerived().TransformDefinition(
5494 S->getConditionVariable()->getLocation(),
5495 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005496 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005497 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005498 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005499 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005500
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005501 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005503
5504 if (S->getCond()) {
5505 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005506 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005507 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005508 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005510 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005511 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005512 }
Mike Stump1eb44332009-09-09 15:08:12 +00005513
John McCall9ae2f072010-08-23 23:25:46 +00005514 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5515 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005517
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005519 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005524 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005525 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005527 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005529 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005530 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005535TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005537 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005539 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005541 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005542 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005543 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005544 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546 if (!getDerived().AlwaysRebuild() &&
5547 Cond.get() == S->getCond() &&
5548 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005549 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005550
John McCall9ae2f072010-08-23 23:25:46 +00005551 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5552 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 S->getRParenLoc());
5554}
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregor43959a92009-08-20 07:17:43 +00005556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005557StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005558TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005559 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005560 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005561 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005562 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregor43959a92009-08-20 07:17:43 +00005564 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005565 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005566 VarDecl *ConditionVar = 0;
5567 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005568 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005569 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005570 getDerived().TransformDefinition(
5571 S->getConditionVariable()->getLocation(),
5572 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005573 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005575 } else {
5576 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005578 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005579 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005580
5581 if (S->getCond()) {
5582 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005583 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005584 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005585 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005587
John McCall9ae2f072010-08-23 23:25:46 +00005588 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005589 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005590 }
Mike Stump1eb44332009-09-09 15:08:12 +00005591
Chad Rosier4a9d7952012-08-08 18:46:20 +00005592 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005593 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005594 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005595
Douglas Gregor43959a92009-08-20 07:17:43 +00005596 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005597 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005598 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005599 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005600
Richard Smith41956372013-01-14 22:39:08 +00005601 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005602 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005603 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005604
Douglas Gregor43959a92009-08-20 07:17:43 +00005605 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005606 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005607 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005608 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005609
Douglas Gregor43959a92009-08-20 07:17:43 +00005610 if (!getDerived().AlwaysRebuild() &&
5611 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005612 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005613 Inc.get() == S->getInc() &&
5614 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005615 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005616
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005618 Init.get(), FullCond, ConditionVar,
5619 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005620}
5621
5622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005624TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005625 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5626 S->getLabel());
5627 if (!LD)
5628 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005629
Douglas Gregor43959a92009-08-20 07:17:43 +00005630 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005631 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005632 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005633}
5634
5635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005636StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005637TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005638 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005639 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005641 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005642
Douglas Gregor43959a92009-08-20 07:17:43 +00005643 if (!getDerived().AlwaysRebuild() &&
5644 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005645 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005646
5647 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005648 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005649}
5650
5651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005652StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005653TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005654 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005655}
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregor43959a92009-08-20 07:17:43 +00005657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005658StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005660 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005661}
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregor43959a92009-08-20 07:17:43 +00005663template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005664StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005665TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005666 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005667 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005668 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005669
Mike Stump1eb44332009-09-09 15:08:12 +00005670 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005671 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005672 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005673}
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005676StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005678 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005679 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5681 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005682 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5683 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005684 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005685 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 if (Transformed != *D)
5688 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor43959a92009-08-20 07:17:43 +00005690 Decls.push_back(Transformed);
5691 }
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005694 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005695
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005696 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005697}
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Douglas Gregor43959a92009-08-20 07:17:43 +00005699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005700StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005701TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005702
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005703 SmallVector<Expr*, 8> Constraints;
5704 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005705 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005706
John McCall60d7b3a2010-08-24 06:29:42 +00005707 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005708 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005709
5710 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005711
Anders Carlsson703e3942010-01-24 05:50:09 +00005712 // Go through the outputs.
5713 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005714 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
Anders Carlsson703e3942010-01-24 05:50:09 +00005716 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005717 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Anders Carlsson703e3942010-01-24 05:50:09 +00005719 // Transform the output expr.
5720 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005721 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005722 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005723 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Anders Carlsson703e3942010-01-24 05:50:09 +00005725 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
John McCall9ae2f072010-08-23 23:25:46 +00005727 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005729
Anders Carlsson703e3942010-01-24 05:50:09 +00005730 // Go through the inputs.
5731 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005732 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005733
Anders Carlsson703e3942010-01-24 05:50:09 +00005734 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005735 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Anders Carlsson703e3942010-01-24 05:50:09 +00005737 // Transform the input expr.
5738 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005739 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005740 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005741 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005742
Anders Carlsson703e3942010-01-24 05:50:09 +00005743 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005744
John McCall9ae2f072010-08-23 23:25:46 +00005745 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005746 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005747
Anders Carlsson703e3942010-01-24 05:50:09 +00005748 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005749 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005750
5751 // Go through the clobbers.
5752 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005753 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005754
5755 // No need to transform the asm string literal.
5756 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005757 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5758 S->isVolatile(), S->getNumOutputs(),
5759 S->getNumInputs(), Names.data(),
5760 Constraints, Exprs, AsmString.get(),
5761 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005762}
5763
Chad Rosier8cd64b42012-06-11 20:47:18 +00005764template<typename Derived>
5765StmtResult
5766TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005767 ArrayRef<Token> AsmToks =
5768 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005769
John McCallaeeacf72013-05-03 00:10:13 +00005770 bool HadError = false, HadChange = false;
5771
5772 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5773 SmallVector<Expr*, 8> TransformedExprs;
5774 TransformedExprs.reserve(SrcExprs.size());
5775 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5776 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5777 if (!Result.isUsable()) {
5778 HadError = true;
5779 } else {
5780 HadChange |= (Result.get() != SrcExprs[i]);
5781 TransformedExprs.push_back(Result.take());
5782 }
5783 }
5784
5785 if (HadError) return StmtError();
5786 if (!HadChange && !getDerived().AlwaysRebuild())
5787 return Owned(S);
5788
Chad Rosier7bd092b2012-08-15 16:53:30 +00005789 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005790 AsmToks, S->getAsmString(),
5791 S->getNumOutputs(), S->getNumInputs(),
5792 S->getAllConstraints(), S->getClobbers(),
5793 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005794}
Douglas Gregor43959a92009-08-20 07:17:43 +00005795
5796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005797StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005798TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005799 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005800 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005801 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005803
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005804 // Transform the @catch statements (if present).
5805 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005806 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005807 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005808 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005809 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005810 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005811 if (Catch.get() != S->getCatchStmt(I))
5812 AnyCatchChanged = true;
5813 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005814 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005815
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005816 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005817 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005818 if (S->getFinallyStmt()) {
5819 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5820 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005822 }
5823
5824 // If nothing changed, just retain this statement.
5825 if (!getDerived().AlwaysRebuild() &&
5826 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005827 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005828 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005829 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005830
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005831 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005832 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005833 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005834}
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor43959a92009-08-20 07:17:43 +00005836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005837StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005838TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005839 // Transform the @catch parameter, if there is one.
5840 VarDecl *Var = 0;
5841 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5842 TypeSourceInfo *TSInfo = 0;
5843 if (FromVar->getTypeSourceInfo()) {
5844 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5845 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005846 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005847 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005848
Douglas Gregorbe270a02010-04-26 17:57:08 +00005849 QualType T;
5850 if (TSInfo)
5851 T = TSInfo->getType();
5852 else {
5853 T = getDerived().TransformType(FromVar->getType());
5854 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005855 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005856 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005857
Douglas Gregorbe270a02010-04-26 17:57:08 +00005858 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5859 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005861 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005862
John McCall60d7b3a2010-08-24 06:29:42 +00005863 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005864 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005865 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005866
5867 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005868 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005869 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005870}
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005873StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005874TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005875 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005876 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005877 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005878 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005879
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005880 // If nothing changed, just retain this statement.
5881 if (!getDerived().AlwaysRebuild() &&
5882 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005883 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005884
5885 // Build a new statement.
5886 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005887 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005888}
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Douglas Gregor43959a92009-08-20 07:17:43 +00005890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005891StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005892TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005893 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005894 if (S->getThrowExpr()) {
5895 Operand = getDerived().TransformExpr(S->getThrowExpr());
5896 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005897 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005898 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005899
Douglas Gregord1377b22010-04-22 21:44:01 +00005900 if (!getDerived().AlwaysRebuild() &&
5901 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005902 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005903
John McCall9ae2f072010-08-23 23:25:46 +00005904 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005905}
Mike Stump1eb44332009-09-09 15:08:12 +00005906
Douglas Gregor43959a92009-08-20 07:17:43 +00005907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005908StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005909TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005910 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005911 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005912 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005913 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005914 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005915 Object =
5916 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5917 Object.get());
5918 if (Object.isInvalid())
5919 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005920
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005921 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005922 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005923 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005924 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005925
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005926 // If nothing change, just retain the current statement.
5927 if (!getDerived().AlwaysRebuild() &&
5928 Object.get() == S->getSynchExpr() &&
5929 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005930 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005931
5932 // Build a new statement.
5933 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005934 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005935}
5936
5937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005938StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005939TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5940 ObjCAutoreleasePoolStmt *S) {
5941 // Transform the body.
5942 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5943 if (Body.isInvalid())
5944 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005945
John McCallf85e1932011-06-15 23:02:42 +00005946 // If nothing changed, just retain this statement.
5947 if (!getDerived().AlwaysRebuild() &&
5948 Body.get() == S->getSubStmt())
5949 return SemaRef.Owned(S);
5950
5951 // Build a new statement.
5952 return getDerived().RebuildObjCAutoreleasePoolStmt(
5953 S->getAtLoc(), Body.get());
5954}
5955
5956template<typename Derived>
5957StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005958TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005959 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005960 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005961 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005962 if (Element.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 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005966 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005967 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005968 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005969
Douglas Gregorc3203e72010-04-22 23:10:45 +00005970 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005971 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005972 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005973 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005974
Douglas Gregorc3203e72010-04-22 23:10:45 +00005975 // If nothing changed, just retain this statement.
5976 if (!getDerived().AlwaysRebuild() &&
5977 Element.get() == S->getElement() &&
5978 Collection.get() == S->getCollection() &&
5979 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005980 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorc3203e72010-04-22 23:10:45 +00005982 // Build a new statement.
5983 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005984 Element.get(),
5985 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005986 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005987 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005988}
5989
5990
5991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005992StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005993TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5994 // Transform the exception declaration, if any.
5995 VarDecl *Var = 0;
5996 if (S->getExceptionDecl()) {
5997 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005998 TypeSourceInfo *T = getDerived().TransformType(
5999 ExceptionDecl->getTypeSourceInfo());
6000 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006001 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006002
Douglas Gregor83cb9422010-09-09 17:09:21 +00006003 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00006004 ExceptionDecl->getInnerLocStart(),
6005 ExceptionDecl->getLocation(),
6006 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006007 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006008 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006009 }
Mike Stump1eb44332009-09-09 15:08:12 +00006010
Douglas Gregor43959a92009-08-20 07:17:43 +00006011 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006012 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006013 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006014 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006015
Douglas Gregor43959a92009-08-20 07:17:43 +00006016 if (!getDerived().AlwaysRebuild() &&
6017 !Var &&
6018 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006019 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006020
6021 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6022 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006023 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006024}
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregor43959a92009-08-20 07:17:43 +00006026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006027StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006028TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6029 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006030 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006031 = getDerived().TransformCompoundStmt(S->getTryBlock());
6032 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006033 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006034
Douglas Gregor43959a92009-08-20 07:17:43 +00006035 // Transform the handlers.
6036 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006037 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006039 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006040 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6041 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006042 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006043
Douglas Gregor43959a92009-08-20 07:17:43 +00006044 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6045 Handlers.push_back(Handler.takeAs<Stmt>());
6046 }
Mike Stump1eb44332009-09-09 15:08:12 +00006047
Douglas Gregor43959a92009-08-20 07:17:43 +00006048 if (!getDerived().AlwaysRebuild() &&
6049 TryBlock.get() == S->getTryBlock() &&
6050 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006051 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006052
John McCall9ae2f072010-08-23 23:25:46 +00006053 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006054 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006055}
Mike Stump1eb44332009-09-09 15:08:12 +00006056
Richard Smithad762fc2011-04-14 22:09:26 +00006057template<typename Derived>
6058StmtResult
6059TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6060 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6061 if (Range.isInvalid())
6062 return StmtError();
6063
6064 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6065 if (BeginEnd.isInvalid())
6066 return StmtError();
6067
6068 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6069 if (Cond.isInvalid())
6070 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006071 if (Cond.get())
6072 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6073 if (Cond.isInvalid())
6074 return StmtError();
6075 if (Cond.get())
6076 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006077
6078 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6079 if (Inc.isInvalid())
6080 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006081 if (Inc.get())
6082 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006083
6084 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6085 if (LoopVar.isInvalid())
6086 return StmtError();
6087
6088 StmtResult NewStmt = S;
6089 if (getDerived().AlwaysRebuild() ||
6090 Range.get() != S->getRangeStmt() ||
6091 BeginEnd.get() != S->getBeginEndStmt() ||
6092 Cond.get() != S->getCond() ||
6093 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006094 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006095 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6096 S->getColonLoc(), Range.get(),
6097 BeginEnd.get(), Cond.get(),
6098 Inc.get(), LoopVar.get(),
6099 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006100 if (NewStmt.isInvalid())
6101 return StmtError();
6102 }
Richard Smithad762fc2011-04-14 22:09:26 +00006103
6104 StmtResult Body = getDerived().TransformStmt(S->getBody());
6105 if (Body.isInvalid())
6106 return StmtError();
6107
6108 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6109 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006110 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006111 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6112 S->getColonLoc(), Range.get(),
6113 BeginEnd.get(), Cond.get(),
6114 Inc.get(), LoopVar.get(),
6115 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006116 if (NewStmt.isInvalid())
6117 return StmtError();
6118 }
Richard Smithad762fc2011-04-14 22:09:26 +00006119
6120 if (NewStmt.get() == S)
6121 return SemaRef.Owned(S);
6122
6123 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6124}
6125
John Wiegley28bbe4b2011-04-28 01:08:34 +00006126template<typename Derived>
6127StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006128TreeTransform<Derived>::TransformMSDependentExistsStmt(
6129 MSDependentExistsStmt *S) {
6130 // Transform the nested-name-specifier, if any.
6131 NestedNameSpecifierLoc QualifierLoc;
6132 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006133 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006134 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6135 if (!QualifierLoc)
6136 return StmtError();
6137 }
6138
6139 // Transform the declaration name.
6140 DeclarationNameInfo NameInfo = S->getNameInfo();
6141 if (NameInfo.getName()) {
6142 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6143 if (!NameInfo.getName())
6144 return StmtError();
6145 }
6146
6147 // Check whether anything changed.
6148 if (!getDerived().AlwaysRebuild() &&
6149 QualifierLoc == S->getQualifierLoc() &&
6150 NameInfo.getName() == S->getNameInfo().getName())
6151 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006152
Douglas Gregorba0513d2011-10-25 01:33:02 +00006153 // Determine whether this name exists, if we can.
6154 CXXScopeSpec SS;
6155 SS.Adopt(QualifierLoc);
6156 bool Dependent = false;
6157 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6158 case Sema::IER_Exists:
6159 if (S->isIfExists())
6160 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006161
Douglas Gregorba0513d2011-10-25 01:33:02 +00006162 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6163
6164 case Sema::IER_DoesNotExist:
6165 if (S->isIfNotExists())
6166 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006167
Douglas Gregorba0513d2011-10-25 01:33:02 +00006168 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006169
Douglas Gregorba0513d2011-10-25 01:33:02 +00006170 case Sema::IER_Dependent:
6171 Dependent = true;
6172 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006173
Douglas Gregor65019ac2011-10-25 03:44:56 +00006174 case Sema::IER_Error:
6175 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006177
Douglas Gregorba0513d2011-10-25 01:33:02 +00006178 // We need to continue with the instantiation, so do so now.
6179 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6180 if (SubStmt.isInvalid())
6181 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006182
Douglas Gregorba0513d2011-10-25 01:33:02 +00006183 // If we have resolved the name, just transform to the substatement.
6184 if (!Dependent)
6185 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006186
Douglas Gregorba0513d2011-10-25 01:33:02 +00006187 // The name is still dependent, so build a dependent expression again.
6188 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6189 S->isIfExists(),
6190 QualifierLoc,
6191 NameInfo,
6192 SubStmt.get());
6193}
6194
6195template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006196ExprResult
6197TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6198 NestedNameSpecifierLoc QualifierLoc;
6199 if (E->getQualifierLoc()) {
6200 QualifierLoc
6201 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6202 if (!QualifierLoc)
6203 return ExprError();
6204 }
6205
6206 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6207 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6208 if (!PD)
6209 return ExprError();
6210
6211 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6212 if (Base.isInvalid())
6213 return ExprError();
6214
6215 return new (SemaRef.getASTContext())
6216 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6217 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6218 QualifierLoc, E->getMemberLoc());
6219}
6220
6221template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006222StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006223TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6224 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6225 if(TryBlock.isInvalid()) return StmtError();
6226
6227 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6228 if(!getDerived().AlwaysRebuild() &&
6229 TryBlock.get() == S->getTryBlock() &&
6230 Handler.get() == S->getHandler())
6231 return SemaRef.Owned(S);
6232
6233 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6234 S->getTryLoc(),
6235 TryBlock.take(),
6236 Handler.take());
6237}
6238
6239template<typename Derived>
6240StmtResult
6241TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6242 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6243 if(Block.isInvalid()) return StmtError();
6244
6245 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6246 Block.take());
6247}
6248
6249template<typename Derived>
6250StmtResult
6251TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6252 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6253 if(FilterExpr.isInvalid()) return StmtError();
6254
6255 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6256 if(Block.isInvalid()) return StmtError();
6257
6258 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6259 FilterExpr.take(),
6260 Block.take());
6261}
6262
6263template<typename Derived>
6264StmtResult
6265TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6266 if(isa<SEHFinallyStmt>(Handler))
6267 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6268 else
6269 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6270}
6271
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006272template<typename Derived>
6273StmtResult
6274TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006275 DeclarationNameInfo DirName;
6276 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6277
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006278 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006279 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006280 ArrayRef<OMPClause *> Clauses = D->clauses();
6281 TClauses.reserve(Clauses.size());
6282 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6283 I != E; ++I) {
6284 if (*I) {
6285 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006286 if (!Clause) {
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 TClauses.push_back(Clause);
6291 }
6292 else {
6293 TClauses.push_back(0);
6294 }
6295 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006296 if (!D->getAssociatedStmt()) {
6297 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006298 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006299 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006300 StmtResult AssociatedStmt =
6301 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006302 if (AssociatedStmt.isInvalid()) {
6303 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006304 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006305 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006306
Alexey Bataev0c018352013-09-06 18:03:48 +00006307 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6308 AssociatedStmt.take(),
6309 D->getLocStart(),
6310 D->getLocEnd());
6311 getSema().EndOpenMPDSABlock(Res.get());
6312 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006313}
6314
6315template<typename Derived>
6316OMPClause *
6317TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6318 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6319 C->getDefaultKindKwLoc(),
6320 C->getLocStart(),
6321 C->getLParenLoc(),
6322 C->getLocEnd());
6323}
6324
6325template<typename Derived>
6326OMPClause *
6327TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006328 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006329 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006330 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6331 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006332 I != E; ++I) {
6333 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6334 if (EVar.isInvalid())
6335 return 0;
6336 Vars.push_back(EVar.take());
6337 }
6338 return getDerived().RebuildOMPPrivateClause(Vars,
6339 C->getLocStart(),
6340 C->getLParenLoc(),
6341 C->getLocEnd());
6342}
6343
Alexey Bataev0c018352013-09-06 18:03:48 +00006344template<typename Derived>
6345OMPClause *
6346TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6347 llvm::SmallVector<Expr *, 16> Vars;
6348 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006349 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6350 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006351 I != E; ++I) {
6352 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6353 if (EVar.isInvalid())
6354 return 0;
6355 Vars.push_back(EVar.take());
6356 }
6357 return getDerived().RebuildOMPSharedClause(Vars,
6358 C->getLocStart(),
6359 C->getLParenLoc(),
6360 C->getLocEnd());
6361}
6362
Douglas Gregor43959a92009-08-20 07:17:43 +00006363//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364// Expression transformation
6365//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006367ExprResult
John McCall454feb92009-12-08 09:21:05 +00006368TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370}
Mike Stump1eb44332009-09-09 15:08:12 +00006371
6372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006373ExprResult
John McCall454feb92009-12-08 09:21:05 +00006374TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006375 NestedNameSpecifierLoc QualifierLoc;
6376 if (E->getQualifierLoc()) {
6377 QualifierLoc
6378 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6379 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006380 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006381 }
John McCalldbd872f2009-12-08 09:08:17 +00006382
6383 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006384 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6385 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006388
John McCallec8045d2010-08-17 21:27:17 +00006389 DeclarationNameInfo NameInfo = E->getNameInfo();
6390 if (NameInfo.getName()) {
6391 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6392 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006393 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006394 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006395
6396 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006397 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006398 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006399 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006400 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006401
6402 // Mark it referenced in the new context regardless.
6403 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006404 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006405
John McCall3fa5cae2010-10-26 07:05:15 +00006406 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006407 }
John McCalldbd872f2009-12-08 09:08:17 +00006408
6409 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006410 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006411 TemplateArgs = &TransArgs;
6412 TransArgs.setLAngleLoc(E->getLAngleLoc());
6413 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006414 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6415 E->getNumTemplateArgs(),
6416 TransArgs))
6417 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006418 }
6419
Chad Rosier4a9d7952012-08-08 18:46:20 +00006420 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006421 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422}
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006425ExprResult
John McCall454feb92009-12-08 09:21:05 +00006426TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006427 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428}
Mike Stump1eb44332009-09-09 15:08:12 +00006429
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006431ExprResult
John McCall454feb92009-12-08 09:21:05 +00006432TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006433 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434}
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006437ExprResult
John McCall454feb92009-12-08 09:21:05 +00006438TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006439 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440}
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006443ExprResult
John McCall454feb92009-12-08 09:21:05 +00006444TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006445 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446}
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006449ExprResult
John McCall454feb92009-12-08 09:21:05 +00006450TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006451 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006452}
6453
6454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006455ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006456TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006457 if (FunctionDecl *FD = E->getDirectCallee())
6458 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006459 return SemaRef.MaybeBindToTemporary(E);
6460}
6461
6462template<typename Derived>
6463ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006464TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6465 ExprResult ControllingExpr =
6466 getDerived().TransformExpr(E->getControllingExpr());
6467 if (ControllingExpr.isInvalid())
6468 return ExprError();
6469
Chris Lattner686775d2011-07-20 06:58:45 +00006470 SmallVector<Expr *, 4> AssocExprs;
6471 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006472 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6473 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6474 if (TS) {
6475 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6476 if (!AssocType)
6477 return ExprError();
6478 AssocTypes.push_back(AssocType);
6479 } else {
6480 AssocTypes.push_back(0);
6481 }
6482
6483 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6484 if (AssocExpr.isInvalid())
6485 return ExprError();
6486 AssocExprs.push_back(AssocExpr.release());
6487 }
6488
6489 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6490 E->getDefaultLoc(),
6491 E->getRParenLoc(),
6492 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006493 AssocTypes,
6494 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006495}
6496
6497template<typename Derived>
6498ExprResult
John McCall454feb92009-12-08 09:21:05 +00006499TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006500 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006505 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006506
John McCall9ae2f072010-08-23 23:25:46 +00006507 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 E->getRParen());
6509}
6510
Richard Smithefeeccf2012-10-21 03:28:35 +00006511/// \brief The operand of a unary address-of operator has special rules: it's
6512/// allowed to refer to a non-static member of a class even if there's no 'this'
6513/// object available.
6514template<typename Derived>
6515ExprResult
6516TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6517 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6518 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6519 else
6520 return getDerived().TransformExpr(E);
6521}
6522
Mike Stump1eb44332009-09-09 15:08:12 +00006523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006524ExprResult
John McCall454feb92009-12-08 09:21:05 +00006525TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006526 ExprResult SubExpr;
6527 if (E->getOpcode() == UO_AddrOf)
6528 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6529 else
6530 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006535 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6538 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006539 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540}
Mike Stump1eb44332009-09-09 15:08:12 +00006541
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006543ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006544TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6545 // Transform the type.
6546 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6547 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006549
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006550 // Transform all of the components into components similar to what the
6551 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006552 // FIXME: It would be slightly more efficient in the non-dependent case to
6553 // just map FieldDecls, rather than requiring the rebuilder to look for
6554 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006555 // template code that we don't care.
6556 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006557 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006558 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006559 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006560 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6561 const Node &ON = E->getComponent(I);
6562 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006563 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006564 Comp.LocStart = ON.getSourceRange().getBegin();
6565 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006566 switch (ON.getKind()) {
6567 case Node::Array: {
6568 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006570 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006572
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006573 ExprChanged = ExprChanged || Index.get() != FromIndex;
6574 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006575 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006576 break;
6577 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006578
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006579 case Node::Field:
6580 case Node::Identifier:
6581 Comp.isBrackets = false;
6582 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006583 if (!Comp.U.IdentInfo)
6584 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006585
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006586 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006587
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006588 case Node::Base:
6589 // Will be recomputed during the rebuild.
6590 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006591 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006592
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006593 Components.push_back(Comp);
6594 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006595
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006596 // If nothing changed, retain the existing expression.
6597 if (!getDerived().AlwaysRebuild() &&
6598 Type == E->getTypeSourceInfo() &&
6599 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006600 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006601
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006602 // Build a new offsetof expression.
6603 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6604 Components.data(), Components.size(),
6605 E->getRParenLoc());
6606}
6607
6608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006609ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006610TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6611 assert(getDerived().AlreadyTransformed(E->getType()) &&
6612 "opaque value expression requires transformation");
6613 return SemaRef.Owned(E);
6614}
6615
6616template<typename Derived>
6617ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006618TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006619 // Rebuild the syntactic form. The original syntactic form has
6620 // opaque-value expressions in it, so strip those away and rebuild
6621 // the result. This is a really awful way of doing this, but the
6622 // better solution (rebuilding the semantic expressions and
6623 // rebinding OVEs as necessary) doesn't work; we'd need
6624 // TreeTransform to not strip away implicit conversions.
6625 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6626 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006627 if (result.isInvalid()) return ExprError();
6628
6629 // If that gives us a pseudo-object result back, the pseudo-object
6630 // expression must have been an lvalue-to-rvalue conversion which we
6631 // should reapply.
6632 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6633 result = SemaRef.checkPseudoObjectRValue(result.take());
6634
6635 return result;
6636}
6637
6638template<typename Derived>
6639ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006640TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6641 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006643 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006644
John McCalla93c9342009-12-07 02:54:59 +00006645 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006646 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006648
John McCall5ab75172009-11-04 07:28:41 +00006649 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006652 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6653 E->getKind(),
6654 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 }
Mike Stump1eb44332009-09-09 15:08:12 +00006656
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006657 // C++0x [expr.sizeof]p1:
6658 // The operand is either an expression, which is an unevaluated operand
6659 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6661 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006663 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6664 if (SubExpr.isInvalid())
6665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006667 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6668 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006670 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6671 E->getOperatorLoc(),
6672 E->getKind(),
6673 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674}
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006677ExprResult
John McCall454feb92009-12-08 09:21:05 +00006678TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006679 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006681 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006682
John McCall60d7b3a2010-08-24 06:29:42 +00006683 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006686
6687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 if (!getDerived().AlwaysRebuild() &&
6689 LHS.get() == E->getLHS() &&
6690 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006691 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006692
John McCall9ae2f072010-08-23 23:25:46 +00006693 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006695 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 E->getRBracketLoc());
6697}
Mike Stump1eb44332009-09-09 15:08:12 +00006698
6699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006700ExprResult
John McCall454feb92009-12-08 09:21:05 +00006701TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006703 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006705 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706
6707 // Transform arguments.
6708 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006709 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006710 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006711 &ArgChanged))
6712 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (!getDerived().AlwaysRebuild() &&
6715 Callee.get() == E->getCallee() &&
6716 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006717 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006720 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006722 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006723 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 E->getRParenLoc());
6725}
Mike Stump1eb44332009-09-09 15:08:12 +00006726
6727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006728ExprResult
John McCall454feb92009-12-08 09:21:05 +00006729TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Douglas Gregor40d96a62011-02-28 21:54:11 +00006734 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006735 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006736 QualifierLoc
6737 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006738
Douglas Gregor40d96a62011-02-28 21:54:11 +00006739 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006740 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006741 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006742 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Eli Friedmanf595cc42009-12-04 06:40:45 +00006744 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006745 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6746 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006749
John McCall6bb80172010-03-30 21:47:33 +00006750 NamedDecl *FoundDecl = E->getFoundDecl();
6751 if (FoundDecl == E->getMemberDecl()) {
6752 FoundDecl = Member;
6753 } else {
6754 FoundDecl = cast_or_null<NamedDecl>(
6755 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6756 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006757 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006758 }
6759
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 if (!getDerived().AlwaysRebuild() &&
6761 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006762 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006763 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006764 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006765 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006766
Anders Carlsson1f240322009-12-22 05:24:09 +00006767 // Mark it referenced in the new context regardless.
6768 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006769 SemaRef.MarkMemberReferenced(E);
6770
John McCall3fa5cae2010-10-26 07:05:15 +00006771 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006772 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773
John McCalld5532b62009-11-23 01:53:49 +00006774 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006775 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006776 TransArgs.setLAngleLoc(E->getLAngleLoc());
6777 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006778 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6779 E->getNumTemplateArgs(),
6780 TransArgs))
6781 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006782 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784 // FIXME: Bogus source location for the operator
6785 SourceLocation FakeOperatorLoc
6786 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6787
John McCallc2233c52010-01-15 08:34:02 +00006788 // FIXME: to do this check properly, we will need to preserve the
6789 // first-qualifier-in-scope here, just in case we had a dependent
6790 // base (and therefore couldn't do the check) and a
6791 // nested-name-qualifier (and therefore could do the lookup).
6792 NamedDecl *FirstQualifierInScope = 0;
6793
John McCall9ae2f072010-08-23 23:25:46 +00006794 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006796 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006797 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006798 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006799 Member,
John McCall6bb80172010-03-30 21:47:33 +00006800 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006801 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006802 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006803 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804}
Mike Stump1eb44332009-09-09 15:08:12 +00006805
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006807ExprResult
John McCall454feb92009-12-08 09:21:05 +00006808TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006809 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006811 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006812
John McCall60d7b3a2010-08-24 06:29:42 +00006813 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006815 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 if (!getDerived().AlwaysRebuild() &&
6818 LHS.get() == E->getLHS() &&
6819 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006820 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Lang Hamesbe9af122012-10-02 04:45:10 +00006822 Sema::FPContractStateRAII FPContractState(getSema());
6823 getSema().FPFeatures.fp_contract = E->isFPContractable();
6824
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006826 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827}
6828
Mike Stump1eb44332009-09-09 15:08:12 +00006829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006830ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006832 CompoundAssignOperator *E) {
6833 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834}
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006837ExprResult TreeTransform<Derived>::
6838TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6839 // Just rebuild the common and RHS expressions and see whether we
6840 // get any changes.
6841
6842 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6843 if (commonExpr.isInvalid())
6844 return ExprError();
6845
6846 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6847 if (rhs.isInvalid())
6848 return ExprError();
6849
6850 if (!getDerived().AlwaysRebuild() &&
6851 commonExpr.get() == e->getCommon() &&
6852 rhs.get() == e->getFalseExpr())
6853 return SemaRef.Owned(e);
6854
6855 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6856 e->getQuestionLoc(),
6857 0,
6858 e->getColonLoc(),
6859 rhs.get());
6860}
6861
6862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006865 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006868
John McCall60d7b3a2010-08-24 06:29:42 +00006869 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006872
John McCall60d7b3a2010-08-24 06:29:42 +00006873 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006876
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 if (!getDerived().AlwaysRebuild() &&
6878 Cond.get() == E->getCond() &&
6879 LHS.get() == E->getLHS() &&
6880 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006881 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006882
John McCall9ae2f072010-08-23 23:25:46 +00006883 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006884 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006885 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006886 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006887 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888}
Mike Stump1eb44332009-09-09 15:08:12 +00006889
6890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006891ExprResult
John McCall454feb92009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006893 // Implicit casts are eliminated during transformation, since they
6894 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006895 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896}
Mike Stump1eb44332009-09-09 15:08:12 +00006897
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006899ExprResult
John McCall454feb92009-12-08 09:21:05 +00006900TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006901 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6902 if (!Type)
6903 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006904
John McCall60d7b3a2010-08-24 06:29:42 +00006905 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006906 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006908 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006909
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006911 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006913 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006914
John McCall9d125032010-01-15 18:39:57 +00006915 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006916 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006918 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919}
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006922ExprResult
John McCall454feb92009-12-08 09:21:05 +00006923TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006924 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6925 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6926 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006928
John McCall60d7b3a2010-08-24 06:29:42 +00006929 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006932
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006934 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006936 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937
John McCall1d7d8d62010-01-19 22:33:45 +00006938 // Note: the expression type doesn't necessarily match the
6939 // type-as-written, but that's okay, because it should always be
6940 // derivable from the initializer.
6941
John McCall42f56b52010-01-18 19:35:47 +00006942 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006944 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945}
Mike Stump1eb44332009-09-09 15:08:12 +00006946
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006948ExprResult
John McCall454feb92009-12-08 09:21:05 +00006949TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006950 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006952 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006953
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 if (!getDerived().AlwaysRebuild() &&
6955 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006956 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006959 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006961 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 E->getAccessorLoc(),
6963 E->getAccessor());
6964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006971 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006972 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006973 Inits, &InitChanged))
6974 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006975
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006979 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006980 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981}
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006984ExprResult
John McCall454feb92009-12-08 09:21:05 +00006985TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregor43959a92009-08-20 07:17:43 +00006988 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006989 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006991 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Douglas Gregor43959a92009-08-20 07:17:43 +00006993 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006994 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 bool ExprChanged = false;
6996 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6997 DEnd = E->designators_end();
6998 D != DEnd; ++D) {
6999 if (D->isFieldDesignator()) {
7000 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7001 D->getDotLoc(),
7002 D->getFieldLoc()));
7003 continue;
7004 }
Mike Stump1eb44332009-09-09 15:08:12 +00007005
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007007 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007010
7011 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7015 ArrayExprs.push_back(Index.release());
7016 continue;
7017 }
Mike Stump1eb44332009-09-09 15:08:12 +00007018
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007020 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7022 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007024
John McCall60d7b3a2010-08-24 06:29:42 +00007025 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
7029 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 End.get(),
7031 D->getLBracketLoc(),
7032 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7035 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 ArrayExprs.push_back(Start.release());
7038 ArrayExprs.push_back(End.release());
7039 }
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 if (!getDerived().AlwaysRebuild() &&
7042 Init.get() == E->getInit() &&
7043 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007044 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007046 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007048 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049}
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007052ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007054 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007055 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007056
Douglas Gregor5557b252009-10-28 00:29:27 +00007057 // FIXME: Will we ever have proper type location here? Will we actually
7058 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 QualType T = getDerived().TransformType(E->getType());
7060 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007061 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 if (!getDerived().AlwaysRebuild() &&
7064 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007065 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 return getDerived().RebuildImplicitValueInitExpr(T);
7068}
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007071ExprResult
John McCall454feb92009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007073 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7074 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007076
John McCall60d7b3a2010-08-24 06:29:42 +00007077 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007082 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
John McCall9ae2f072010-08-23 23:25:46 +00007086 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007087 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088}
7089
7090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007091ExprResult
John McCall454feb92009-12-08 09:21:05 +00007092TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007094 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007095 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7096 &ArgumentChanged))
7097 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007100 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 E->getRParenLoc());
7102}
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104/// \brief Transform an address-of-label expression.
7105///
7106/// By default, the transformation of an address-of-label expression always
7107/// rebuilds the expression, so that the label identifier can be resolved to
7108/// the corresponding label statement by semantic analysis.
7109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007110ExprResult
John McCall454feb92009-12-08 09:21:05 +00007111TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007112 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7113 E->getLabel());
7114 if (!LD)
7115 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007118 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119}
Mike Stump1eb44332009-09-09 15:08:12 +00007120
7121template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007124 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007125 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007127 if (SubStmt.isInvalid()) {
7128 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007130 }
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007133 SubStmt.get() == E->getSubStmt()) {
7134 // Calling this an 'error' is unintuitive, but it does the right thing.
7135 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007136 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007137 }
Mike Stump1eb44332009-09-09 15:08:12 +00007138
7139 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007140 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141 E->getRParenLoc());
7142}
Mike Stump1eb44332009-09-09 15:08:12 +00007143
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007145ExprResult
John McCall454feb92009-12-08 09:21:05 +00007146TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007147 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007149 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007150
John McCall60d7b3a2010-08-24 06:29:42 +00007151 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007153 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007154
John McCall60d7b3a2010-08-24 06:29:42 +00007155 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 if (!getDerived().AlwaysRebuild() &&
7160 Cond.get() == E->getCond() &&
7161 LHS.get() == E->getLHS() &&
7162 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007164
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007166 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 E->getRParenLoc());
7168}
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
John McCall454feb92009-12-08 09:21:05 +00007172TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007173 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174}
7175
7176template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007177ExprResult
John McCall454feb92009-12-08 09:21:05 +00007178TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007179 switch (E->getOperator()) {
7180 case OO_New:
7181 case OO_Delete:
7182 case OO_Array_New:
7183 case OO_Array_Delete:
7184 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007185
Douglas Gregor668d6d92009-12-13 20:44:55 +00007186 case OO_Call: {
7187 // This is a call to an object's operator().
7188 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7189
7190 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007191 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007192 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007193 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007194
7195 // FIXME: Poor location information
7196 SourceLocation FakeLParenLoc
7197 = SemaRef.PP.getLocForEndOfToken(
7198 static_cast<Expr *>(Object.get())->getLocEnd());
7199
7200 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007201 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007202 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007203 Args))
7204 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007205
John McCall9ae2f072010-08-23 23:25:46 +00007206 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007207 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007208 E->getLocEnd());
7209 }
7210
7211#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7212 case OO_##Name:
7213#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7214#include "clang/Basic/OperatorKinds.def"
7215 case OO_Subscript:
7216 // Handled below.
7217 break;
7218
7219 case OO_Conditional:
7220 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007221
7222 case OO_None:
7223 case NUM_OVERLOADED_OPERATORS:
7224 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007225 }
7226
John McCall60d7b3a2010-08-24 06:29:42 +00007227 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007228 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007229 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007230
Richard Smithefeeccf2012-10-21 03:28:35 +00007231 ExprResult First;
7232 if (E->getOperator() == OO_Amp)
7233 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7234 else
7235 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007237 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238
John McCall60d7b3a2010-08-24 06:29:42 +00007239 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007240 if (E->getNumArgs() == 2) {
7241 Second = getDerived().TransformExpr(E->getArg(1));
7242 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 }
Mike Stump1eb44332009-09-09 15:08:12 +00007245
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246 if (!getDerived().AlwaysRebuild() &&
7247 Callee.get() == E->getCallee() &&
7248 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007249 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007250 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Lang Hamesbe9af122012-10-02 04:45:10 +00007252 Sema::FPContractStateRAII FPContractState(getSema());
7253 getSema().FPFeatures.fp_contract = E->isFPContractable();
7254
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7256 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007257 Callee.get(),
7258 First.get(),
7259 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260}
Mike Stump1eb44332009-09-09 15:08:12 +00007261
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007263ExprResult
John McCall454feb92009-12-08 09:21:05 +00007264TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7265 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266}
Mike Stump1eb44332009-09-09 15:08:12 +00007267
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007269ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007270TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7271 // Transform the callee.
7272 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7273 if (Callee.isInvalid())
7274 return ExprError();
7275
7276 // Transform exec config.
7277 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7278 if (EC.isInvalid())
7279 return ExprError();
7280
7281 // Transform arguments.
7282 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007283 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007284 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007285 &ArgChanged))
7286 return ExprError();
7287
7288 if (!getDerived().AlwaysRebuild() &&
7289 Callee.get() == E->getCallee() &&
7290 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007291 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007292
7293 // FIXME: Wrong source location information for the '('.
7294 SourceLocation FakeLParenLoc
7295 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7296 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007297 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007298 E->getRParenLoc(), EC.get());
7299}
7300
7301template<typename Derived>
7302ExprResult
John McCall454feb92009-12-08 09:21:05 +00007303TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007304 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7305 if (!Type)
7306 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007307
John McCall60d7b3a2010-08-24 06:29:42 +00007308 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007309 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007314 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007316 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007318 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007319 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007320 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007321 E->getAngleBrackets().getEnd(),
7322 // FIXME. this should be '(' location
7323 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007324 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007325 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326}
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007329ExprResult
John McCall454feb92009-12-08 09:21:05 +00007330TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7331 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332}
Mike Stump1eb44332009-09-09 15:08:12 +00007333
7334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007335ExprResult
John McCall454feb92009-12-08 09:21:05 +00007336TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7337 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007338}
7339
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007341ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007343 CXXReinterpretCastExpr *E) {
7344 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345}
Mike Stump1eb44332009-09-09 15:08:12 +00007346
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007348ExprResult
John McCall454feb92009-12-08 09:21:05 +00007349TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7350 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351}
Mike Stump1eb44332009-09-09 15:08:12 +00007352
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007354ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007356 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007357 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7358 if (!Type)
7359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007360
John McCall60d7b3a2010-08-24 06:29:42 +00007361 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007362 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007364 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007365
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007367 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007371 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007372 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007373 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374 E->getRParenLoc());
7375}
Mike Stump1eb44332009-09-09 15:08:12 +00007376
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007378ExprResult
John McCall454feb92009-12-08 09:21:05 +00007379TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007381 TypeSourceInfo *TInfo
7382 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7383 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007384 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007387 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007388 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007389
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007390 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7391 E->getLocStart(),
7392 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 E->getLocEnd());
7394 }
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Eli Friedmanef331b72012-01-20 01:26:23 +00007396 // We don't know whether the subexpression is potentially evaluated until
7397 // after we perform semantic analysis. We speculatively assume it is
7398 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7401 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007402
John McCall60d7b3a2010-08-24 06:29:42 +00007403 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007406
Douglas Gregorb98b1992009-08-11 05:31:07 +00007407 if (!getDerived().AlwaysRebuild() &&
7408 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007409 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007410
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007411 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7412 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007413 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414 E->getLocEnd());
7415}
7416
7417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007418ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007419TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7420 if (E->isTypeOperand()) {
7421 TypeSourceInfo *TInfo
7422 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7423 if (!TInfo)
7424 return ExprError();
7425
7426 if (!getDerived().AlwaysRebuild() &&
7427 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007428 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007429
Douglas Gregor3c52a212011-03-06 17:40:41 +00007430 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007431 E->getLocStart(),
7432 TInfo,
7433 E->getLocEnd());
7434 }
7435
Francois Pichet01b7c302010-09-08 12:20:18 +00007436 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7437
7438 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7439 if (SubExpr.isInvalid())
7440 return ExprError();
7441
7442 if (!getDerived().AlwaysRebuild() &&
7443 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007444 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007445
7446 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7447 E->getLocStart(),
7448 SubExpr.get(),
7449 E->getLocEnd());
7450}
7451
7452template<typename Derived>
7453ExprResult
John McCall454feb92009-12-08 09:21:05 +00007454TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007455 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456}
Mike Stump1eb44332009-09-09 15:08:12 +00007457
Douglas Gregorb98b1992009-08-11 05:31:07 +00007458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007459ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007460TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007461 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007462 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463}
Mike Stump1eb44332009-09-09 15:08:12 +00007464
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007466ExprResult
John McCall454feb92009-12-08 09:21:05 +00007467TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007468 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007469
Douglas Gregorec79d872012-02-24 17:41:38 +00007470 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7471 // Make sure that we capture 'this'.
7472 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007473 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007474 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007475
Douglas Gregor828a1972010-01-07 23:12:05 +00007476 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477}
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007480ExprResult
John McCall454feb92009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007482 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007485
Douglas Gregorb98b1992009-08-11 05:31:07 +00007486 if (!getDerived().AlwaysRebuild() &&
7487 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007488 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007489
Douglas Gregorbca01b42011-07-06 22:04:06 +00007490 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7491 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492}
Mike Stump1eb44332009-09-09 15:08:12 +00007493
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007495ExprResult
John McCall454feb92009-12-08 09:21:05 +00007496TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007497 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007498 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7499 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007503 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007505 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007506
Douglas Gregor036aed12009-12-23 23:03:06 +00007507 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508}
Mike Stump1eb44332009-09-09 15:08:12 +00007509
Douglas Gregorb98b1992009-08-11 05:31:07 +00007510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007511ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007512TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7513 FieldDecl *Field
7514 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7515 E->getField()));
7516 if (!Field)
7517 return ExprError();
7518
7519 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7520 return SemaRef.Owned(E);
7521
7522 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7523}
7524
7525template<typename Derived>
7526ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007527TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7528 CXXScalarValueInitExpr *E) {
7529 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7530 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007532
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007534 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007535 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007536
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007538 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007539 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540}
Mike Stump1eb44332009-09-09 15:08:12 +00007541
Douglas Gregorb98b1992009-08-11 05:31:07 +00007542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007543ExprResult
John McCall454feb92009-12-08 09:21:05 +00007544TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007546 TypeSourceInfo *AllocTypeInfo
7547 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7548 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007550
Douglas Gregorb98b1992009-08-11 05:31:07 +00007551 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007552 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007553 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556 // Transform the placement arguments (if any).
7557 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007558 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007559 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007560 E->getNumPlacementArgs(), true,
7561 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007563
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007564 // Transform the initializer (if any).
7565 Expr *OldInit = E->getInitializer();
7566 ExprResult NewInit;
7567 if (OldInit)
7568 NewInit = getDerived().TransformExpr(OldInit);
7569 if (NewInit.isInvalid())
7570 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007571
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007572 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007573 FunctionDecl *OperatorNew = 0;
7574 if (E->getOperatorNew()) {
7575 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007576 getDerived().TransformDecl(E->getLocStart(),
7577 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007578 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007579 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007580 }
7581
7582 FunctionDecl *OperatorDelete = 0;
7583 if (E->getOperatorDelete()) {
7584 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007585 getDerived().TransformDecl(E->getLocStart(),
7586 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007587 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007588 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007589 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007590
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007592 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007594 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007595 OperatorNew == E->getOperatorNew() &&
7596 OperatorDelete == E->getOperatorDelete() &&
7597 !ArgumentChanged) {
7598 // Mark any declarations we need as referenced.
7599 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007600 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007601 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007602 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007603 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007605 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007606 QualType ElementType
7607 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7608 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7609 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7610 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007611 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007612 }
7613 }
7614 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007615
John McCall3fa5cae2010-10-26 07:05:15 +00007616 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007617 }
Mike Stump1eb44332009-09-09 15:08:12 +00007618
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007619 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007620 if (!ArraySize.get()) {
7621 // If no array size was specified, but the new expression was
7622 // instantiated with an array type (e.g., "new T" where T is
7623 // instantiated with "int[4]"), extract the outer bound from the
7624 // array type as our array size. We do this with constant and
7625 // dependently-sized array types.
7626 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7627 if (!ArrayT) {
7628 // Do nothing
7629 } else if (const ConstantArrayType *ConsArrayT
7630 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007632 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007633 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007634 SemaRef.Context.getSizeType(),
7635 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007636 AllocType = ConsArrayT->getElementType();
7637 } else if (const DependentSizedArrayType *DepArrayT
7638 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7639 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007640 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007641 AllocType = DepArrayT->getElementType();
7642 }
7643 }
7644 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007645
Douglas Gregorb98b1992009-08-11 05:31:07 +00007646 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7647 E->isGlobalNew(),
7648 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007649 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007651 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007652 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007653 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007654 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007655 E->getDirectInitRange(),
7656 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007657}
Mike Stump1eb44332009-09-09 15:08:12 +00007658
Douglas Gregorb98b1992009-08-11 05:31:07 +00007659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007660ExprResult
John McCall454feb92009-12-08 09:21:05 +00007661TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007662 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007663 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007665
Douglas Gregor1af74512010-02-26 00:38:10 +00007666 // Transform the delete operator, if known.
7667 FunctionDecl *OperatorDelete = 0;
7668 if (E->getOperatorDelete()) {
7669 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007670 getDerived().TransformDecl(E->getLocStart(),
7671 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007672 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007673 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007675
Douglas Gregorb98b1992009-08-11 05:31:07 +00007676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007677 Operand.get() == E->getArgument() &&
7678 OperatorDelete == E->getOperatorDelete()) {
7679 // Mark any declarations we need as referenced.
7680 // FIXME: instantiation-specific.
7681 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007682 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007683
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007684 if (!E->getArgument()->isTypeDependent()) {
7685 QualType Destroyed = SemaRef.Context.getBaseElementType(
7686 E->getDestroyedType());
7687 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7688 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007690 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007691 }
7692 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007693
John McCall3fa5cae2010-10-26 07:05:15 +00007694 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007695 }
Mike Stump1eb44332009-09-09 15:08:12 +00007696
Douglas Gregorb98b1992009-08-11 05:31:07 +00007697 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7698 E->isGlobalDelete(),
7699 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007700 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007701}
Mike Stump1eb44332009-09-09 15:08:12 +00007702
Douglas Gregorb98b1992009-08-11 05:31:07 +00007703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007704ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007705TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007706 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007707 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007708 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007710
John McCallb3d87482010-08-24 05:47:05 +00007711 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007712 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007713 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007714 E->getOperatorLoc(),
7715 E->isArrow()? tok::arrow : tok::period,
7716 ObjectTypePtr,
7717 MayBePseudoDestructor);
7718 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007719 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007720
John McCallb3d87482010-08-24 05:47:05 +00007721 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007722 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7723 if (QualifierLoc) {
7724 QualifierLoc
7725 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7726 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007727 return ExprError();
7728 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007729 CXXScopeSpec SS;
7730 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007731
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007732 PseudoDestructorTypeStorage Destroyed;
7733 if (E->getDestroyedTypeInfo()) {
7734 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007735 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007736 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007737 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007738 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007739 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007740 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007741 // We aren't likely to be able to resolve the identifier down to a type
7742 // now anyway, so just retain the identifier.
7743 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7744 E->getDestroyedTypeLoc());
7745 } else {
7746 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007747 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007748 *E->getDestroyedTypeIdentifier(),
7749 E->getDestroyedTypeLoc(),
7750 /*Scope=*/0,
7751 SS, ObjectTypePtr,
7752 false);
7753 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007754 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007755
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007756 Destroyed
7757 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7758 E->getDestroyedTypeLoc());
7759 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007760
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007761 TypeSourceInfo *ScopeTypeInfo = 0;
7762 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007763 CXXScopeSpec EmptySS;
7764 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7765 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007766 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007767 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007768 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007769
John McCall9ae2f072010-08-23 23:25:46 +00007770 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007771 E->getOperatorLoc(),
7772 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007773 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007774 ScopeTypeInfo,
7775 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007776 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007777 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007778}
Mike Stump1eb44332009-09-09 15:08:12 +00007779
Douglas Gregora71d8192009-09-04 17:36:40 +00007780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007781ExprResult
John McCallba135432009-11-21 08:51:07 +00007782TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007783 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007784 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7785 Sema::LookupOrdinaryName);
7786
7787 // Transform all the decls.
7788 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7789 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007790 NamedDecl *InstD = static_cast<NamedDecl*>(
7791 getDerived().TransformDecl(Old->getNameLoc(),
7792 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007793 if (!InstD) {
7794 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7795 // This can happen because of dependent hiding.
7796 if (isa<UsingShadowDecl>(*I))
7797 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007798 else {
7799 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007800 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007801 }
John McCall9f54ad42009-12-10 09:41:52 +00007802 }
John McCallf7a1a742009-11-24 19:00:30 +00007803
7804 // Expand using declarations.
7805 if (isa<UsingDecl>(InstD)) {
7806 UsingDecl *UD = cast<UsingDecl>(InstD);
7807 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7808 E = UD->shadow_end(); I != E; ++I)
7809 R.addDecl(*I);
7810 continue;
7811 }
7812
7813 R.addDecl(InstD);
7814 }
7815
7816 // Resolve a kind, but don't do any further analysis. If it's
7817 // ambiguous, the callee needs to deal with it.
7818 R.resolveKind();
7819
7820 // Rebuild the nested-name qualifier, if present.
7821 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007822 if (Old->getQualifierLoc()) {
7823 NestedNameSpecifierLoc QualifierLoc
7824 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7825 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007826 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007827
Douglas Gregor4c9be892011-02-28 20:01:57 +00007828 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007829 }
7830
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007831 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007832 CXXRecordDecl *NamingClass
7833 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7834 Old->getNameLoc(),
7835 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007836 if (!NamingClass) {
7837 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007838 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007840
Douglas Gregor66c45152010-04-27 16:10:10 +00007841 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007842 }
7843
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007844 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7845
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007846 // If we have neither explicit template arguments, nor the template keyword,
7847 // it's a normal declaration name.
7848 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007849 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7850
7851 // If we have template arguments, rebuild them, then rebuild the
7852 // templateid expression.
7853 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007854 if (Old->hasExplicitTemplateArgs() &&
7855 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007856 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007857 TransArgs)) {
7858 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007859 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007860 }
John McCallf7a1a742009-11-24 19:00:30 +00007861
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007862 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007863 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864}
Mike Stump1eb44332009-09-09 15:08:12 +00007865
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007867ExprResult
John McCall454feb92009-12-08 09:21:05 +00007868TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007869 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7870 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007872
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007874 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007875 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007876
Mike Stump1eb44332009-09-09 15:08:12 +00007877 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879 T,
7880 E->getLocEnd());
7881}
Mike Stump1eb44332009-09-09 15:08:12 +00007882
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007884ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007885TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7886 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7887 if (!LhsT)
7888 return ExprError();
7889
7890 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7891 if (!RhsT)
7892 return ExprError();
7893
7894 if (!getDerived().AlwaysRebuild() &&
7895 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7896 return SemaRef.Owned(E);
7897
7898 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7899 E->getLocStart(),
7900 LhsT, RhsT,
7901 E->getLocEnd());
7902}
7903
7904template<typename Derived>
7905ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007906TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7907 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007908 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007909 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7910 TypeSourceInfo *From = E->getArg(I);
7911 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007912 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007913 TypeLocBuilder TLB;
7914 TLB.reserve(FromTL.getFullDataSize());
7915 QualType To = getDerived().TransformType(TLB, FromTL);
7916 if (To.isNull())
7917 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007918
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007919 if (To == From->getType())
7920 Args.push_back(From);
7921 else {
7922 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7923 ArgChanged = true;
7924 }
7925 continue;
7926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007927
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007928 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007929
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007930 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007931 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007932 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7933 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7934 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007935
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007936 // Determine whether the set of unexpanded parameter packs can and should
7937 // be expanded.
7938 bool Expand = true;
7939 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007940 Optional<unsigned> OrigNumExpansions =
7941 ExpansionTL.getTypePtr()->getNumExpansions();
7942 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007943 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7944 PatternTL.getSourceRange(),
7945 Unexpanded,
7946 Expand, RetainExpansion,
7947 NumExpansions))
7948 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007949
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007950 if (!Expand) {
7951 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007953 // expansion.
7954 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007955
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007956 TypeLocBuilder TLB;
7957 TLB.reserve(From->getTypeLoc().getFullDataSize());
7958
7959 QualType To = getDerived().TransformType(TLB, PatternTL);
7960 if (To.isNull())
7961 return ExprError();
7962
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007964 PatternTL.getSourceRange(),
7965 ExpansionTL.getEllipsisLoc(),
7966 NumExpansions);
7967 if (To.isNull())
7968 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007970 PackExpansionTypeLoc ToExpansionTL
7971 = TLB.push<PackExpansionTypeLoc>(To);
7972 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7973 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7974 continue;
7975 }
7976
7977 // Expand the pack expansion by substituting for each argument in the
7978 // pack(s).
7979 for (unsigned I = 0; I != *NumExpansions; ++I) {
7980 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7981 TypeLocBuilder TLB;
7982 TLB.reserve(PatternTL.getFullDataSize());
7983 QualType To = getDerived().TransformType(TLB, PatternTL);
7984 if (To.isNull())
7985 return ExprError();
7986
Eli Friedman20cfeca2013-07-19 21:49:32 +00007987 if (To->containsUnexpandedParameterPack()) {
7988 To = getDerived().RebuildPackExpansionType(To,
7989 PatternTL.getSourceRange(),
7990 ExpansionTL.getEllipsisLoc(),
7991 NumExpansions);
7992 if (To.isNull())
7993 return ExprError();
7994
7995 PackExpansionTypeLoc ToExpansionTL
7996 = TLB.push<PackExpansionTypeLoc>(To);
7997 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7998 }
7999
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008000 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8001 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008003 if (!RetainExpansion)
8004 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008005
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008006 // If we're supposed to retain a pack expansion, do so by temporarily
8007 // forgetting the partially-substituted parameter pack.
8008 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8009
8010 TypeLocBuilder TLB;
8011 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008013 QualType To = getDerived().TransformType(TLB, PatternTL);
8014 if (To.isNull())
8015 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008016
8017 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008018 PatternTL.getSourceRange(),
8019 ExpansionTL.getEllipsisLoc(),
8020 NumExpansions);
8021 if (To.isNull())
8022 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008024 PackExpansionTypeLoc ToExpansionTL
8025 = TLB.push<PackExpansionTypeLoc>(To);
8026 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8027 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8028 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008029
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008030 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8031 return SemaRef.Owned(E);
8032
8033 return getDerived().RebuildTypeTrait(E->getTrait(),
8034 E->getLocStart(),
8035 Args,
8036 E->getLocEnd());
8037}
8038
8039template<typename Derived>
8040ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008041TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8042 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8043 if (!T)
8044 return ExprError();
8045
8046 if (!getDerived().AlwaysRebuild() &&
8047 T == E->getQueriedTypeSourceInfo())
8048 return SemaRef.Owned(E);
8049
8050 ExprResult SubExpr;
8051 {
8052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8053 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8054 if (SubExpr.isInvalid())
8055 return ExprError();
8056
8057 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8058 return SemaRef.Owned(E);
8059 }
8060
8061 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8062 E->getLocStart(),
8063 T,
8064 SubExpr.get(),
8065 E->getLocEnd());
8066}
8067
8068template<typename Derived>
8069ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008070TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8071 ExprResult SubExpr;
8072 {
8073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8074 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8075 if (SubExpr.isInvalid())
8076 return ExprError();
8077
8078 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8079 return SemaRef.Owned(E);
8080 }
8081
8082 return getDerived().RebuildExpressionTrait(
8083 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8084}
8085
8086template<typename Derived>
8087ExprResult
John McCall865d4472009-11-19 22:55:06 +00008088TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008089 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008090 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8091}
8092
8093template<typename Derived>
8094ExprResult
8095TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8096 DependentScopeDeclRefExpr *E,
8097 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008098 NestedNameSpecifierLoc QualifierLoc
8099 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8100 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008101 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008102 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008103
John McCall43fed0d2010-11-12 08:19:04 +00008104 // TODO: If this is a conversion-function-id, verify that the
8105 // destination type name (if present) resolves the same way after
8106 // instantiation as it did in the local scope.
8107
Abramo Bagnara25777432010-08-11 22:01:17 +00008108 DeclarationNameInfo NameInfo
8109 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8110 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008112
John McCallf7a1a742009-11-24 19:00:30 +00008113 if (!E->hasExplicitTemplateArgs()) {
8114 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008115 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 // Note: it is sufficient to compare the Name component of NameInfo:
8117 // if name has not changed, DNLoc has not changed either.
8118 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008119 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008120
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008121 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008122 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008123 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008124 /*TemplateArgs*/ 0,
8125 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008126 }
John McCalld5532b62009-11-23 01:53:49 +00008127
8128 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008129 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8130 E->getNumTemplateArgs(),
8131 TransArgs))
8132 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008133
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008134 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008135 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008136 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008137 &TransArgs,
8138 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008139}
8140
8141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008142ExprResult
John McCall454feb92009-12-08 09:21:05 +00008143TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008144 // CXXConstructExprs other than for list-initialization and
8145 // CXXTemporaryObjectExpr are always implicit, so when we have
8146 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008147 if ((E->getNumArgs() == 1 ||
8148 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008149 (!getDerived().DropCallArgument(E->getArg(0))) &&
8150 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008151 return getDerived().TransformExpr(E->getArg(0));
8152
Douglas Gregorb98b1992009-08-11 05:31:07 +00008153 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8154
8155 QualType T = getDerived().TransformType(E->getType());
8156 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008157 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158
8159 CXXConstructorDecl *Constructor
8160 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008161 getDerived().TransformDecl(E->getLocStart(),
8162 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008165
Douglas Gregorb98b1992009-08-11 05:31:07 +00008166 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008167 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008168 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008169 &ArgumentChanged))
8170 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008171
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 if (!getDerived().AlwaysRebuild() &&
8173 T == E->getType() &&
8174 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008175 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008176 // Mark the constructor as referenced.
8177 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008178 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008179 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008180 }
Mike Stump1eb44332009-09-09 15:08:12 +00008181
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008182 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8183 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008184 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008185 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008186 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008187 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008188 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008189 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190}
Mike Stump1eb44332009-09-09 15:08:12 +00008191
Douglas Gregorb98b1992009-08-11 05:31:07 +00008192/// \brief Transform a C++ temporary-binding expression.
8193///
Douglas Gregor51326552009-12-24 18:51:59 +00008194/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8195/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008197ExprResult
John McCall454feb92009-12-08 09:21:05 +00008198TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008199 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200}
Mike Stump1eb44332009-09-09 15:08:12 +00008201
John McCall4765fa02010-12-06 08:20:24 +00008202/// \brief Transform a C++ expression that contains cleanups that should
8203/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008204///
John McCall4765fa02010-12-06 08:20:24 +00008205/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008206/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008208ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008209TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008210 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008211}
Mike Stump1eb44332009-09-09 15:08:12 +00008212
Douglas Gregorb98b1992009-08-11 05:31:07 +00008213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008214ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008216 CXXTemporaryObjectExpr *E) {
8217 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8218 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008220
Douglas Gregorb98b1992009-08-11 05:31:07 +00008221 CXXConstructorDecl *Constructor
8222 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008223 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008224 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008225 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008227
Douglas Gregorb98b1992009-08-11 05:31:07 +00008228 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008229 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008230 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008231 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008232 &ArgumentChanged))
8233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008234
Douglas Gregorb98b1992009-08-11 05:31:07 +00008235 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008236 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008237 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008238 !ArgumentChanged) {
8239 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008240 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008241 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008243
Richard Smithc83c2302012-12-19 01:39:02 +00008244 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008245 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8246 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008247 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008248 E->getLocEnd());
8249}
Mike Stump1eb44332009-09-09 15:08:12 +00008250
Douglas Gregorb98b1992009-08-11 05:31:07 +00008251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008252ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008253TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008254
8255 // FIXME: Implement nested generic lambda transformations.
8256 if (E->isGenericLambda()) {
8257 getSema().Diag(E->getIntroducerRange().getBegin(),
8258 diag::err_glambda_not_fully_implemented)
8259 << " template transformation of generic lambdas not implemented yet";
8260 return ExprError();
8261 }
Douglas Gregordfca6f52012-02-13 22:00:16 +00008262 // Transform the type of the lambda parameters and start the definition of
8263 // the lambda itself.
8264 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008265 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008266 if (!MethodTy)
8267 return ExprError();
8268
Eli Friedman8da8a662012-09-19 01:18:11 +00008269 // Create the local class that will describe the lambda.
8270 CXXRecordDecl *Class
8271 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8272 MethodTy,
8273 /*KnownDependent=*/false);
8274 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8275
Douglas Gregorc6889e72012-02-14 22:28:59 +00008276 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008277 SmallVector<QualType, 4> ParamTypes;
8278 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008279 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8280 E->getCallOperator()->param_begin(),
8281 E->getCallOperator()->param_size(),
8282 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008283 return ExprError();
Faisal Valifad9e132013-09-26 19:54:12 +00008284 getSema().PushLambdaScope();
8285 LambdaScopeInfo *LSI = getSema().getCurLambda();
8286 // TODO: Fix for nested lambdas
8287 LSI->GLTemplateParameterList = 0;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008288 // Build the call operator.
8289 CXXMethodDecl *CallOperator
8290 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008291 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008292 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008293 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008294 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008295
Richard Smith612409e2012-07-25 03:56:55 +00008296 return getDerived().TransformLambdaScope(E, CallOperator);
8297}
8298
8299template<typename Derived>
8300ExprResult
8301TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8302 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008303 bool Invalid = false;
8304
8305 // Transform any init-capture expressions before entering the scope of the
8306 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008307 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008308 InitCaptureExprs.resize(E->explicit_capture_end() -
8309 E->explicit_capture_begin());
8310 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8311 CEnd = E->capture_end();
8312 C != CEnd; ++C) {
8313 if (!C->isInitCapture())
8314 continue;
8315 InitCaptureExprs[C - E->capture_begin()] =
8316 getDerived().TransformExpr(E->getInitCaptureInit(C));
8317 }
8318
Douglas Gregord5387e82012-02-14 00:00:48 +00008319 // Introduce the context of the call operator.
8320 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8321
Faisal Valifad9e132013-09-26 19:54:12 +00008322 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008323 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008324 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008325 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008326 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008327 E->hasExplicitParameters(),
8328 E->hasExplicitResultType(),
8329 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008330
Douglas Gregordfca6f52012-02-13 22:00:16 +00008331 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008332 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008333 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008334 CEnd = E->capture_end();
8335 C != CEnd; ++C) {
8336 // When we hit the first implicit capture, tell Sema that we've finished
8337 // the list of explicit captures.
8338 if (!FinishedExplicitCaptures && C->isImplicit()) {
8339 getSema().finishLambdaExplicitCaptures(LSI);
8340 FinishedExplicitCaptures = true;
8341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008342
Douglas Gregordfca6f52012-02-13 22:00:16 +00008343 // Capturing 'this' is trivial.
8344 if (C->capturesThis()) {
8345 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8346 continue;
8347 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008348
Richard Smith0d8e9642013-05-16 06:20:58 +00008349 // Rebuild init-captures, including the implied field declaration.
8350 if (C->isInitCapture()) {
8351 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8352 if (Init.isInvalid()) {
8353 Invalid = true;
8354 continue;
8355 }
8356 FieldDecl *OldFD = C->getInitCaptureField();
8357 FieldDecl *NewFD = getSema().checkInitCapture(
8358 C->getLocation(), OldFD->getType()->isReferenceType(),
8359 OldFD->getIdentifier(), Init.take());
8360 if (!NewFD)
8361 Invalid = true;
8362 else
8363 getDerived().transformedLocalDecl(OldFD, NewFD);
8364 continue;
8365 }
8366
8367 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8368
Douglas Gregora7365242012-02-14 19:27:52 +00008369 // Determine the capture kind for Sema.
8370 Sema::TryCaptureKind Kind
8371 = C->isImplicit()? Sema::TryCapture_Implicit
8372 : C->getCaptureKind() == LCK_ByCopy
8373 ? Sema::TryCapture_ExplicitByVal
8374 : Sema::TryCapture_ExplicitByRef;
8375 SourceLocation EllipsisLoc;
8376 if (C->isPackExpansion()) {
8377 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8378 bool ShouldExpand = false;
8379 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008380 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008381 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8382 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008383 Unexpanded,
8384 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008385 NumExpansions)) {
8386 Invalid = true;
8387 continue;
8388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389
Douglas Gregora7365242012-02-14 19:27:52 +00008390 if (ShouldExpand) {
8391 // The transform has determined that we should perform an expansion;
8392 // transform and capture each of the arguments.
8393 // expansion of the pattern. Do so.
8394 VarDecl *Pack = C->getCapturedVar();
8395 for (unsigned I = 0; I != *NumExpansions; ++I) {
8396 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8397 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008398 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008399 Pack));
8400 if (!CapturedVar) {
8401 Invalid = true;
8402 continue;
8403 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008404
Douglas Gregora7365242012-02-14 19:27:52 +00008405 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008406 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8407 }
Douglas Gregora7365242012-02-14 19:27:52 +00008408 continue;
8409 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008410
Douglas Gregora7365242012-02-14 19:27:52 +00008411 EllipsisLoc = C->getEllipsisLoc();
8412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008413
Douglas Gregordfca6f52012-02-13 22:00:16 +00008414 // Transform the captured variable.
8415 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008416 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008417 C->getCapturedVar()));
8418 if (!CapturedVar) {
8419 Invalid = true;
8420 continue;
8421 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422
Douglas Gregordfca6f52012-02-13 22:00:16 +00008423 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008424 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008425 }
8426 if (!FinishedExplicitCaptures)
8427 getSema().finishLambdaExplicitCaptures(LSI);
8428
Douglas Gregordfca6f52012-02-13 22:00:16 +00008429
8430 // Enter a new evaluation context to insulate the lambda from any
8431 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008433
8434 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008435 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008436 /*IsInstantiation=*/true);
8437 return ExprError();
8438 }
8439
8440 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008441 StmtResult Body = getDerived().TransformStmt(E->getBody());
8442 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008444 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008446 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008447
Chad Rosier4a9d7952012-08-08 18:46:20 +00008448 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008449 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008450}
8451
8452template<typename Derived>
8453ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008454TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008455 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008456 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8457 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008459
Douglas Gregorb98b1992009-08-11 05:31:07 +00008460 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008461 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008462 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008464 &ArgumentChanged))
8465 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008466
Douglas Gregorb98b1992009-08-11 05:31:07 +00008467 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008468 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008469 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008470 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008471
Douglas Gregorb98b1992009-08-11 05:31:07 +00008472 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008473 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008474 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008475 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008476 E->getRParenLoc());
8477}
Mike Stump1eb44332009-09-09 15:08:12 +00008478
Douglas Gregorb98b1992009-08-11 05:31:07 +00008479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008480ExprResult
John McCall865d4472009-11-19 22:55:06 +00008481TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008482 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008483 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008484 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008485 Expr *OldBase;
8486 QualType BaseType;
8487 QualType ObjectType;
8488 if (!E->isImplicitAccess()) {
8489 OldBase = E->getBase();
8490 Base = getDerived().TransformExpr(OldBase);
8491 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008493
John McCallaa81e162009-12-01 22:10:20 +00008494 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008495 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008496 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008497 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008498 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008499 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008500 ObjectTy,
8501 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008502 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008503 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008504
John McCallb3d87482010-08-24 05:47:05 +00008505 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008506 BaseType = ((Expr*) Base.get())->getType();
8507 } else {
8508 OldBase = 0;
8509 BaseType = getDerived().TransformType(E->getBaseType());
8510 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8511 }
Mike Stump1eb44332009-09-09 15:08:12 +00008512
Douglas Gregor6cd21982009-10-20 05:58:46 +00008513 // Transform the first part of the nested-name-specifier that qualifies
8514 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008515 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008516 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008517 E->getFirstQualifierFoundInScope(),
8518 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008519
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008520 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008521 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008522 QualifierLoc
8523 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8524 ObjectType,
8525 FirstQualifierInScope);
8526 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008527 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008528 }
Mike Stump1eb44332009-09-09 15:08:12 +00008529
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008530 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8531
John McCall43fed0d2010-11-12 08:19:04 +00008532 // TODO: If this is a conversion-function-id, verify that the
8533 // destination type name (if present) resolves the same way after
8534 // instantiation as it did in the local scope.
8535
Abramo Bagnara25777432010-08-11 22:01:17 +00008536 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008537 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008538 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008540
John McCallaa81e162009-12-01 22:10:20 +00008541 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008542 // This is a reference to a member without an explicitly-specified
8543 // template argument list. Optimize for this common case.
8544 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008545 Base.get() == OldBase &&
8546 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008547 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008548 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008549 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008550 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008551
John McCall9ae2f072010-08-23 23:25:46 +00008552 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008553 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008554 E->isArrow(),
8555 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008556 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008557 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008558 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008559 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008560 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008561 }
8562
John McCalld5532b62009-11-23 01:53:49 +00008563 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008564 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8565 E->getNumTemplateArgs(),
8566 TransArgs))
8567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008568
John McCall9ae2f072010-08-23 23:25:46 +00008569 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008570 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008571 E->isArrow(),
8572 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008573 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008574 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008575 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008576 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008577 &TransArgs);
8578}
8579
8580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008581ExprResult
John McCall454feb92009-12-08 09:21:05 +00008582TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008583 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008584 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008585 QualType BaseType;
8586 if (!Old->isImplicitAccess()) {
8587 Base = getDerived().TransformExpr(Old->getBase());
8588 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008589 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008590 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8591 Old->isArrow());
8592 if (Base.isInvalid())
8593 return ExprError();
8594 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008595 } else {
8596 BaseType = getDerived().TransformType(Old->getBaseType());
8597 }
John McCall129e2df2009-11-30 22:42:35 +00008598
Douglas Gregor4c9be892011-02-28 20:01:57 +00008599 NestedNameSpecifierLoc QualifierLoc;
8600 if (Old->getQualifierLoc()) {
8601 QualifierLoc
8602 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8603 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008604 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008605 }
8606
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008607 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8608
Abramo Bagnara25777432010-08-11 22:01:17 +00008609 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008610 Sema::LookupOrdinaryName);
8611
8612 // Transform all the decls.
8613 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8614 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008615 NamedDecl *InstD = static_cast<NamedDecl*>(
8616 getDerived().TransformDecl(Old->getMemberLoc(),
8617 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008618 if (!InstD) {
8619 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8620 // This can happen because of dependent hiding.
8621 if (isa<UsingShadowDecl>(*I))
8622 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008623 else {
8624 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008625 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008626 }
John McCall9f54ad42009-12-10 09:41:52 +00008627 }
John McCall129e2df2009-11-30 22:42:35 +00008628
8629 // Expand using declarations.
8630 if (isa<UsingDecl>(InstD)) {
8631 UsingDecl *UD = cast<UsingDecl>(InstD);
8632 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8633 E = UD->shadow_end(); I != E; ++I)
8634 R.addDecl(*I);
8635 continue;
8636 }
8637
8638 R.addDecl(InstD);
8639 }
8640
8641 R.resolveKind();
8642
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008643 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008644 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008645 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008646 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008647 Old->getMemberLoc(),
8648 Old->getNamingClass()));
8649 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008650 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008651
Douglas Gregor66c45152010-04-27 16:10:10 +00008652 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008654
John McCall129e2df2009-11-30 22:42:35 +00008655 TemplateArgumentListInfo TransArgs;
8656 if (Old->hasExplicitTemplateArgs()) {
8657 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8658 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008659 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8660 Old->getNumTemplateArgs(),
8661 TransArgs))
8662 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008663 }
John McCallc2233c52010-01-15 08:34:02 +00008664
8665 // FIXME: to do this check properly, we will need to preserve the
8666 // first-qualifier-in-scope here, just in case we had a dependent
8667 // base (and therefore couldn't do the check) and a
8668 // nested-name-qualifier (and therefore could do the lookup).
8669 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008670
John McCall9ae2f072010-08-23 23:25:46 +00008671 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008672 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008673 Old->getOperatorLoc(),
8674 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008675 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008676 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008677 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008678 R,
8679 (Old->hasExplicitTemplateArgs()
8680 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008681}
8682
8683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008684ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008685TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008687 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8688 if (SubExpr.isInvalid())
8689 return ExprError();
8690
8691 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008692 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008693
8694 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8695}
8696
8697template<typename Derived>
8698ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008699TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008700 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8701 if (Pattern.isInvalid())
8702 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008703
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008704 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8705 return SemaRef.Owned(E);
8706
Douglas Gregor67fd1252011-01-14 21:20:45 +00008707 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8708 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008709}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008710
8711template<typename Derived>
8712ExprResult
8713TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8714 // If E is not value-dependent, then nothing will change when we transform it.
8715 // Note: This is an instantiation-centric view.
8716 if (!E->isValueDependent())
8717 return SemaRef.Owned(E);
8718
8719 // Note: None of the implementations of TryExpandParameterPacks can ever
8720 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008721 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008722 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8723 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008724 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008725 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008727 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008728 ShouldExpand, RetainExpansion,
8729 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008730 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
Douglas Gregor089e8932011-10-10 18:59:29 +00008732 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008733 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
Douglas Gregor089e8932011-10-10 18:59:29 +00008735 NamedDecl *Pack = E->getPack();
8736 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008737 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008738 Pack));
8739 if (!Pack)
8740 return ExprError();
8741 }
8742
Chad Rosier4a9d7952012-08-08 18:46:20 +00008743
Douglas Gregoree8aff02011-01-04 17:33:58 +00008744 // We now know the length of the parameter pack, so build a new expression
8745 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008746 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8747 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008748 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008749}
8750
Douglas Gregorbe230c32011-01-03 17:17:50 +00008751template<typename Derived>
8752ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008753TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8754 SubstNonTypeTemplateParmPackExpr *E) {
8755 // Default behavior is to do nothing with this transformation.
8756 return SemaRef.Owned(E);
8757}
8758
8759template<typename Derived>
8760ExprResult
John McCall91a57552011-07-15 05:09:51 +00008761TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8762 SubstNonTypeTemplateParmExpr *E) {
8763 // Default behavior is to do nothing with this transformation.
8764 return SemaRef.Owned(E);
8765}
8766
8767template<typename Derived>
8768ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008769TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8770 // Default behavior is to do nothing with this transformation.
8771 return SemaRef.Owned(E);
8772}
8773
8774template<typename Derived>
8775ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008776TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8777 MaterializeTemporaryExpr *E) {
8778 return getDerived().TransformExpr(E->GetTemporaryExpr());
8779}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008780
Douglas Gregor03e80032011-06-21 17:03:29 +00008781template<typename Derived>
8782ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008783TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8784 CXXStdInitializerListExpr *E) {
8785 return getDerived().TransformExpr(E->getSubExpr());
8786}
8787
8788template<typename Derived>
8789ExprResult
John McCall454feb92009-12-08 09:21:05 +00008790TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008791 return SemaRef.MaybeBindToTemporary(E);
8792}
8793
8794template<typename Derived>
8795ExprResult
8796TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008797 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008798}
8799
8800template<typename Derived>
8801ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008802TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8803 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8804 if (SubExpr.isInvalid())
8805 return ExprError();
8806
8807 if (!getDerived().AlwaysRebuild() &&
8808 SubExpr.get() == E->getSubExpr())
8809 return SemaRef.Owned(E);
8810
8811 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008812}
8813
8814template<typename Derived>
8815ExprResult
8816TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8817 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008818 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008819 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008821 /*IsCall=*/false, Elements, &ArgChanged))
8822 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008824 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8825 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008826
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008827 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8828 Elements.data(),
8829 Elements.size());
8830}
8831
8832template<typename Derived>
8833ExprResult
8834TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008835 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008836 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008837 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008838 bool ArgChanged = false;
8839 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8840 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008841
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008842 if (OrigElement.isPackExpansion()) {
8843 // This key/value element is a pack expansion.
8844 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8845 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8846 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8847 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8848
8849 // Determine whether the set of unexpanded parameter packs can
8850 // and should be expanded.
8851 bool Expand = true;
8852 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008853 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8854 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008855 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8856 OrigElement.Value->getLocEnd());
8857 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8858 PatternRange,
8859 Unexpanded,
8860 Expand, RetainExpansion,
8861 NumExpansions))
8862 return ExprError();
8863
8864 if (!Expand) {
8865 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008867 // expansion.
8868 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8869 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8870 if (Key.isInvalid())
8871 return ExprError();
8872
8873 if (Key.get() != OrigElement.Key)
8874 ArgChanged = true;
8875
8876 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8877 if (Value.isInvalid())
8878 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008879
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008880 if (Value.get() != OrigElement.Value)
8881 ArgChanged = true;
8882
Chad Rosier4a9d7952012-08-08 18:46:20 +00008883 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008884 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8885 };
8886 Elements.push_back(Expansion);
8887 continue;
8888 }
8889
8890 // Record right away that the argument was changed. This needs
8891 // to happen even if the array expands to nothing.
8892 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008893
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008894 // The transform has determined that we should perform an elementwise
8895 // expansion of the pattern. Do so.
8896 for (unsigned I = 0; I != *NumExpansions; ++I) {
8897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8898 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8899 if (Key.isInvalid())
8900 return ExprError();
8901
8902 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8903 if (Value.isInvalid())
8904 return ExprError();
8905
Chad Rosier4a9d7952012-08-08 18:46:20 +00008906 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008907 Key.get(), Value.get(), SourceLocation(), NumExpansions
8908 };
8909
8910 // If any unexpanded parameter packs remain, we still have a
8911 // pack expansion.
8912 if (Key.get()->containsUnexpandedParameterPack() ||
8913 Value.get()->containsUnexpandedParameterPack())
8914 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008915
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008916 Elements.push_back(Element);
8917 }
8918
8919 // We've finished with this pack expansion.
8920 continue;
8921 }
8922
8923 // Transform and check key.
8924 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8925 if (Key.isInvalid())
8926 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008927
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008928 if (Key.get() != OrigElement.Key)
8929 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008930
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008931 // Transform and check value.
8932 ExprResult Value
8933 = getDerived().TransformExpr(OrigElement.Value);
8934 if (Value.isInvalid())
8935 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008936
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008937 if (Value.get() != OrigElement.Value)
8938 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008939
8940 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008941 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008942 };
8943 Elements.push_back(Element);
8944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008945
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008946 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8947 return SemaRef.MaybeBindToTemporary(E);
8948
8949 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8950 Elements.data(),
8951 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008952}
8953
Mike Stump1eb44332009-09-09 15:08:12 +00008954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008955ExprResult
John McCall454feb92009-12-08 09:21:05 +00008956TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008957 TypeSourceInfo *EncodedTypeInfo
8958 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8959 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008960 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008961
Douglas Gregorb98b1992009-08-11 05:31:07 +00008962 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008963 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008964 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008965
8966 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008967 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008968 E->getRParenLoc());
8969}
Mike Stump1eb44332009-09-09 15:08:12 +00008970
Douglas Gregorb98b1992009-08-11 05:31:07 +00008971template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008972ExprResult TreeTransform<Derived>::
8973TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008974 // This is a kind of implicit conversion, and it needs to get dropped
8975 // and recomputed for the same general reasons that ImplicitCastExprs
8976 // do, as well a more specific one: this expression is only valid when
8977 // it appears *immediately* as an argument expression.
8978 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008979}
8980
8981template<typename Derived>
8982ExprResult TreeTransform<Derived>::
8983TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008984 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008985 = getDerived().TransformType(E->getTypeInfoAsWritten());
8986 if (!TSInfo)
8987 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008988
John McCallf85e1932011-06-15 23:02:42 +00008989 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008990 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008991 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008992
John McCallf85e1932011-06-15 23:02:42 +00008993 if (!getDerived().AlwaysRebuild() &&
8994 TSInfo == E->getTypeInfoAsWritten() &&
8995 Result.get() == E->getSubExpr())
8996 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008997
John McCallf85e1932011-06-15 23:02:42 +00008998 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008999 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009000 Result.get());
9001}
9002
9003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009004ExprResult
John McCall454feb92009-12-08 09:21:05 +00009005TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009006 // Transform arguments.
9007 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009008 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009009 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009010 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009011 &ArgChanged))
9012 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009013
Douglas Gregor92e986e2010-04-22 16:44:27 +00009014 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9015 // Class message: transform the receiver type.
9016 TypeSourceInfo *ReceiverTypeInfo
9017 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9018 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009019 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009020
Douglas Gregor92e986e2010-04-22 16:44:27 +00009021 // If nothing changed, just retain the existing message send.
9022 if (!getDerived().AlwaysRebuild() &&
9023 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009024 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009025
9026 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009027 SmallVector<SourceLocation, 16> SelLocs;
9028 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009029 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9030 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009031 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009032 E->getMethodDecl(),
9033 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009034 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009035 E->getRightLoc());
9036 }
9037
9038 // Instance message: transform the receiver
9039 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9040 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009041 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009042 = getDerived().TransformExpr(E->getInstanceReceiver());
9043 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009044 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009045
9046 // If nothing changed, just retain the existing message send.
9047 if (!getDerived().AlwaysRebuild() &&
9048 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009049 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009050
Douglas Gregor92e986e2010-04-22 16:44:27 +00009051 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009052 SmallVector<SourceLocation, 16> SelLocs;
9053 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009054 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009055 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009056 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009057 E->getMethodDecl(),
9058 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009059 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009060 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009061}
9062
Mike Stump1eb44332009-09-09 15:08:12 +00009063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009064ExprResult
John McCall454feb92009-12-08 09:21:05 +00009065TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009067}
9068
Mike Stump1eb44332009-09-09 15:08:12 +00009069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009070ExprResult
John McCall454feb92009-12-08 09:21:05 +00009071TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009072 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009073}
9074
Mike Stump1eb44332009-09-09 15:08:12 +00009075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009076ExprResult
John McCall454feb92009-12-08 09:21:05 +00009077TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009078 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009079 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009080 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009081 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009082
9083 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009084
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009085 // If nothing changed, just retain the existing expression.
9086 if (!getDerived().AlwaysRebuild() &&
9087 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009088 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009089
John McCall9ae2f072010-08-23 23:25:46 +00009090 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009091 E->getLocation(),
9092 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009093}
9094
Mike Stump1eb44332009-09-09 15:08:12 +00009095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009096ExprResult
John McCall454feb92009-12-08 09:21:05 +00009097TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009098 // 'super' and types never change. Property never changes. Just
9099 // retain the existing expression.
9100 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009101 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009102
Douglas Gregore3303542010-04-26 20:47:02 +00009103 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009104 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009105 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009106 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009107
Douglas Gregore3303542010-04-26 20:47:02 +00009108 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009109
Douglas Gregore3303542010-04-26 20:47:02 +00009110 // If nothing changed, just retain the existing expression.
9111 if (!getDerived().AlwaysRebuild() &&
9112 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009113 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009114
John McCall12f78a62010-12-02 01:19:52 +00009115 if (E->isExplicitProperty())
9116 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9117 E->getExplicitProperty(),
9118 E->getLocation());
9119
9120 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009121 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009122 E->getImplicitPropertyGetter(),
9123 E->getImplicitPropertySetter(),
9124 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009125}
9126
Mike Stump1eb44332009-09-09 15:08:12 +00009127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009128ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009129TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9130 // Transform the base expression.
9131 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9132 if (Base.isInvalid())
9133 return ExprError();
9134
9135 // Transform the key expression.
9136 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9137 if (Key.isInvalid())
9138 return ExprError();
9139
9140 // If nothing changed, just retain the existing expression.
9141 if (!getDerived().AlwaysRebuild() &&
9142 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9143 return SemaRef.Owned(E);
9144
Chad Rosier4a9d7952012-08-08 18:46:20 +00009145 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009146 Base.get(), Key.get(),
9147 E->getAtIndexMethodDecl(),
9148 E->setAtIndexMethodDecl());
9149}
9150
9151template<typename Derived>
9152ExprResult
John McCall454feb92009-12-08 09:21:05 +00009153TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009154 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009155 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009156 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009157 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009158
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009159 // If nothing changed, just retain the existing expression.
9160 if (!getDerived().AlwaysRebuild() &&
9161 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009162 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009163
John McCall9ae2f072010-08-23 23:25:46 +00009164 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009165 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009166 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009167}
9168
Mike Stump1eb44332009-09-09 15:08:12 +00009169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009170ExprResult
John McCall454feb92009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009173 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009174 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009175 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009176 SubExprs, &ArgumentChanged))
9177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009178
Douglas Gregorb98b1992009-08-11 05:31:07 +00009179 if (!getDerived().AlwaysRebuild() &&
9180 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009181 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009182
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009184 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 E->getRParenLoc());
9186}
9187
Mike Stump1eb44332009-09-09 15:08:12 +00009188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009189ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009190TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9191 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9192 if (SrcExpr.isInvalid())
9193 return ExprError();
9194
9195 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9196 if (!Type)
9197 return ExprError();
9198
9199 if (!getDerived().AlwaysRebuild() &&
9200 Type == E->getTypeSourceInfo() &&
9201 SrcExpr.get() == E->getSrcExpr())
9202 return SemaRef.Owned(E);
9203
9204 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9205 SrcExpr.get(), Type,
9206 E->getRParenLoc());
9207}
9208
9209template<typename Derived>
9210ExprResult
John McCall454feb92009-12-08 09:21:05 +00009211TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009212 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009213
John McCallc6ac9c32011-02-04 18:33:18 +00009214 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9215 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9216
9217 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009218 blockScope->TheDecl->setBlockMissingReturnType(
9219 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009220
Chris Lattner686775d2011-07-20 06:58:45 +00009221 SmallVector<ParmVarDecl*, 4> params;
9222 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009223
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009224 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009225 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9226 oldBlock->param_begin(),
9227 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009228 0, paramTypes, &params)) {
9229 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009230 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009231 }
John McCallc6ac9c32011-02-04 18:33:18 +00009232
Jordan Rose09189892013-03-08 22:25:36 +00009233 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009234 QualType exprResultType =
9235 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009236
Jordan Rosebea522f2013-03-08 21:51:21 +00009237 QualType functionType =
9238 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009239 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009240 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009241
9242 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009243 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009244 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009245
9246 if (!oldBlock->blockMissingReturnType()) {
9247 blockScope->HasImplicitReturnType = false;
9248 blockScope->ReturnType = exprResultType;
9249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009250
John McCall711c52b2011-01-05 12:14:39 +00009251 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009252 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009253 if (body.isInvalid()) {
9254 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009255 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009256 }
John McCall711c52b2011-01-05 12:14:39 +00009257
John McCallc6ac9c32011-02-04 18:33:18 +00009258#ifndef NDEBUG
9259 // In builds with assertions, make sure that we captured everything we
9260 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009261 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9262 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9263 e = oldBlock->capture_end(); i != e; ++i) {
9264 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009265
Douglas Gregorfc921372011-05-20 15:32:55 +00009266 // Ignore parameter packs.
9267 if (isa<ParmVarDecl>(oldCapture) &&
9268 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9269 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009270
Douglas Gregorfc921372011-05-20 15:32:55 +00009271 VarDecl *newCapture =
9272 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9273 oldCapture));
9274 assert(blockScope->CaptureMap.count(newCapture));
9275 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009276 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009277 }
9278#endif
9279
9280 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9281 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009282}
9283
Mike Stump1eb44332009-09-09 15:08:12 +00009284template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009285ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009286TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009287 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009288}
Eli Friedman276b0612011-10-11 02:20:01 +00009289
9290template<typename Derived>
9291ExprResult
9292TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009293 QualType RetTy = getDerived().TransformType(E->getType());
9294 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009295 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009296 SubExprs.reserve(E->getNumSubExprs());
9297 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9298 SubExprs, &ArgumentChanged))
9299 return ExprError();
9300
9301 if (!getDerived().AlwaysRebuild() &&
9302 !ArgumentChanged)
9303 return SemaRef.Owned(E);
9304
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009305 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009306 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009307}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009308
Douglas Gregorb98b1992009-08-11 05:31:07 +00009309//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009310// Type reconstruction
9311//===----------------------------------------------------------------------===//
9312
Mike Stump1eb44332009-09-09 15:08:12 +00009313template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009314QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9315 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009316 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009317 getDerived().getBaseEntity());
9318}
9319
Mike Stump1eb44332009-09-09 15:08:12 +00009320template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009321QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9322 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009323 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009324 getDerived().getBaseEntity());
9325}
9326
Mike Stump1eb44332009-09-09 15:08:12 +00009327template<typename Derived>
9328QualType
John McCall85737a72009-10-30 00:06:24 +00009329TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9330 bool WrittenAsLValue,
9331 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009332 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009333 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009334}
9335
9336template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009337QualType
John McCall85737a72009-10-30 00:06:24 +00009338TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9339 QualType ClassType,
9340 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009341 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009342 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009343}
9344
9345template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009346QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009347TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9348 ArrayType::ArraySizeModifier SizeMod,
9349 const llvm::APInt *Size,
9350 Expr *SizeExpr,
9351 unsigned IndexTypeQuals,
9352 SourceRange BracketsRange) {
9353 if (SizeExpr || !Size)
9354 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9355 IndexTypeQuals, BracketsRange,
9356 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009357
9358 QualType Types[] = {
9359 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9360 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9361 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009362 };
Craig Topperb9602322013-07-15 03:38:40 +00009363 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009364 QualType SizeType;
9365 for (unsigned I = 0; I != NumTypes; ++I)
9366 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9367 SizeType = Types[I];
9368 break;
9369 }
Mike Stump1eb44332009-09-09 15:08:12 +00009370
Eli Friedman01f276d2012-01-25 23:20:27 +00009371 // Note that we can return a VariableArrayType here in the case where
9372 // the element type was a dependent VariableArrayType.
9373 IntegerLiteral *ArraySize
9374 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9375 /*FIXME*/BracketsRange.getBegin());
9376 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009377 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009378 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009379}
Mike Stump1eb44332009-09-09 15:08:12 +00009380
Douglas Gregor577f75a2009-08-04 16:50:30 +00009381template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009382QualType
9383TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009384 ArrayType::ArraySizeModifier SizeMod,
9385 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009386 unsigned IndexTypeQuals,
9387 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009388 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009389 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009390}
9391
9392template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009393QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009394TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009395 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009396 unsigned IndexTypeQuals,
9397 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009398 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009399 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009400}
Mike Stump1eb44332009-09-09 15:08:12 +00009401
Douglas Gregor577f75a2009-08-04 16:50:30 +00009402template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009403QualType
9404TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009405 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009406 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009407 unsigned IndexTypeQuals,
9408 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009409 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009410 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009411 IndexTypeQuals, BracketsRange);
9412}
9413
9414template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009415QualType
9416TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009417 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009418 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009419 unsigned IndexTypeQuals,
9420 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009421 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009422 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009423 IndexTypeQuals, BracketsRange);
9424}
9425
9426template<typename Derived>
9427QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009428 unsigned NumElements,
9429 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009430 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009431 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009432}
Mike Stump1eb44332009-09-09 15:08:12 +00009433
Douglas Gregor577f75a2009-08-04 16:50:30 +00009434template<typename Derived>
9435QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9436 unsigned NumElements,
9437 SourceLocation AttributeLoc) {
9438 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9439 NumElements, true);
9440 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009441 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9442 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009443 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009444}
Mike Stump1eb44332009-09-09 15:08:12 +00009445
Douglas Gregor577f75a2009-08-04 16:50:30 +00009446template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009447QualType
9448TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009449 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009450 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009451 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009452}
Mike Stump1eb44332009-09-09 15:08:12 +00009453
Douglas Gregor577f75a2009-08-04 16:50:30 +00009454template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009455QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9456 QualType T,
9457 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009458 const FunctionProtoType::ExtProtoInfo &EPI) {
9459 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009460 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009461 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009462 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009463}
Mike Stump1eb44332009-09-09 15:08:12 +00009464
Douglas Gregor577f75a2009-08-04 16:50:30 +00009465template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009466QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9467 return SemaRef.Context.getFunctionNoProtoType(T);
9468}
9469
9470template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009471QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9472 assert(D && "no decl found");
9473 if (D->isInvalidDecl()) return QualType();
9474
Douglas Gregor92e986e2010-04-22 16:44:27 +00009475 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009476 TypeDecl *Ty;
9477 if (isa<UsingDecl>(D)) {
9478 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009479 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009480 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9481
9482 // A valid resolved using typename decl points to exactly one type decl.
9483 assert(++Using->shadow_begin() == Using->shadow_end());
9484 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009485
John McCalled976492009-12-04 22:46:56 +00009486 } else {
9487 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9488 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9489 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9490 }
9491
9492 return SemaRef.Context.getTypeDeclType(Ty);
9493}
9494
9495template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009496QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9497 SourceLocation Loc) {
9498 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009499}
9500
9501template<typename Derived>
9502QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9503 return SemaRef.Context.getTypeOfType(Underlying);
9504}
9505
9506template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009507QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9508 SourceLocation Loc) {
9509 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009510}
9511
9512template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009513QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9514 UnaryTransformType::UTTKind UKind,
9515 SourceLocation Loc) {
9516 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9517}
9518
9519template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009520QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009521 TemplateName Template,
9522 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009523 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009524 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009525}
Mike Stump1eb44332009-09-09 15:08:12 +00009526
Douglas Gregordcee1a12009-08-06 05:28:30 +00009527template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009528QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9529 SourceLocation KWLoc) {
9530 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9531}
9532
9533template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009534TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009535TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009536 bool TemplateKW,
9537 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009538 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009539 Template);
9540}
9541
9542template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009543TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009544TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9545 const IdentifierInfo &Name,
9546 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009547 QualType ObjectType,
9548 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009549 UnqualifiedId TemplateName;
9550 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009551 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009552 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009553 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009554 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009555 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009556 /*EnteringContext=*/false,
9557 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009558 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009559}
Mike Stump1eb44332009-09-09 15:08:12 +00009560
Douglas Gregorb98b1992009-08-11 05:31:07 +00009561template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009562TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009563TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009564 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009565 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009566 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009567 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009568 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009569 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009570 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009571 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009572 Sema::TemplateTy Template;
9573 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009574 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009575 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009576 /*EnteringContext=*/false,
9577 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009578 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009579}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009580
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009582ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009583TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9584 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009585 Expr *OrigCallee,
9586 Expr *First,
9587 Expr *Second) {
9588 Expr *Callee = OrigCallee->IgnoreParenCasts();
9589 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009590
Douglas Gregorb98b1992009-08-11 05:31:07 +00009591 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009592 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009593 if (!First->getType()->isOverloadableType() &&
9594 !Second->getType()->isOverloadableType())
9595 return getSema().CreateBuiltinArraySubscriptExpr(First,
9596 Callee->getLocStart(),
9597 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009598 } else if (Op == OO_Arrow) {
9599 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009600 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9601 } else if (Second == 0 || isPostIncDec) {
9602 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009603 // The argument is not of overloadable type, so try to create a
9604 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009605 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009606 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009607
John McCall9ae2f072010-08-23 23:25:46 +00009608 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009609 }
9610 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009611 if (!First->getType()->isOverloadableType() &&
9612 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009613 // Neither of the arguments is an overloadable type, so try to
9614 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009615 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009616 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009617 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009618 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009620
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009621 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009622 }
9623 }
Mike Stump1eb44332009-09-09 15:08:12 +00009624
9625 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009626 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009627 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009628
John McCall9ae2f072010-08-23 23:25:46 +00009629 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009630 assert(ULE->requiresADL());
9631
9632 // FIXME: Do we have to check
9633 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009634 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009635 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009636 // If we've resolved this to a particular non-member function, just call
9637 // that function. If we resolved it to a member function,
9638 // CreateOverloaded* will find that function for us.
9639 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9640 if (!isa<CXXMethodDecl>(ND))
9641 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009642 }
Mike Stump1eb44332009-09-09 15:08:12 +00009643
Douglas Gregorb98b1992009-08-11 05:31:07 +00009644 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009645 Expr *Args[2] = { First, Second };
9646 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009647
Douglas Gregorb98b1992009-08-11 05:31:07 +00009648 // Create the overloaded operator invocation for unary operators.
9649 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009650 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009651 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009652 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009653 }
Mike Stump1eb44332009-09-09 15:08:12 +00009654
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009655 if (Op == OO_Subscript) {
9656 SourceLocation LBrace;
9657 SourceLocation RBrace;
9658
9659 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9660 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9661 LBrace = SourceLocation::getFromRawEncoding(
9662 NameLoc.CXXOperatorName.BeginOpNameLoc);
9663 RBrace = SourceLocation::getFromRawEncoding(
9664 NameLoc.CXXOperatorName.EndOpNameLoc);
9665 } else {
9666 LBrace = Callee->getLocStart();
9667 RBrace = OpLoc;
9668 }
9669
9670 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9671 First, Second);
9672 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009673
Douglas Gregorb98b1992009-08-11 05:31:07 +00009674 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009675 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009676 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009677 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9678 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009680
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009681 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009682}
Mike Stump1eb44332009-09-09 15:08:12 +00009683
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009684template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009685ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009686TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009687 SourceLocation OperatorLoc,
9688 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009689 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009690 TypeSourceInfo *ScopeType,
9691 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009692 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009693 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009694 QualType BaseType = Base->getType();
9695 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009696 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009697 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009698 !BaseType->getAs<PointerType>()->getPointeeType()
9699 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009700 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009701 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009702 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009703 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009704 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009705 /*FIXME?*/true);
9706 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009707
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009708 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009709 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9710 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9711 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9712 NameInfo.setNamedTypeInfo(DestroyedType);
9713
Richard Smith6314db92012-05-15 06:15:11 +00009714 // The scope type is now known to be a valid nested name specifier
9715 // component. Tack it on to the end of the nested name specifier.
9716 if (ScopeType)
9717 SS.Extend(SemaRef.Context, SourceLocation(),
9718 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009719
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009720 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009721 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009722 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009723 SS, TemplateKWLoc,
9724 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009725 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009726 /*TemplateArgs*/ 0);
9727}
9728
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009729template<typename Derived>
9730StmtResult
9731TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009732 SourceLocation Loc = S->getLocStart();
9733 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9734 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9735 S->getCapturedRegionKind(), NumParams);
9736 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9737
9738 if (Body.isInvalid()) {
9739 getSema().ActOnCapturedRegionError();
9740 return StmtError();
9741 }
9742
9743 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009744}
9745
Douglas Gregor577f75a2009-08-04 16:50:30 +00009746} // end namespace clang
9747
9748#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H